private void tmrCheckForData_Tick(object sender, EventArgs e)
        {
            try
            {
                if (listeningPort == null || !listeningPort.IsOpen || stopReceiving)
                {
                    return;
                }

                int numberOfBytes = listeningPort.BytesToRead;

                if (listeningPort.BytesToRead <= 0 || dataProcessor.IsBusy())
                {
                    return;
                }

                byte[] buffer = new byte[numberOfBytes];

                numberOfBytes = listeningPort.Read(buffer, 0, numberOfBytes);

                if (numberOfBytes > 0)
                {
                    dataProcessor.ProcessData(buffer);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                Application.Exit();
            }
        }
Beispiel #2
0
        private void tmrCheckForData_Tick(object sender, EventArgs e)
        {
            if (listeningPort == null || !listeningPort.IsOpen)
            {
                return;
            }

            int numberOfBytes = listeningPort.BytesToRead;

            if (listeningPort.BytesToRead <= 0)
            {
                return;
            }

            byte[] buffer = new byte[numberOfBytes];

            numberOfBytes = listeningPort.Read(buffer, 0, numberOfBytes);

            if (numberOfBytes > 0)
            {
                dataProcessor.ProcessData(buffer);
                foreach (byte b in buffer)
                {
                    lstComPortDisplay.Items.Add(Convert.ToString(b, 16).PadLeft(2, '0').ToUpper());
                }
            }
        }