void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { lock (lockObj) { if (OnReceiveData != null) { int count = serialPort.BytesToRead; serialPort.Read(rxBuffer, 0, count); ReceiveEventArgs eventArgs = new ReceiveEventArgs(rxBuffer, 0, count); eventArgs.PortName = (sender as SerialPort).PortName; OnReceiveData(this, eventArgs); } } }
public virtual void OnReceived(object sender, ReceiveEventArgs e) { }
void portReceiver_OnReceiveData(object sender, ReceiveEventArgs e) { //将收到的串口数据放入队列 dataQueue.EnqueueReceive(new EventArgsPackage(sender, e)); }