【发布时间】:2020-10-25 20:27:30
【问题描述】:
我正在尝试从以 HEX 格式发送数据的设备读取串行数据,然后将其写入 azure 中继流写入器到接收器应用程序。 设备正在发送这些十六进制值:16 51 1D 65 D4 A6 但是我的程序似乎正在阅读:
如何让串口读取 HEX 数据并通过流写入器发送?我在下面附上了我的代码。感谢您的帮助!
// Read from the serial and write to the hybrid connection.
var writes = Task.Run(async () => {
// var reader = Console.In;
var writer = new StreamWriter(relayConnection) { AutoFlush = true };
do
{
// Read serial data from the serial port.
string line = sp.ReadExisting();
// Write the line to the hybrid connection (Azure Relay)
if(line.ToString() != "")
{
await writer.WriteLineAsync(line);
}
//cancel connection and break loop
if (Main.disconnect == true)
{
break;
}
}
while (true);
});
【问题讨论】:
标签: c# azure serial-port hex streamwriter