I have a GPS from u-blox.com with a USB-connection and driver. The driver installs a virual COM port that pops up when you plug the USB in. Using a hyperterminal I can then
I have used the following code to communicate over USB to an Arduino, it send and receives a byte from the Arduino. It's simple, and isn't talking to a GPS, but hopefully it will help somehow!
public static byte ReadByte()
{
byte byteRead = new byte();
SerialPort port = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
port.Open();
int byteValue = port.ReadByte();
port.Close();
byteRead = Convert.ToByte(byteValue);
return byteRead;
}
public static void SendByte(byte packet)
{
SerialPort port = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
port.Open();
byte[] writeByte = new byte[1];
writeByte[0] = packet;
port.Write(writeByte, 0, 1);
port.Close();
}
I ran into a similar problem in an application I was writing and the problem turned out to be that I was trying to us SerialPort.WriteLine
which sends a \r\n
to end the line when I really needed to just send \n
. When I switched to SerialPort.Write
with a \n
appended to the end, everything worked as in HyperTerminal.
Try using handshakes/flow-control. They are also useful when employing a usb-serial adapter.