如何从串口读取GPS数据

时间:2019-09-20 21:14:07

标签: c# serial-port gps

我正在尝试从BU-353S4 USB GPS读取串行端口上输入的数据。就可读的NMEA句子而言,我什么也没得到。 GPS与Raspberry Pi完美配合。

这是用于.NET控制台应用程序。整个网络上都有类似的问题,但是似乎没有一个样本有效。

var port = new SerialPort
{
    PortName = "COM5",
    BaudRate = 4800,
    Parity = Parity.None,
    DataBits = 8,
    StopBits = StopBits.One,
};
port.DataReceived += Port_DataReceived;


private static void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    string line = "";
    SerialPort port = (SerialPort)sender;
    line = port.ReadExisting();
    Console.Write(line);
}

和...

private static void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    SerialPort port = (SerialPort)sender;
    var count = port.BytesToRead;
    var buffer = new byte[count];
    port.Read(buffer, 0, count);
    var line = Encoding.ASCII.GetString(buffer);
    Console.Write(line);
}

无论我尝试什么,最终都会得到类似的东西:

?))))))(((((((#Y?“” !!!!!!!!!!??? z?----------?D??

?J?&%%%%%%%%% ?? ?%$$$$$$$$$ f Qx?++++ ******?! ? ? #???? )xm ???? = ?? ?     ?????? ???? ]? ? D0? ?????? 3 4 ???? 2 \

1 个答案:

答案 0 :(得分:0)

原来,GPS正在发送SiRF而不是NMEA。一旦按照this SuperUser post中的步骤将其切换到NMEA,一切都将正常运行!