private void _checkport(object state) { int size = 0; if (Status == PortStatus.CLOSED) { return; } lock (_serial) { if (_serial.BytesToRead > 0) { size = _serial.Read(rbuf, 0, _serial.BytesToRead); } } if (size <= 0) { return; } int p = 0; while (size-- >= 0) { ifrm.pushc(rbuf[p++]); if (ifrm.flag == RF_STATE.RF_CKSUM) { if (InFrameHandlers.ContainsKey(ifrm.addr)) { InFrameHandlers[ifrm.addr](ifrm); } ifrm.ResetFlag(); } } }
public SPort(string PortName, int BaudRate, Parity Parity, int DataBits, StopBits StopBit) { _serial = new SerialPort(PortName, BaudRate, Parity, DataBits, StopBit); //_serial.DataReceived +=new SerialDataReceivedEventHandler(_serial_DataReceived); _serial.Handshake = Handshake.None; if (!NodeAgent.IsDebug) { _timer = new Timer(_checkport); _timer.Change(0, 3); } // _serial.ErrorReceived += new SerialErrorReceivedEventHandler(_serial_ErrorReceived); // _serial.RtsEnable = false; CmdToSend = new Queue <byte[]>(); InFrameHandlers = new Dictionary <byte, IOInFrameHandler>(); ifrm = new FrameBuffer(); ifrm.ResetFlag(); Status = PortStatus.CLOSED; }
public SPort(string PortName, int BaudRate, Parity Parity, int DataBits, StopBits StopBit) { _serial = new SerialPort(PortName, BaudRate, Parity, DataBits, StopBit); //_serial.DataReceived +=new SerialDataReceivedEventHandler(_serial_DataReceived); _serial.Handshake = Handshake.None; if (!NodeAgent.IsDebug) { _timer = new Timer(_checkport); _timer.Change(0, 3); } // _serial.ErrorReceived += new SerialErrorReceivedEventHandler(_serial_ErrorReceived); // _serial.RtsEnable = false; CmdToSend = new Queue<byte[]>(); InFrameHandlers = new Dictionary<byte, IOInFrameHandler>(); ifrm = new FrameBuffer(); ifrm.ResetFlag(); Status = PortStatus.CLOSED; }