I used pythons serial lib to write commands to a usb port:
ser = serial.Serial()
ser.port = 'com4'
ser.baudrate = 115200
ser.parity = serial.PARITY_NONE
ser.stopbits = serial.STOPBITS_ONE
ser.bytesize = serial.EIGHTBITS
ser.timeout = None
ser.open()
CMD_MOTOR_DRIVE=[1, 249, 3, 6, 42, 100]
ser.write(CMD_MOTOR_DRIVE_1)
Now I wants to do the same in c# with help of the SerialPort class:
SerialPort port = new SerialPort();
port.PortName = ports[0]; //"com4"
port.BaudRate = 115200;
port.Parity = Parity.None;
port.StopBits = StopBits.One;
port.DataBits = 8;
port.Open();
//System.Threading.Thread.Sleep(20);
if(port.IsOpen == true)
{
log.Info("Port has been opened");
}
while(true)
{
port.Write("1, 249, 3, 6, 11, 100");
}
I am able to open the port, but the controller seems not to response to the command of the port.Write(string) function. I do not know what is the corresponding way in c# to convert the command into a byte array. I think I have to use the port.Write((Byte[], Int32, Int32)) function and not the port.Write(string) one?