Esempio n. 1
0
        private void backgroundWorkerDevice_DoWork(object sender, DoWorkEventArgs e)
        {
            this.backgroundWorkerDevice.ReportProgress((int)BGW_STATES.BGW_MONIOR_OUTPUT, "Device BGW Started");

            ProtocolCommunicationsTiger nProtoCommsTiger = new ProtocolCommunicationsTiger();

            DateTime lastRXReportTime = DateTime.Now;

            while (!this.backgroundWorkerDevice.CancellationPending)
            {
                List <byte> dataIn = new List <byte>();

                //look for data from Device
                if (serialPort1.BytesToRead > 0)
                {
                    int nByte = this.serialPort1.ReadByte();

                    bool result = nProtoCommsTiger.BuildFrame((byte)nByte);

                    dataIn.Add((byte)nByte);

                    if (result == true)
                    {
                        //got a valid frame
                        byte[] nData = nProtoCommsTiger.GetFrameAsByteArray();

                        this.backgroundWorkerDevice.ReportProgress((int)BGW_STATES.BGW_MONIOR_OUTPUT, "New Frame:" +
                                                                   SupportFunctions.ByteArrayToString(nData, nData.Count()));
                    }

                    //update status term every 100ms
                    DateTime nTime = DateTime.Now;
                    TimeSpan lastReportTimePassed = nTime.Subtract(lastRXReportTime);

                    if (lastReportTimePassed.TotalMilliseconds >= 100)
                    {
                        String rxData = SupportFunctions.ByteListToString(dataIn);

                        dataIn.Clear();

                        this.backgroundWorkerDevice.ReportProgress((int)BGW_STATES.BGW_TERM_RX_UPDATE, rxData);
                    }
                }
                else
                {
                    //CPU Rest
                    System.Threading.Thread.Sleep(10);
                }
            }
        }
Esempio n. 2
0
 private void UpDateRawRxTerminal(List <byte> dataToSend)
 {
     this.richTextBoxRX.AppendText(SupportFunctions.ByteListToString(dataToSend));
 }