Beispiel #1
0
 private void ConnectForm_Shown(object sender, EventArgs e)
 {
     MainForm.serialPort          = new SerialPort();
     MainForm.serialPort.PortName = Properties.Settings.Default.SerialPortName;
     MainForm.serialPort.BaudRate = 115200;
     if (WFGlobal.OpenSerialPort(ref MainForm.serialPort, ""))
     {
         if (DLLWork.CheckDevice())
         {
             MainForm.bConnectedDevice = true;
             label1.Text        = "成功连接到硬件设备";
             progressBar1.Value = progressBar1.Maximum;
             WFGlobal.WaitMS(2000);
             this.Close();
             return;
         }
         else
         {
             MainForm.serialPort.Close();
         }
     }
     string[] ports = SerialPort.GetPortNames();
     Array.Sort(ports);
     progressBar1.Maximum = ports.Length - 1;
     progressBar1.Value   = 0;
     foreach (string port in ports)
     {
         Debug.WriteLine(port);
         progressBar1.PerformStep();
         WFGlobal.WaitMS(1);
         MainForm.serialPort.PortName = port;
         MainForm.serialPort.BaudRate = 115200;
         if (WFGlobal.OpenSerialPort(ref MainForm.serialPort, ""))
         {
             if (DLLWork.CheckDevice())
             {
                 Properties.Settings.Default.SerialPortName = port;
                 Properties.Settings.Default.Save();
                 MainForm.bConnectedDevice = true;
                 label1.Text        = "成功连接到硬件设备";
                 progressBar1.Value = progressBar1.Maximum;
                 WFGlobal.WaitMS(2000);
                 this.Close();
                 return;
             }
             else
             {
                 MainForm.serialPort.Close();
             }
         }
     }
     label1.Text = "未找到设备,请重新连接硬件设备";
     WFGlobal.WaitMS(2000);
     this.Close();
 }
Beispiel #2
0
        bool OpenUart()
        {
            Uart.PortName = cbCom.Text;
            RxPacket      = new CP1616Packet();
            if (WFGlobal.OpenSerialPort(ref Uart) == false)
            {
                return(false);
            }
            Properties.Settings.Default.PortName = cbCom.Text;
            Properties.Settings.Default.Save();

            return(true);
        }
Beispiel #3
0
 private void Form1_Load(object sender, EventArgs e)
 {
     toolStripStatusLabel1.Text    = "工作串口为" + serialPort1.PortName;
     CP1616PacketHead.Addr_SIZE    = 1;
     CP1616PacketHead.DataLen_SIZE = 1;
     CP1616PacketHead.CalcHeaderLen();
     if (!WFGlobal.OpenSerialPort(ref serialPort1, "工控机握手监测"))
     {
         this.Close();
         return;
     }
     RxCount = 0;
     TxCount = 0;
     HandWork();
     timer1.Enabled = true;
 }
Beispiel #4
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox1.Text.Length != 15)
     {
         MessageBox.Show("设备ID长度需要为15位");
         return;
     }
     if (oldID == textBox1.Text)
     {
         MessageBox.Show("不能两次连续下载相同ID");
         return;
     }
     if (button1.Text == "烧写")
     {
         progressBar1.Value = progressBar1.Minimum;
         serialPort1.Close();
         serialPort1.PortName = cbCom.Text;
         if (!WFGlobal.OpenSerialPort(ref serialPort1, "所选"))
         {
             return;
         }
         textBox1.Enabled = false;
         button1.Text     = "停止";
         bComRead         = true;
         Thread t = new Thread(ComProc_Read);
         t.Start();
     }
     else
     {
         bComRead = false;
         while (!bComReadExit)
         {
             ;
         }
         button1.Text = "烧写";
         serialPort1.Close();
         textBox1.Enabled = true;
     }
 }
Beispiel #5
0
 private void btNetStart_Click(object sender, EventArgs e)
 {
     if (btNetStart.Text == "启动网络")
     {
         Uart.PortName = cbCom.Text;
         RxPacket      = new CP1616Packet();
         if (WFGlobal.OpenSerialPort(ref Uart) == false)
         {
             return;
         }
         Properties.Settings.Default.PortName = cbCom.Text;
         Properties.Settings.Default.Save();
         sensorSingIn.clearSignIn();
         listView1.Items.Clear();
         chart1.Series[0].Points.Clear();
         chart2.Series[0].Points.Clear();
         chart3.Series[0].Points.Clear();
         chart4.Series[0].Points.Clear();
         chart3.Series[1].Points.Clear();
         chart4.Series[1].Points.Clear();
         chart3.Series[2].Points.Clear();
         chart4.Series[2].Points.Clear();
         chart3.Series[3].Points.Clear();
         chart4.Series[3].Points.Clear();
         bStopNet = false;
         for (int i = 0; i < 3; i++)
         {
             startResult = 0;
             waitCommand = 1;
             CP1616Packet.CP1616ComSend(ref Uart, waitCommand, 0, (ushort)0);
             int x = 0;
             while (true)
             {
                 Thread.Sleep(1);
                 if (startResult != 0)
                 {
                     break;
                 }
                 x++;
                 if (x > 1000)
                 {
                     startResult = 0xff;
                     break;
                 }
             }
             if (startResult == 0xff)//超时了
             {
             }
             else
             {
                 break;
             }
         }
         if (startResult == 0xff)
         {
             MessageBox.Show("网络控制器未做应答!!!");
             Uart.Close();
             btNetStart.Text = "启动网络";
             return;
         }
         else if (startResult == 2)
         {
             bStopNet        = false;
             btNetStart.Text = "停止网络";
             MessageBox.Show("网络已经启动,等待接入");
         }
         else if (startResult == 3)
         {
             bStopNet        = false;
             btNetStart.Text = "停止网络";
             MessageBox.Show("标定网络已经启动,将自动转为测量网络,等待接入");
         }
         else
         {
             WaitSometingForm.WaitSometing_Init();
             waitCommand = 0x10;//点名完成
             if (!WaitSometingForm.WaitSometing(10, 3000, "等待无线节点组网,预计时长25s"))
             {
                 waitCommand = 0;
                 Uart.Close();
                 MessageBox.Show("组网失败");
                 return;
             }
             if (listView1.Items.Count != 0)
             {
                 WaitSometingForm.WaitSometing_Init();
                 waitCommand = 0x20;//等待测量数据
                 if (!WaitSometingForm.WaitSometing(10, 500, "等待网络数据,预计时长3s"))
                 {
                     waitCommand = 0;
                     MessageBox.Show("组网失败");
                     Uart.Close();
                     bStopNet = false;
                     return;
                 }
                 bStopNet        = false;
                 btNetStart.Text = "停止网络";
                 MessageBox.Show("网络启动成功");
             }
             else
             {
                 waitCommand = 0;
                 MessageBox.Show("当前网络没有发现任何无线节点,网络自动停止");
                 Uart.Close();
                 btNetStart.Text = "启动网络";
                 return;
             }
         }
     }
     else
     {
         bStopNet = true;
         WaitSometingForm.WaitSometing_Init();
         waitCommand = 0x02;//等待网络停止
         if (!WaitSometingForm.WaitSometing(10, 500, "等待网络停止,预计时长5s"))
         {
             waitCommand = 0;
             MessageBox.Show("网络停止失败");
             return;
         }
         MessageBox.Show("网络已停止");
         Uart.Close();
         btNetStart.Text = "启动网络";
     }
 }