Ejemplo n.º 1
0
 protected void OnTimerMsgRecieved(MUDControlCData data)//触发事件方法
 {
     if (TimerMsgRevieced != null)
     {
         TimerMsgRevieced(this, data);
     }
 }
Ejemplo n.º 2
0
 //传给Timer的数据用于分析用户选择的物理量
 public void TimerShow(object sender, MUDControlCData data)
 {
     this.Invoke(new Action(() =>
     {
         //线圈检测状态和测速通讯线连接状态同时满足
         if (MUDControlC.CoilCheckState == false && Moduleflag == true)
         {
             //在用户设定的周期内
             if (runNum < runTime)
             {
                 button1.Enabled = false;
                 if (data.D == 1 && inFlag == false)
                 {
                     //测交通量
                     carCount++;
                     inFlag = true;
                 }
                 if (data.D == 0)
                 {
                     inFlag = false;//还原车辆第一次进入线圈的标志,以便再次计数
                 }
                 //测车速
                 speed += data.Speed;
                 //测时间
                 timeTotal += data.Time;
             }
         }
     }));
 }
Ejemplo n.º 3
0
        private void GetMsg()
        {
            try
            {
                while (true)
                {
                    byte[] arrRecMsg = new byte[12];
                    int    length    = client.Receive(arrRecMsg);
                    float  a         = 0;
                    float  b         = 0;
                    float  c         = 0;
                    float  d         = 0;
                    this.Invoke(new Action(() =>
                    {
                        if (comboBox1.SelectedIndex == 0)
                        {
                            a = arrRecMsg[9];
                            b = arrRecMsg[10];
                        }
                        if (comboBox1.SelectedIndex == 1)
                        {
                            a = arrRecMsg[7];
                            b = arrRecMsg[8];
                        }
                        c        = (a * 256 + b) / 100;        //频率
                        d        = (arrRecMsg[4] >> 4) & 0x01; //0 1
                        speed    = 0;
                        lastTime = 0;
                        if (d == 1 && inFlag == false)
                        {
                            inTime = System.DateTime.Now.Second * 1000 + System.DateTime.Now.Millisecond;//以毫秒为单位
                            inFlag = true;
                        }
                        if (d == 0 && inFlag == true)
                        {
                            outTime = System.DateTime.Now.Second * 1000 + System.DateTime.Now.Millisecond; //以毫秒为单位
                            inFlag  = false;                                                               //还原车辆第一次进入线圈的标志

                            //车辆离开线圈时计算时间和车速
                            lastTime = outTime - inTime;
                            speed    = Math.Round((0.3 * 1000 / lastTime), 2);
                        }
                        data = new MUDControlCData {
                            A = a, B = b, C = c, D = d, Time = lastTime, Speed = speed, State = frequencyState
                        };
                        OnMsgRecieved(data);
                        OnTimerMsgRecieved(data);
                    }));
                }
            }
            catch (SocketException ex)
            {
                client.Close();
                client.Dispose();
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 4
0
 //传给实时测速的数据
 public void Show(object sender, MUDControlCData data)
 {
     this.Invoke(new Action(() =>
     {
         int i;
         //输出速度
         if (MUDControlC.CoilCheckState == false && Moduleflag == true)
         {
             if (data.Speed != 0)
             {
                 i = dataGridView1.Rows.Add();
                 dataGridView1.Rows[i].Cells[0].Value = DateTime.Now.ToString("hh:mm:ss");
                 dataGridView1.Rows[i].Cells[1].Value = data.Speed;
             }
         }
         dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;
     }));
 }
Ejemplo n.º 5
0
 public void Show(object sender, MUDControlCData data)
 {
     this.Invoke(new Action(() =>
     {
         int i;
         //输出频率检测数据,不包含高低电平0/字段
         if (data.State == true && fretransferState == true)
         {
             i = dataGridView1.Rows.Add();
             dataGridView1.Rows[i].Cells[0].Value = DateTime.Now.ToString("hh:mm:ss");
             dataGridView1.Rows[i].Cells[1].Value = data.C;
         }
         //输出线圈检测数据,
         else if (data.State == false)
         {
             //仅输出频率数据
             if (fretransferState == true && levtransferState == false || fretransferState == true && levtransferState == true && frequency_CheckBox.Checked == true)
             {
                 i = dataGridView1.Rows.Add();
                 dataGridView1.Rows[i].Cells[0].Value = DateTime.Now.ToString("hh:mm:ss");
                 dataGridView1.Rows[i].Cells[1].Value = data.C;
             }
             //仅输出高低电平数据
             if (fretransferState == false && levtransferState == true && frequency_CheckBox.Checked == false)
             {
                 i = dataGridView1.Rows.Add();
                 dataGridView1.Rows[i].Cells[0].Value = DateTime.Now.ToString("hh:mm:ss");
                 dataGridView1.Rows[i].Cells[2].Value = data.D;
             }
             //输出频率数据和高低电平数据
             else if (frequency_CheckBox.Checked == false && levtransferState == true)
             {
                 i = dataGridView1.Rows.Add();
                 dataGridView1.Rows[i].Cells[0].Value = DateTime.Now.ToString("hh:mm:ss");
                 dataGridView1.Rows[i].Cells[1].Value = data.C;
                 dataGridView1.Rows[i].Cells[2].Value = data.D;
             }
         }
         dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;
     }));
 }