private void ThreadScan()
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder sbLog = new StringBuilder();
            StringBuilder sbAll = new StringBuilder();
            FrameUnit frameUnit = FrameManager.CreateFrame(dataBuffer, 0x30); //�����κ�����֡
            float maxAmpliVal, minAmpliVal;
            float maxFreqVal, minFreqVal;
            float maxModFreqVal, minModFreqVal;

            Afg3022.FunGen fGen = new Afg3022.FunGen();

            try
            {
                byte[] buffer = new byte[1];
                buffer[0] = MRChannel;
                float tempVal;

                for (int i = 0; i < ((float)(numScanEnd.Value) - (float)(numScanStart.Value) + 0.1f) * 10; i++)
                {
                    while (fGen.SetFmFreq(0, (float)numScanStart.Value + i * 0.1f) == false)
                    {
                        MessageBox.Show("3022δ׼����");
                    }

                    sbLog.Length = 0;
                    sbLog.Append("!!!!!!!!!");
                    sbLog.Append(DateTime.Now.ToLongTimeString());
                    sbLog.Append("    3022�����Ƶ��");
                    sbLog.Append(((float)numScanStart.Value + i * 0.1f).ToString());
                    sbLog.Append("//{{{1\r\n");
                    AppendText(txtLog, sbLog.ToString());
                    Thread.Sleep(1000);

                    Protocol.FrameTransmit.Send(1, boardAddress1, 0x30, buffer, 1);
                    if (frameUnit.WaitData(3000) == false)
                    {
                        MessageBox.Show("�ղ�������");
                        ShowText(btnLowScan, "��ʼɨ��");
                        break;
                    }
                    else
                    {
                        sb.Length = 0;
                        for (int k = 8; k < frameUnit.FrameLength - 4; k += 2)
                        {
                            float chVal;
                            chVal = dataBuffer[k] + dataBuffer[k + 1] * 256;
                            sb.Append("ͨ��" + ((k - 8) / 2).ToString() + ":   " + chVal.ToString() + " ");

                            sb.Append("\r\n");
                        }
                        ShowText(txtVal, sb.ToString());
                        sbAll.Append(DateTime.Now.ToLongTimeString());
                        sbAll.Append(":\r\n");
                        sbAll.Append(sb.ToString());
                        sbAll.Append(":\r\n");

                        sbLog.Length = 0;
                        sbLog.Append("ʱ��\t��ѹ\tƵ��\t��Ƶ//{{{2\r\n");
                        sbLog.Append(DateTime.Now.ToLongTimeString());
                        sbLog.Append("\t");
                        tempVal = dataBuffer[8 + (int)numScanCh.Value * 2] + dataBuffer[9 + (int)numScanCh.Value * 2] * 256;
                        maxAmpliVal = tempVal;
                        minAmpliVal = tempVal;
                        sbLog.Append(tempVal.ToString());
                        sbLog.Append("\t");
                        tempVal = dataBuffer[10 + (int)numScanCh.Value * 2] + dataBuffer[11 + (int)numScanCh.Value * 2] * 256;
                        maxFreqVal = tempVal;
                        minFreqVal = tempVal;
                        sbLog.Append(tempVal.ToString());
                        sbLog.Append("\t");
                        tempVal = dataBuffer[12 + (int)numScanCh.Value * 2] + dataBuffer[13 + (int)numScanCh.Value * 2] * 256;
                        maxModFreqVal = tempVal;
                        minModFreqVal = tempVal;
                        sbLog.Append(tempVal.ToString());
                        sbLog.Append("\r\n");
                        AppendText(txtLog, sbLog.ToString());

                    }
                    #region ��ʼ�ɼ�

                    for (int j = 0; j < (int)(numTstTime.Value * 60); j++)
                    {
                        Thread.Sleep(1000);
                        Protocol.FrameTransmit.Send(1, boardAddress1, 0x30, buffer, 1);
                        if (frameUnit.WaitData(30) == false)
                        {
                            MessageBox.Show("�ղ�������");
                            ShowText(btnLowScan, "��ʼɨ��");
                            break;
                        }
                        else
                        {
                            sb.Length = 0;
                            for (int k = 8; k < frameUnit.FrameLength - 4; k += 2)
                            {
                                float chVal;
                                chVal = dataBuffer[k] + dataBuffer[k + 1] * 256;
                                sb.Append("ͨ��" + ((k - 8) / 2).ToString() + ":   " + chVal.ToString() + " ");
                                sb.Append("\r\n");
                            }
                            ShowText(txtVal, sb.ToString());
                            sbAll.Append(DateTime.Now.ToLongTimeString());
                            sbAll.Append(":\r\n");
                            sbAll.Append(sb.ToString());
                            sbAll.Append(":\r\n");

                            sbLog.Length = 0;

                            sbLog.Append(DateTime.Now.ToLongTimeString());
                            sbLog.Append("\t");
                            tempVal = dataBuffer[8 + (int)numScanCh.Value * 2] + dataBuffer[9 + (int)numScanCh.Value * 2] * 256;
                            if (tempVal > maxAmpliVal)
                            {
                                maxAmpliVal = tempVal;
                            }
                            if (tempVal < maxAmpliVal)
                            {
                                minAmpliVal = tempVal;
                            }
                            sbLog.Append(tempVal.ToString());
                            sbLog.Append("\t");
                            tempVal = dataBuffer[10 + (int)numScanCh.Value * 2] + dataBuffer[11 + (int)numScanCh.Value * 2] * 256;
                            if (tempVal > maxFreqVal)
                            {
                                maxFreqVal = tempVal;
                            }
                            if (tempVal < minFreqVal)
                            {
                                minFreqVal = tempVal;
                            }
                            sbLog.Append(tempVal.ToString());
                            sbLog.Append("\t");
                            tempVal = dataBuffer[12 + (int)numScanCh.Value * 2] + dataBuffer[13 + (int)numScanCh.Value * 2] * 256;
                            if (tempVal > maxModFreqVal)
                            {
                                maxModFreqVal = tempVal;
                            }
                            if (tempVal < minModFreqVal)
                            {
                                minModFreqVal = tempVal;
                            }
                            sbLog.Append(tempVal.ToString());
                            sbLog.Append("\r\n");
                            AppendText(txtLog, sbLog.ToString());
                        }

                    }
                    #endregion

                    sbLog.Length = 0;
                    sbLog.Append("//}}}2\r\n");
                    sbLog.Append("!!!!!!!!!");
                    sbLog.Append(DateTime.Now.ToLongTimeString());
                    sbLog.Append("    3022���Ե�Ƶ����\r\n");
                    sbLog.Append("!!!!!!!!!�������ֵ:");
                    sbLog.Append(maxAmpliVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!������Сֵ:");
                    sbLog.Append(minAmpliVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!Ƶ�����ֵ:");
                    sbLog.Append(maxFreqVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!Ƶ����Сֵ:");
                    sbLog.Append(minFreqVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!����Ƶ�����ֵ:");
                    sbLog.Append(maxModFreqVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!����Ƶ����Сֵ:");
                    sbLog.Append(minModFreqVal);
                    sbLog.Append("\r\n");
                    sbLog.Append(((float)numScanStart.Value + i * 0.1f).ToString());
                    sbLog.Append("//}}}1\r\n");
                    AppendText(txtLog, sbLog.ToString());

                }

            }
            catch (ThreadAbortException)
            {

            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }
Exemple #2
0
        private void ThreadScan()
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder sbLog = new StringBuilder();
            StringBuilder sbAll = new StringBuilder();
            FrameUnit     frameUnit = FrameManager.CreateFrame(dataBuffer, 0x30); //接收任何数据帧
            float         maxAmpliVal, minAmpliVal;
            float         maxFreqVal, minFreqVal;
            float         maxModFreqVal, minModFreqVal;



            Afg3022.FunGen fGen = new Afg3022.FunGen();

            try
            {
                byte[] buffer = new byte[1];
                buffer[0] = MRChannel;
                float tempVal;

                for (int i = 0; i < ((float)(numScanEnd.Value) - (float)(numScanStart.Value) + 0.1f) * 10; i++)
                {
                    while (fGen.SetFmFreq(0, (float)numScanStart.Value + i * 0.1f) == false)
                    {
                        MessageBox.Show("3022未准备好");
                    }

                    sbLog.Length = 0;
                    sbLog.Append("!!!!!!!!!");
                    sbLog.Append(DateTime.Now.ToLongTimeString());
                    sbLog.Append("    3022输出低频:");
                    sbLog.Append(((float)numScanStart.Value + i * 0.1f).ToString());
                    sbLog.Append("//{{{1\r\n");
                    AppendText(txtLog, sbLog.ToString());
                    Thread.Sleep(1000);


                    Protocol.FrameTransmit.Send(1, boardAddress1, 0x30, buffer, 1);
                    if (frameUnit.WaitData(3000) == false)
                    {
                        MessageBox.Show("收不到数据");
                        ShowText(btnLowScan, "开始扫描");
                        break;
                    }
                    else
                    {
                        sb.Length = 0;
                        for (int k = 8; k < frameUnit.FrameLength - 4; k += 2)
                        {
                            float chVal;
                            chVal = dataBuffer[k] + dataBuffer[k + 1] * 256;
                            sb.Append("通道" + ((k - 8) / 2).ToString() + ":   " + chVal.ToString() + " ");

                            sb.Append("\r\n");
                        }
                        ShowText(txtVal, sb.ToString());
                        sbAll.Append(DateTime.Now.ToLongTimeString());
                        sbAll.Append(":\r\n");
                        sbAll.Append(sb.ToString());
                        sbAll.Append(":\r\n");

                        sbLog.Length = 0;
                        sbLog.Append("时间\t电压\t频率\t低频//{{{2\r\n");
                        sbLog.Append(DateTime.Now.ToLongTimeString());
                        sbLog.Append("\t");
                        tempVal     = dataBuffer[8 + (int)numScanCh.Value * 2] + dataBuffer[9 + (int)numScanCh.Value * 2] * 256;
                        maxAmpliVal = tempVal;
                        minAmpliVal = tempVal;
                        sbLog.Append(tempVal.ToString());
                        sbLog.Append("\t");
                        tempVal    = dataBuffer[10 + (int)numScanCh.Value * 2] + dataBuffer[11 + (int)numScanCh.Value * 2] * 256;
                        maxFreqVal = tempVal;
                        minFreqVal = tempVal;
                        sbLog.Append(tempVal.ToString());
                        sbLog.Append("\t");
                        tempVal       = dataBuffer[12 + (int)numScanCh.Value * 2] + dataBuffer[13 + (int)numScanCh.Value * 2] * 256;
                        maxModFreqVal = tempVal;
                        minModFreqVal = tempVal;
                        sbLog.Append(tempVal.ToString());
                        sbLog.Append("\r\n");
                        AppendText(txtLog, sbLog.ToString());
                    }
                    #region 开始采集

                    for (int j = 0; j < (int)(numTstTime.Value * 60); j++)
                    {
                        Thread.Sleep(1000);
                        Protocol.FrameTransmit.Send(1, boardAddress1, 0x30, buffer, 1);
                        if (frameUnit.WaitData(30) == false)
                        {
                            MessageBox.Show("收不到数据");
                            ShowText(btnLowScan, "开始扫描");
                            break;
                        }
                        else
                        {
                            sb.Length = 0;
                            for (int k = 8; k < frameUnit.FrameLength - 4; k += 2)
                            {
                                float chVal;
                                chVal = dataBuffer[k] + dataBuffer[k + 1] * 256;
                                sb.Append("通道" + ((k - 8) / 2).ToString() + ":   " + chVal.ToString() + " ");
                                sb.Append("\r\n");
                            }
                            ShowText(txtVal, sb.ToString());
                            sbAll.Append(DateTime.Now.ToLongTimeString());
                            sbAll.Append(":\r\n");
                            sbAll.Append(sb.ToString());
                            sbAll.Append(":\r\n");

                            sbLog.Length = 0;

                            sbLog.Append(DateTime.Now.ToLongTimeString());
                            sbLog.Append("\t");
                            tempVal = dataBuffer[8 + (int)numScanCh.Value * 2] + dataBuffer[9 + (int)numScanCh.Value * 2] * 256;
                            if (tempVal > maxAmpliVal)
                            {
                                maxAmpliVal = tempVal;
                            }
                            if (tempVal < maxAmpliVal)
                            {
                                minAmpliVal = tempVal;
                            }
                            sbLog.Append(tempVal.ToString());
                            sbLog.Append("\t");
                            tempVal = dataBuffer[10 + (int)numScanCh.Value * 2] + dataBuffer[11 + (int)numScanCh.Value * 2] * 256;
                            if (tempVal > maxFreqVal)
                            {
                                maxFreqVal = tempVal;
                            }
                            if (tempVal < minFreqVal)
                            {
                                minFreqVal = tempVal;
                            }
                            sbLog.Append(tempVal.ToString());
                            sbLog.Append("\t");
                            tempVal = dataBuffer[12 + (int)numScanCh.Value * 2] + dataBuffer[13 + (int)numScanCh.Value * 2] * 256;
                            if (tempVal > maxModFreqVal)
                            {
                                maxModFreqVal = tempVal;
                            }
                            if (tempVal < minModFreqVal)
                            {
                                minModFreqVal = tempVal;
                            }
                            sbLog.Append(tempVal.ToString());
                            sbLog.Append("\r\n");
                            AppendText(txtLog, sbLog.ToString());
                        }
                    }
                    #endregion

                    sbLog.Length = 0;
                    sbLog.Append("//}}}2\r\n");
                    sbLog.Append("!!!!!!!!!");
                    sbLog.Append(DateTime.Now.ToLongTimeString());
                    sbLog.Append("    3022测试低频结束\r\n");
                    sbLog.Append("!!!!!!!!!幅度最大值:");
                    sbLog.Append(maxAmpliVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!幅度最小值:");
                    sbLog.Append(minAmpliVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!频率最大值:");
                    sbLog.Append(maxFreqVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!频率最小值:");
                    sbLog.Append(minFreqVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!调制频率最大值:");
                    sbLog.Append(maxModFreqVal);
                    sbLog.Append("\r\n");
                    sbLog.Append("!!!!!!!!!调制频率最小值:");
                    sbLog.Append(minModFreqVal);
                    sbLog.Append("\r\n");
                    sbLog.Append(((float)numScanStart.Value + i * 0.1f).ToString());
                    sbLog.Append("//}}}1\r\n");
                    AppendText(txtLog, sbLog.ToString());
                }
            }
            catch (ThreadAbortException)
            {
            }
            finally
            {
                FrameManager.DeleteFrame(frameUnit);
            }
        }