public stm32f4_RxPacket CommandProc(ushort command, byte[] txdata, int rxTimeOut) { byte[] txBuf = stm32f4_TxPacket.MakeCP1616Packet(command, txdata); if (!WFNetLib.WFGlobal.OpenSerialPort(ref com, "stm32f4 pc端")) { return(null); } Debug.WriteLine(WFNetLib.StringFunc.StringsFunction.byteToHexStr(txBuf, " ")); com.ReadTimeout = rxTimeOut; com.Write(txBuf, 0, txBuf.Length); stm32f4_RxPacket ret = new stm32f4_RxPacket(command); while (true) { try { if (ret.DataPacketed((byte)com.ReadByte())) { com.Close(); return(ret); } } catch// (Exception ex) { //Debug.WriteLine("血糖通信失败" + ex.Message); //MessageBox.Show("发送错误"); //textBox2.Text = "发送错误"; com.Close(); return(null); } } }
public static stm32f4_RxPacket CP1616ComProc(ref SerialPort serialPort, ushort com, int retry) { stm32f4_RxPacket ret = new stm32f4_RxPacket(com); while (retry != 0) { while (true) { try { if (ret.DataPacketed((byte)serialPort.ReadByte())) { return(ret); } } catch// (Exception ex) { //Debug.WriteLine("血糖通信失败" + ex.Message); break; } } retry--; } return(null); }