예제 #1
0
        private void DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            var _message = new List <byte>();

            while (true)
            {
                if (_serialPort.BytesToRead == 0)
                {
                    continue;
                }
                var _byte = (byte)_serialPort.ReadByte();
                if (_byte == EndByte)
                {
                    break;
                }
                if (_byte == JamByte)
                {
                    _message.RemoveAt(_message.Count - 1);
                }
                else
                {
                    _message.Add(_byte);
                }
            }
            _handler.Invoke(System.Text.Encoding.Default.GetString(_message.ToArray()), false);
        }
예제 #2
0
        private void DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            byte[] data = new byte[serialPort.BytesToRead];
            serialPort.Read(data, 0, data.Length);
            var acceptData = packer.Unpacking(data);

            if (acceptData == null)
            {
                return;
            }
            handler.Invoke(System.Text.Encoding.Default.GetString(acceptData), false);
        }