C# serial communication with u-blox gps

前端 未结 9 1759
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-06 11:12

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

相关标签:
9条回答
  • 2021-01-06 11:52

    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();
        }
    
    0 讨论(0)
  • 2021-01-06 12:02

    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.

    0 讨论(0)
  • 2021-01-06 12:03

    Try using handshakes/flow-control. They are also useful when employing a usb-serial adapter.

    0 讨论(0)
提交回复
热议问题