C# serial communication with u-blox gps

前端 未结 9 1899
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  •  猫巷女王i
    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();
        }
    

提交回复
热议问题