示例#1
0
        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();
                }
            }
        }
示例#2
0
        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;


            CmdToSend       = new Queue <byte[]>();
            InFrameHandlers = new Dictionary <byte, IOInFrameHandler>();

            ifrm = new FrameBuffer();
            ifrm.ResetFlag();

            Status = PortStatus.CLOSED;
        }
示例#3
0
        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;

            
            CmdToSend = new Queue<byte[]>();
            InFrameHandlers = new Dictionary<byte, IOInFrameHandler>();
            
            ifrm = new FrameBuffer();
            ifrm.ResetFlag();

            Status = PortStatus.CLOSED;
        }