关于SerialPort中的DataReceived事件的问题???
我想在DataReceived接受事件中一个字节一个字节的接受,并在当接收到一个16进制的FF时停止接受,该怎样写程序呢?
请教各位高手!!
[解决办法]
bool R = true; private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e) { if (!R) return; if (sReceiver.BytesToRead == 0) { return; } int ArraySum = sReceiver.BytesToRead; byte[] InputArray = new byte[ArraySum]; sReceiver.Read(InputArray, 0, ArraySum); foreach (byte b in InputArray) { if (b == 0xFF) { R = false; return; } //处理数据 } }