PDA

View Full Version : SSC-32 communication



Bevels
07-11-2009, 03:48 PM
I have a usb/serial adaptor that emulates a serial port with a usb port. I have connected this to my SSC-32 controller and I am trying to feed an ascii command to it using WinCC scripts. If no one knows how to do that, does anyone know how to send an ascii command using visual basic?

The connection is COM 4 and I want to send the ascii command #1 P750 just as a test.

Adrenalynn
07-11-2009, 05:03 PM
You don't mention baud rate...




using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleCenterServo
{
class Program
{

static void Main(string[] args)
{
System.IO.Ports.SerialPort serialPort = new System.IO.Ports.SerialPort();

// Close the serial port if it is already open
if (serialPort.IsOpen)
{
serialPort.Close();
}
try
{
// Configure our serial port *** You'll likely need to change these for your config! ***
serialPort.PortName = "COM4";
serialPort.BaudRate = 38400;
serialPort.Parity = System.IO.Ports.Parity.None;
serialPort.DataBits = 8;
serialPort.StopBits = System.IO.Ports.StopBits.One;

//Now open the serial port
serialPort.Open();
}
catch (Exception ex)
{
Console.WriteLine("Couldn't open the Serial Port!");
Console.WriteLine(ex.ToString());//Report the actual error
}
try
{
//Now we'll send some data. Specifically we want to send "#Channel Number P1500<cr>" to center the servo
serialPort.Write("#1 P750\r");
}
catch (Exception ex)
{
Console.WriteLine("Couldn't send the command for some reason... I give up. Sorry!");
Console.WriteLine(ex.ToString()); //Report the actual error
}

//Report our apparent success
Console.WriteLine("Go little servo, Go!" + Environment.NewLine);
Console.WriteLine("Sent: #1 P750<cr>" + Environment.NewLine);

//Now let's close our serial port.
try
{
serialPort.Close();
}
catch (Exception ex)
{
Console.WriteLine("Couldn't close the darned serial port. Here's what it said: " + Environment.NewLine);
Console.WriteLine(ex.ToString());
}
//Wait for [Enter] before we close
Console.ReadLine();

}
}
}


Now - I'm not a VB programmer, so I doubt this'll work the first time, but if you write VB it should get you easily on the right track. If not, go learn VB, and then this will get you on the right track. ;) This should be trivial to debug. I read a VB app once or twice... years ago. Should be pretty close. It's kinda like swimmin' laps in a kiddie-pool ;).



Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.IO

Module Module1
Sub Main()
If serialPort.IsOpen Then
serialPort.Close()
End If

Try
With serialPort
.PortName = "COM4"
.BaudRate = 38400
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One

End With

'--- Now open the port
serialPort.Open()

Catch ex As Exception
MsgBox(ex.ToString) '--- Do a little error handling
End Try

Try
'--- Write the data
serialPort.Write("#1 P750" & vbCr) '--- data + <CR> as required
Catch ex As Exception
MsgBox(ex.ToString) '--- Do a little error handling
End Try

Try '--- Close the serial port and clean up
serialPort.Close()
Catch ex As Exception
MsgBox(ex.ToString) '--- Do a little error handling
End Try
Console.ReadLine() '--- Don't let the console close before we tag a key
End Sub
End Module

Bevels
07-12-2009, 01:08 PM
I am trying to communicate to my SSC-32 using VBScript. I tried using a function mentioned in another thread but I cannot get it to work. I am trying to get VBScript to tell a motor to move #2 P750. First I tried this:

Sub ssc32test()
Set MSComm1=CreateObject("MSCOMMLib.MSComm")
MSComm1.Settings = "115200,n,8,4"
MSComm1.CommPort = 4
MSComm1.InBufferCount = 0
MSComm1.PortOpen = True
If Err Then
MsgBox "COM" & MSComm1.CommPort & ": not opened, Sorry!"
Exit Sub
End If
MSComm1.Output="#2 P750" & CHR(13)
WScript.Sleep(1000)
MSComm1.PortOpen = False
Set MSComm1 = Nothing
End Sub

But it gave me errors for MSComm1 saying that it was undefined so I added this in the Sub:

Dim MSComm1

Then it gave me errors saying that WScript wasnt valid so I deleted that line. After deleting several other things to get it to work without errors I wound up with this:

Dim MSComm1
Set MSComm1=CreateObject("MSCOMMLib.MSComm")
MSComm1.Settings = "115200,n,8,4"
MSComm1.CommPort = 4
MSComm1.InBufferCount = 0
MSComm1.PortOpen = True
MSComm1.Output="#2 P750" & CHR(13)

However, when I test this, the motor doesnt move at all. #2 P750 definitely is the desired command because I tested it on the Lynmotion ssc32 program. Does anyone have any ideas?

Adrenalynn
07-12-2009, 01:54 PM
Please don't start new threads for the same question. I've merged it into here.

Bevels
07-12-2009, 02:01 PM
Sorry. Do you have any ideas?

Adrenalynn
07-12-2009, 02:06 PM
>> After deleting several other things to get it to work without errors I wound up with this:

In programming, "deleting stuff that doesn't compile" doesn't mean "it's now working". My suggestion would be to learn vbscript if you want to learn vbscript.

MikeG
07-12-2009, 03:48 PM
Consider downloading one of the .NET express editors and using the SerialPort object of the System.IO.Ports namespace. MSCOMM is a legacy API and has always been a bit buggy.

jes1510
07-12-2009, 06:50 PM
Have you considered python? There are quit a few people around here (myself included) that use python over a serial port to great success. As a matter of fact I have code for an SSC32 in python.

The other option is using C# in .net. Adrenalynn wrote a great tutorial on how to get that working.

In general most people that work on "real" robots and computers shy away from any flavor of basic.

You also need to understand that for any programming language you probably need to start at "Hello World". You are begging for trouble if you grab someone else's code and modify it and you don't understand how it works.

Adrenalynn
07-12-2009, 08:15 PM
Consider downloading one of the .NET express editors and using the SerialPort object of the System.IO.Ports namespace. MSCOMM is a legacy API and has always been a bit buggy.

I actually tried the VB I posted in the first response - believe it or not it actually worked with a couple typo fixes...

Alex
07-13-2009, 09:15 AM
I'll second (or is it third:)) what Adrenalynn and MikeG are saying, go with .NET if you're going to use Visual Basic. I'd stay FAR away from Visual Basic 6 or VBScript ( BTW, (VBScript | VBA) != Visual Basic 6 although all the syntax is nearly identical). I'm with Adrenalynn, you can't pay me enough to program in Visual Basic 6. It's a very clunky language.

Visual Basic 2008 Express Edition can be downloaded for free and has a ton of excellent tutorials:

http://www.microsoft.com/express/vb/Default.aspx

Bevels
07-16-2009, 08:14 PM
Thanks Adrenalynn for your help. Your code was pretty much spot on (I think 1 line was missing) I just needed to download the MSCOMM32.ocx and register it. Then I had to reference it in my library in WinCC as an object and then it worked in the WinCC vbs. I finally got it working though and learned two programming languages in the process. Thanks a bunch.

Bevels
07-18-2009, 07:26 PM
So I got the control system for my servos working and I have a fully functional code. However, I was mounting the servos onto a crane as part of a research project for one of my professors. The servos had to communicate with some SIEMENS software called WinCC. This software interfaces with another PLC to operate the crane. There is a start button as part of our GUI that activate's the crane's PLC. My code works fine but when I start the PLC, it is almost as though it is sending signals to every port because when I start the crane my servos go haywire (no matter what port I connect it to). However, no one that I research with has ever programmed serial information into it.

The servo's only go haywire when I am operating them through WinCC and have the crane started. If I operate them through the lynxmotion terminal, they work fine even if the crane is running. I figured that the lynxmotion sets up its connection in such a way as to filter the data it receives. I was wondering if anyone knows what might cause this sort of problem and how to fix it by manipulating my port settings?

Adrenalynn
07-18-2009, 09:35 PM
Are you sending a 1500uS pulse to all servos upon bootup?

If you are and still getting issues, then unplug the serial cable that goes to the SSC32, put a null modem on it, and plug it into another PC. Run terminal software like the free "realterm" and watch the data you're sending vs the data lynxmotion is sending. That'll tell you where you've gone awry!

Can't debug what ya can't see.

Bevels
07-18-2009, 09:45 PM
What is the purpose of sending the 1500uS pule to all servos on bootup? (curiousity question)

Adrenalynn
07-18-2009, 11:23 PM
Centering all servos is a requirement - it wakes up and calibrates the controller in the servo.