Exemplo n.º 1
0
        private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            Globals.Serial.ReadTimeout = 2000;
            byte        FailedCounter = 0;
            HDLC_Rx     DataRx        = new HDLC_Rx();
            List <byte> Buffer        = new List <byte>();

            HDLC_Rx.DPA_RX_STATE state = new HDLC_Rx.DPA_RX_STATE();
            //System.Threading.Thread.Sleep(1);

            while (backgroundWorker1.CancellationPending == false)
            {
                DataRx = new HDLC_Rx();
                state  = new HDLC_Rx.DPA_RX_STATE();
                Globals.Serial.DiscardInBuffer();
                while (!Send_RequestData())
                {
                    FailedCounter++;
                    if (FailedCounter >= 3)
                    {
                        Append_Output(">> Sending Request For Data Failed\n");
                        break;
                    }
                }

                #region Parse through Data

                while (state == HDLC_Rx.DPA_RX_STATE.DPA_RX_NOERR)
                {
                    try
                    {
                        state = DataRx.DPA_RX_Parse((byte)Globals.Serial.ReadByte());
                    }
                    catch (Exception excep)
                    {
                        Replace_Output(">> trig'd?\n");
                        break;
                    }
                }
                switch (state)
                {
                case HDLC_Rx.DPA_RX_STATE.DPA_RX_OK:
                    //Was a success, add code here
                    Replace_Output(">> trig'd\n");
                    Update_SamplingFreqLabel(BitConverter.ToUInt16(DataRx.Data.GetRange(200, 2).ToArray(), 0));
                    Plot_Series(DataRx.Data.GetRange(0, 200));
                    Calc_And_Plot_DFT(DataRx.Data.GetRange(0, 200));
                    break;

                case HDLC_Rx.DPA_RX_STATE.DPA_RX_FE:
                    Append_Output(">> An error in the calibration data frame.\n"); break;

                case HDLC_Rx.DPA_RX_STATE.DPA_RX_CRCERR:
                    break;
                }
            }
            #endregion
        }
Exemplo n.º 2
0
        private void button_single_Click(object sender, EventArgs e)
        {
            byte FailedCounter = 0;

            //Otherwise the system is already stopped
            button_RunStop.BackColor = System.Drawing.SystemColors.Control;
            button_single.BackColor  = System.Drawing.Color.Yellow;
            HDLC_Rx     DataRx = new HDLC_Rx();
            List <byte> Buffer = new List <byte>();

            HDLC_Rx.DPA_RX_STATE state = new HDLC_Rx.DPA_RX_STATE();
            DataRx = new HDLC_Rx();
            state  = new HDLC_Rx.DPA_RX_STATE();
            Globals.Serial.DiscardInBuffer();
            bool success = false;

            while (success == false)
            {
                while (!Send_RequestData())
                {
                    FailedCounter++;
                    if (FailedCounter >= 3)
                    {
                        Append_Output(">> Sending Request For Data Failed\n");
                        break;
                    }
                }

                while (state == HDLC_Rx.DPA_RX_STATE.DPA_RX_NOERR)
                {
                    try
                    {
                        state = DataRx.DPA_RX_Parse((byte)Globals.Serial.ReadByte());
                    }
                    catch (Exception excep)
                    {
                        Replace_Output(">> trig'd?\n");
                        break;
                    }
                }
                switch (state)
                {
                case HDLC_Rx.DPA_RX_STATE.DPA_RX_OK:
                    //Was a success, add code here
                    Replace_Output(">> trig'd\n");
                    Plot_Series(DataRx.Data.GetRange(0, 200));
                    Update_SamplingFreqLabel(BitConverter.ToUInt16(DataRx.Data.GetRange(200, 2).ToArray(), 0));
                    Calc_And_Plot_DFT(DataRx.Data.GetRange(0, 200));
                    button_single.BackColor  = System.Drawing.Color.Transparent;
                    button_RunStop.BackColor = System.Drawing.Color.Red;
                    success = true;
                    break;

                case HDLC_Rx.DPA_RX_STATE.DPA_RX_FE:
                    Append_Output(">> An error in the calibration data frame.\n"); break;

                case HDLC_Rx.DPA_RX_STATE.DPA_RX_CRCERR:
                    break;
                }
            }
        }