Quick Question

What is wrong with this? I am trying to communicate to a TReX motor controller. I need to send the following data “DA 1F 1F” or “0xDA 0x1F 0x1F”

using System; 
using System.IO.Ports; 
using System.Threading; 
public class PortChat 
    static SerialPort _serialPort; 
    public static void Main() 
        StringComparer stringComparer = StringComparer.OrdinalIgnoreCase; 
        // Create a new SerialPort object with default settings. 
        _serialPort = new SerialPort(); 
        _serialPort.PortName = "COM3"; 
        _serialPort.BaudRate = 19200; 
        _serialPort.DataBits = 8; 
        _serialPort.Parity = Parity.None; 
        _serialPort.StopBits = StopBits.One;         
        _serialPort.Write("Byte[DA 1F 1F]"); 


I’m pretty sure this line

_serialPort.Write("Byte[DA 1F 1F]");

is just sending the ASCII values of that string onto the serial port, which is not what you want. Try using the serial port function that takes a byte array instead.

- Ryan