private void button3_Click(object sender, EventArgs e) { byte[] data = new byte[1]; data[0] = (byte)numericUpDown2.Value; WaitSometingForm.WaitSometing_Init(); waitCommand = 7; CP1616Packet.CP1616ComSend(ref Uart, waitCommand, 0, data); if (!WaitSometingForm.WaitSometing(100, 150, "等待控制器读取节点标定系数,预计时长15s")) { waitCommand = 0; MessageBox.Show("读取失败!!!!!"); } waitCommand = 0; }
private void button1_Click(object sender, EventArgs e) { byte[] data = new byte[2]; data[1] = (byte)numericUpDown1.Value; data[0] = (byte)numericUpDown2.Value; if (numericUpDown2.Value == 0) { data[0] = 0xfe;//广播地址 } WaitSometingForm.WaitSometing_Init(); waitCommand = 4; CP1616Packet.CP1616ComSend(ref Uart, waitCommand, 0, data); if (!WaitSometingForm.WaitSometing(100, 150, "等待控制器设定节点ID,预计时长15s")) { waitCommand = 0; MessageBox.Show("设定失败!!!!!"); } waitCommand = 0; }
private void button1_Click(object sender, EventArgs e) { byte[] data = new byte[1 + 12]; float k, b, A; if (float.TryParse(textBox1.Text, out k) == false) { MessageBox.Show("节点斜率k输入有误"); return; } if (float.TryParse(textBox2.Text, out b) == false) { MessageBox.Show("节点截距b输入有误"); return; } if (float.TryParse(textBox3.Text, out A) == false) { MessageBox.Show("节点增益A输入有误"); return; } data[0] = (byte)numericUpDown2.Value; byte[] kbyte = BitConverter.GetBytes(k); byte[] bbyte = BitConverter.GetBytes(b); byte[] Abyte = BitConverter.GetBytes(A); for (int i = 0; i < 4; i++) { data[1 + i] = kbyte[i]; data[5 + i] = bbyte[i]; data[9 + i] = Abyte[i]; } WaitSometingForm.WaitSometing_Init(); waitCommand = 6; CP1616Packet.CP1616ComSend(ref Uart, waitCommand, 0, data); if (!WaitSometingForm.WaitSometing(100, 150, "等待控制器设定节点标定系数,预计时长15s")) { waitCommand = 0; MessageBox.Show("设定失败!!!!!"); } waitCommand = 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 = "启动网络"; } }
private void btNetStart_Click(object sender, EventArgs e) { if (btNetStart.Text == "启动网络") { sensorSingIn.clearSignIn(); listView1.Items.Clear(); for (int i = 0; i < 3; i++) { startResult = 0; waitCommand = 5; //timer1.Enabled = true; CP1616Packet.CP1616ComSend(ref Uart, waitCommand, 0, (ushort)0); int x = 0; while (true) { Thread.Sleep(1); if (startResult != 0) { break; } x++; if (x > 500) { startResult = 0xff; break; } } if (startResult == 0xff)//超时了 { } else { break; } } if (startResult == 0xff) { MessageBox.Show("网络控制器未做应答!!!"); return; } else if (startResult == 2) { waitCommand = 0x10; MessageBox.Show("网络已经启动,等待接入"); } else if (startResult == 3) { waitCommand = 0x10; MessageBox.Show("测量网络已经启动,将自动转为标定网络,等待接入"); } else { WaitSometingForm.WaitSometing_Init(); waitCommand = 0x10;//点名完成 if (!WaitSometingForm.WaitSometing(10, 3000, "等待无线节点组网,预计时长25s")) { waitCommand = 0; MessageBox.Show("组网失败"); return; } if (listView1.Items.Count != 0) { WaitSometingForm.WaitSometing_Init(); waitCommand = 0x22;//等待标定数据 if (!WaitSometingForm.WaitSometing(10, 500, "等待网络数据,预计时长3s")) { waitCommand = 0; MessageBox.Show("组网失败"); bStopNet = false; return; } bStopNet = false; btNetStart.Text = "停止网络"; MessageBox.Show("网络启动成功"); } else { waitCommand = 0; MessageBox.Show("当前网络没有发现任何无线节点,网络自动停止"); return; } } bStopNet = false; } else { bStopNet = true; WaitSometingForm.WaitSometing_Init(); waitCommand = 0x02;//等待网络停止 if (!WaitSometingForm.WaitSometing(10, 500, "等待网络停止,预计时长5s")) { waitCommand = 0; MessageBox.Show("网络停止失败"); return; } MessageBox.Show("网络已停止"); btNetStart.Text = "启动网络"; } }