Exemplo n.º 1
0
        private async void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            int bytesToRead = serialPort1.BytesToRead;
            int bytesCnt    = 0;

            int[]   buf = new int[bytesToRead];
            string  str = "";
            TextBox tb  = textBoxLog;

            while (bytesCnt < bytesToRead)
            {
                buf[bytesCnt++] = serialPort1.ReadByte();
            }

            m_ProtocolDeSerializer.AddBytes(buf);

            bytesCnt = 0;
            while (bytesCnt < bytesToRead)
            {
                str += buf[bytesCnt++].ToString() + ',';
            }

            str += "\r\n";
            //str = m_ProtocolDeSerializer.ToString();
            //this.textBoxLog.BeginInvoke((MethodInvoker)(() => this.textBoxLog.Text = str));
        }
Exemplo n.º 2
0
        private async void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            int bytesToRead = serialPort1.BytesToRead;
            int bytesCnt    = 0;

            int[]   buf = new int[bytesToRead];
            string  str = "";
            TextBox tb  = textBoxLog;

            while (bytesCnt < bytesToRead)
            {
                buf[bytesCnt++] = serialPort1.ReadByte();
            }

            m_ProtocolDeSerializer.AddBytes(buf);

            bytesCnt = 0;
            string hex_string = "";

            while (bytesCnt < bytesToRead)
            {
                char ch = (buf[bytesCnt] == 0) ? ('0') : ((char)buf[bytesCnt]);
                hex_string += buf[bytesCnt].ToString() + ',';
                str        += ch;
                bytesCnt++;
            }

            str += "\r\n";
            //str = m_ProtocolDeSerializer.ToString();
            this.textBoxLog.BeginInvoke((MethodInvoker)(() => this.textBoxLog.Text += str + hex_string));
        }