Example #1
0
        public static void insert_fsv_data(FSV_DATA fsv_data)
        {
            try
            {
                FbCommand myCommand = new FbCommand();
                myCommand.Connection = connection;


                myCommand.CommandText = "insert into fsv_data(TXRX,freq,peak_freq,peak_level,trace_data) values(@TXRX,@freq,@peak_freq,@peak_level,@trace_data);";
                myCommand.Parameters.Clear();
                myCommand.Parameters.Add("TXRX", FbDbType.VarChar, 10);
                myCommand.Parameters.Add("freq", FbDbType.Double, 0);
                myCommand.Parameters.Add("peak_freq", FbDbType.Double, 0);
                myCommand.Parameters.Add("peak_level", FbDbType.Double, 0);
                myCommand.Parameters.Add("trace_data", FbDbType.Binary, 32765);

                myCommand.Parameters[0].Value = fsv_data.TXRX.Trim();
                myCommand.Parameters[1].Value = fsv_data.freq;
                myCommand.Parameters[2].Value = fsv_data.peak_freq;
                myCommand.Parameters[3].Value = fsv_data.peak_level;
                myCommand.Parameters[4].Value = fsv_data.trace_data;

                myCommand.ExecuteNonQuery();

                myCommand.Dispose();
            }
            catch (Exception e)
            {
                RadMessageBox.Show("Insert error!!");
            }
        }
Example #2
0
        private void fetch()
        {
            //decimal start = 0;
            //decimal stop = 0;
            //decimal interval = 0;
            try
            {
                Invoke((MethodInvoker) delegate
                {
                    chart_trace.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
                    chart_trace.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
                    chart_trace.ChartAreas[0].AxisX.ScaleView.Zoomable       = true;

                    chart_peak.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
                    chart_peak.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
                    chart_peak.ChartAreas[0].AxisX.ScaleView.Zoomable       = true;

                    decimal freq = Convert.ToDecimal(comboBox_freq.Text);
                    if (comboBox_freq_unit.SelectedIndex == 0)
                    {
                        freq *= 1000000000;
                    }
                    else if (comboBox_freq_unit.SelectedIndex == 1)
                    {
                        freq *= 1000000;
                    }
                    else if (comboBox_freq_unit.SelectedIndex == 2)
                    {
                        freq *= 1000;
                    }
                    else if (comboBox_freq_unit.SelectedIndex == 3)
                    {
                        freq *= 1;
                    }


                    decimal span = radSpinEditor_span.Value;
                    if (comboBox_span.SelectedIndex == 0)
                    {
                        span *= 1000000000;
                    }
                    else if (comboBox_span.SelectedIndex == 1)
                    {
                        span *= 1000000;
                    }
                    else if (comboBox_span.SelectedIndex == 2)
                    {
                        span *= 1000;
                    }
                    else if (comboBox_span.SelectedIndex == 3)
                    {
                        span *= 1;
                    }

                    //start = freq - span;
                    //stop = freq + span;
                    //interval = (stop - start) / (radSpinEditor_point.Value - 1);

                    //data_convert con_start = convert(start);
                    //data_convert con_stop = convert(stop);
                    //차트의 X축 최소값과 최대값, Y축 최소값과 최대값
                    //chart1.ChartAreas[0].AxisX.Minimum = Convert.ToDouble(start);
                    //chart1.ChartAreas[0].AxisX.Maximum = Convert.ToDouble(stop);
                    //chart1.ChartAreas[0].AxisX.Interval = (con_stop.data - con_start.data) / Convert.ToDouble(radSpinEditor_point.Value);
                    //chart1.ChartAreas[0].AxisY.Minimum = -150;
                    //chart1.ChartAreas[0].AxisY.Maximum = 0;


                    //LassoZoomController lassoZoomController = new LassoZoomController();
                    //radChartView_peak.Controllers.Add(lassoZoomController);

                    //ChartPanZoomController panZoomController = new ChartPanZoomController();
                    //panZoomController.PanZoomMode = ChartPanZoomMode.Horizontal;
                    //radChartView_peak.Controllers.Add(panZoomController);
                });

                string command = "INIT:CONT ON";
                session.Write(command);
                command = "FORM REAL,32";   // 바이트로 데이터를 받는다
                //command = "FORM ASCII";   // 콤마 구분자로 데이터를 받는다
                session.Write(command);

                Stopwatch sw = new Stopwatch();
                sw.Start();

                // 시리즈 초기화
                Invoke((MethodInvoker) delegate
                {
                    chart_trace.Series[0].Points.Clear();
                    for (int i = 0; i < 691; i++)
                    {
                        chart_trace.Series[0].Points.AddY(0.0);
                    }
                });


                while (true)
                {
                    //command = "INIT:CONM";
                    //session.Write(command);

                    command = "CALC:MARK1:MAX:PEAK";
                    session.Write(command);

                    command = "CALC:MARK1:X?";
                    double       resultX = Convert.ToDouble(session.Query(command));
                    data_convert con     = convert(resultX);

                    command = "CALC:MARK1:Y?";
                    double resultY = Convert.ToDouble(session.Query(command));
                    resultY = Math.Round(resultY, 2);

                    //Console.WriteLine("resultY : " + resultY);

                    command = "TRAC? TRACE1";
                    session.Write(command);

                    // 데이터가 바이너리로 넘어오는 경우
                    byte[] bytes = session.ReadByteArray();

                    char tmp = (char)bytes[0];
                    if (tmp.ToString() == "#")
                    {
                        tmp = (char)bytes[1];

                        int length = Convert.ToInt16(tmp.ToString());

                        string datalength = ((char)bytes[2]).ToString();
                        datalength += ((char)bytes[3]).ToString();
                        datalength += ((char)bytes[4]).ToString();
                        datalength += ((char)bytes[5]).ToString();

                        int datalength_int = Convert.ToInt32(datalength);

                        double[] values = new double[datalength_int / length];
                        Invoke((MethodInvoker) delegate
                        {
                            try
                            {
                                label_peakfreq.Text  = con.data.ToString("F6", CultureInfo.InvariantCulture) + " " + con.unit;
                                label_peaklevel.Text = resultY.ToString("F2", CultureInfo.InvariantCulture) + " dBm";
                                //label_peakfreq.Refresh();
                                //label_peaklevel.Refresh();

                                //chart_trace.Series[0].Points.Clear();

                                // TX/RX 판별
                                string txrx = "";

                                Decimal tx_upper = radSpinEditor_tx.Value + radSpinEditor_tx_limit.Value;
                                Decimal tx_lower = radSpinEditor_tx.Value - radSpinEditor_tx_limit.Value;
                                Decimal rx_upper = radSpinEditor_rx.Value + radSpinEditor_rx_limit.Value;
                                Decimal rx_lower = radSpinEditor_rx.Value - radSpinEditor_rx_limit.Value;

                                Decimal dBm = Convert.ToDecimal(resultY);
                                if (dBm >= tx_lower && dBm <= tx_upper)
                                {
                                    txrx = "TX";
                                    radPanel_tx.Visible = true;
                                }
                                else if (dBm >= rx_lower && dBm <= rx_upper)
                                {
                                    txrx = "RX";
                                    radPanel_rx.Visible = true;
                                }
                                else
                                {
                                    txrx = "NONE";
                                    radPanel_tx.Visible = false;
                                    radPanel_rx.Visible = false;
                                }

                                // Chart 그리기
                                if (checkBox_update.Checked)
                                {
                                    examplePointPairLitst.Clear();
                                    chart_trace.Series.SuspendUpdates();
                                    chart_trace.Series[0].Points.SuspendUpdates();
                                    for (int i = 0; i < values.Length; i++)
                                    {
                                        if (length == 4)
                                        {
                                            values[i] = BitConverter.ToSingle(bytes, i * length + 6);
                                        }
                                        else if (length == 8)
                                        {
                                            values[i] = BitConverter.ToDouble(bytes, i * length + 6);
                                        }
                                        //chart_trace.Series[0].Points.AddY(values[i]);
                                        chart_trace.Series[0].Points[i].SetValueY(values[i]);

                                        //examplePointPairLitst.Add(i, values[i]);
                                    }

                                    //zedGraphControl1.AxisChange();
                                    //zedGraphControl1.Invalidate();
                                    //zedGraphControl1.Update();

                                    chart_trace.Series[0].Points.ResumeUpdates();

                                    chart_trace.Series.ResumeUpdates();
                                    chart_trace.Update();


                                    chart_peak.Series.SuspendUpdates();
                                    chart_peak.Series[0].Points.AddXY(DateTime.Now.ToShortTimeString(), resultY);
                                    chart_peak.Series.ResumeUpdates();

                                    if (txrx == "TX")
                                    {
                                        System.Windows.Forms.DataVisualization.Charting.DataPoint pt = chart_peak.Series[0].Points[chart_peak.Series[0].Points.Count - 1];
                                        pt.MarkerColor = System.Drawing.Color.DeepSkyBlue;
                                        pt.MarkerSize  = 10;
                                        pt.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
                                    }
                                    else if (txrx == "RX")
                                    {
                                        System.Windows.Forms.DataVisualization.Charting.DataPoint pt = chart_peak.Series[0].Points[chart_peak.Series[0].Points.Count - 1];
                                        pt.MarkerColor = System.Drawing.Color.Red;
                                        pt.MarkerSize  = 10;
                                        pt.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
                                    }

                                    if (chart_peak.Series[0].Points.Count > 500)
                                    {
                                        chart_peak.Series[0].Points.RemoveAt(0);
                                    }

                                    if (chart_peak.ChartAreas[0].AxisX.Maximum > chart_peak.ChartAreas[0].AxisX.ScaleView.Size)
                                    {
                                        chart_peak.ChartAreas[0].AxisX.ScaleView.Scroll(chart_peak.ChartAreas[0].AxisX.Maximum);
                                    }
                                }

                                // data insert
                                if (resultY >= Convert.ToDouble(radSpinEditor_rec_limit.Value))
                                {
                                    radPanel_rec.Visible = true;

                                    FSV_DATA fsv_data   = new FSV_DATA();
                                    fsv_data.TXRX       = txrx;
                                    fsv_data.freq       = Convert.ToDouble(comboBox_freq.Text);
                                    fsv_data.peak_freq  = resultX;
                                    fsv_data.peak_level = resultY;
                                    fsv_data.trace_data = bytes;

                                    if (today_filename != DateTime.Now.ToShortDateString())
                                    {
                                        today_filename = DateTime.Now.ToShortDateString();
                                        Database.Connect();
                                    }
                                    Database.insert_fsv_data(fsv_data);
                                }
                                else
                                {
                                    radPanel_rec.Visible = false;
                                }

                                rec_count += 1;

                                if (sw.ElapsedMilliseconds > 1000)
                                {
                                    label_rec_count.Text = rec_count.ToString() + " Captures/Sec";
                                    label_rec_count.Refresh();
                                    rec_count = 0;
                                    sw.Restart();
                                }
                            }
                            catch (Exception ex)
                            {
                                //RadMessageBox.Show(ex.Message);
                            }
                        });
                    }
                }
            }
            catch (Exception e)
            {
            }
        }