Communication with the SSC-32 Controller
The SSC-32 controller board exposes a serial port. If your computer no longer has a serial port then a USB-to-Serial adapter cable needs to be used. I bought the TRENDnet USB to Serial Converter from Amazon and used it successfully with Windows XP and Windows 7. I have not yet tried it on Linux but it should work there as well.
The code for communicating with the SSC-32 board resides in the SSC32Communication project under the SSC32Communication folder. The starting point is the SSC32Board class which initializes the serial port:
public class SSC32Board : IDisposable { private SerialPort m_SerialPort; private CommandRunner m_CommandRunner; public SSC32Board(string portName) { m_SerialPort = new System.IO.Ports.SerialPort(); m_SerialPort.PortName = portName; m_SerialPort.BaudRate = 115200; m_SerialPort.Parity = System.IO.Ports.Parity.None; m_SerialPort.DataBits = 8; m_SerialPort.StopBits = System.IO.Ports.StopBits.One; m_SerialPort.Open(); m_CommandRunner = new CommandRunner(m_SerialPort); }
The portName is a string in the format COM<x> where x is the number of the COM port assigned by your system to the connection to your board (e.g. COM4). In the case of the TRENDnet converter the configuration can be found in the registry. This allows me to determine the COM port automatically like so:
string portName = SerialPortHelper.FindProlificPortName(); using (SSC32Board board = new SSC32Board(portName)) { ... }
If you use another converter then you might either try our various COM ports or find the appropriate port via the Windows configuration UI.
Now that we have a serial port connection we can start communicating with the board. This is handled by the CommandRunner class which sends servo commands to the board. The class effectively performs two tasks:
- It sends the command text to the board using the serial port.
- It polls the board to find out whether the command has been completed.
The second task is required since any subsequent commands will be dropped unless they are sent after the previous command has been completed.The command completion check is very simple:
private void WaitForCommandCompletion() { while (!CommandCompleted()) { Thread.Sleep(TimeSpan.FromMilliseconds(10)); } return; } private bool CommandCompleted() { m_SerialPort.Write("Q\r"); char result = (char)m_SerialPort.ReadChar(); Console.WriteLine(result); if (result == '.') { return true; } else { return false; } }
Details about the communication protocol are listed here: www.lynxmotion.com/images/data/ssc-32.pdf.