我正在尝试从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);
}
无论我尝试什么,最终都会得到类似的东西:
?J?&%%%%%%%%% ?? ?%$$$$$$$$$ f Qx?++++ ******?! ? ? #???? )xm ???? = ?? ? ?????? ???? ]? ? D0? ?????? 3 4 ???? 2 \