private void Uart_DataReceived(object sender, SerialDataReceivedEventArgs e) { int irx; byte rx; while (true) { try { irx = Uart.ReadByte(); } catch { return; } if (!Uart.IsOpen) { return; } if (irx == -1) { return; } rx = (byte)irx; if (RxPacket.DataPacketed(rx)) { if (uartRxProc != null) { uartRxProc(RxPacket); } RxPacket = new CP1616Packet(); } } }
void Uart_DataReceived(object sender, SerialDataReceivedEventArgs e) { int irx; byte rx; while (true) { try { irx = Uart.ReadByte(); } catch { return; } if (!Uart.IsOpen) { return; } if (irx == -1) { return; } rx = (byte)irx; if (RxPacket.DataPacketed(rx)) { byte[] data = new byte[2]; data[0] = RxPacket.Header.Command; if (waitCommand == RxPacket.Header.Command) { WaitSometingForm.bGenerateSometing = true; } if (bStopNet) { data[1] = 0x02;//要求关闭网络 CP1616Packet.CP1616ComSend(ref Uart, 3, 0, data); } else if (RxPacket.Header.Command == 1)//标定网络启动确认 { startResult = RxPacket.Data[0]; } else if (RxPacket.Header.Command == 0x22)//标定网络,请求转换为测量网络 { this.Invoke((EventHandler)(delegate { textBox1.AppendText(DateTime.Now.ToString("HH:mm:ss:ffff") + ":标定网络转换为测量网络\r\n"); })); startResult = 3; data[1] = 0x03; CP1616Packet.CP1616ComSend(ref Uart, 3, 0, data); } else if (RxPacket.Header.Command == 0x10) { data[1] = 0x00; CP1616Packet.CP1616ComSend(ref Uart, 3, 0, data); SignInProc(); } else if (RxPacket.Header.Command == 0x20) { startResult = 2; if (listView1.Items.Count == 0) { data[1] = 0x01;//请求传感器名单 CP1616Packet.CP1616ComSend(ref Uart, 3, 0, data); } else { data[1] = 0x00; CP1616Packet.CP1616ComSend(ref Uart, 3, 0, data); ADCDataProc(); } this.Invoke((EventHandler)(delegate { if (btNetStart.Text == "启动网络") { btNetStart.Text = "停止网络"; } })); } RxPacket = new CP1616Packet(); } } }