我正在编写一个 C# 应用程序,用于同时从多个串行 COM 端口读取数据,以分析 IPOD 的数据通信。发送的数据需要解释为十六进制字节。例如,
0xFF 0x55 0x01 0x00 0x04 0xC3 0xFF 0x55 ...
例如,我希望能够阅读此内容并将其显示在富文本框中
0xFF 0x55 0x01 0x00 0x04 0xC3
0xFF 0x55 ...
Run Code Online (Sandbox Code Playgroud)
命令的开头包括标头(0xFF 0x55),其余部分是命令+参数+校验和。
解决这个问题的最佳方法是什么?
我目前有:
private delegate void SetTextDeleg(string text);
void sp_DataReceivedRx(object sender, SerialDataReceivedEventArgs e)
{
Thread.Sleep(500);
try
{
string data = IPODRxPort.ReadExisting(); // Is this appropriate??
// Invokes the delegate on the UI thread, and sends the data that was received to the invoked method.
// ---- The "si_DataReceived" method will be executed on …Run Code Online (Sandbox Code Playgroud)