diff --git a/C-Windows-1/Form1.Designer.cs b/C-Windows-1/Form1.Designer.cs index 388564e..edb5edb 100644 --- a/C-Windows-1/Form1.Designer.cs +++ b/C-Windows-1/Form1.Designer.cs @@ -182,12 +182,16 @@ this.BtnCon1 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.labelyinjian = new System.Windows.Forms.Label(); + this.labelruanjian = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView1)).BeginInit(); this.menuStrip1.SuspendLayout(); this.groupBox1.SuspendLayout(); this.myGroupBox4.SuspendLayout(); this.myGroupBox3.SuspendLayout(); this.myGroupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); this.SuspendLayout(); // // SerialPort1 @@ -566,7 +570,7 @@ this.帮助ToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1034, 25); + this.menuStrip1.Size = new System.Drawing.Size(1045, 25); this.menuStrip1.TabIndex = 126; this.menuStrip1.Text = "menuStrip1"; // @@ -753,7 +757,7 @@ // checkBox1 // this.checkBox1.AutoSize = true; - this.checkBox1.Location = new System.Drawing.Point(889, 83); + this.checkBox1.Location = new System.Drawing.Point(900, 83); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(96, 16); this.checkBox1.TabIndex = 141; @@ -764,7 +768,7 @@ // codecheck // this.codecheck.Enabled = false; - this.codecheck.Location = new System.Drawing.Point(885, 56); + this.codecheck.Location = new System.Drawing.Point(896, 56); this.codecheck.Name = "codecheck"; this.codecheck.ReadOnly = true; this.codecheck.Size = new System.Drawing.Size(100, 21); @@ -775,7 +779,7 @@ // this.label9.AutoSize = true; this.label9.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.label9.Location = new System.Drawing.Point(892, 29); + this.label9.Location = new System.Drawing.Point(903, 29); this.label9.Name = "label9"; this.label9.Size = new System.Drawing.Size(87, 16); this.label9.TabIndex = 143; @@ -801,12 +805,13 @@ this.groupBox1.Controls.Add(this.label34); this.groupBox1.Controls.Add(this.Sunzong); this.groupBox1.Controls.Add(this.label28); - this.groupBox1.Location = new System.Drawing.Point(822, 127); + this.groupBox1.Location = new System.Drawing.Point(1140, 127); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(200, 161); this.groupBox1.TabIndex = 145; this.groupBox1.TabStop = false; this.groupBox1.Text = "产测计数"; + this.groupBox1.Visible = false; // // button1 // @@ -1547,11 +1552,43 @@ this.label6.TabIndex = 15; this.label6.Text = "9999"; // + // groupBox2 + // + this.groupBox2.Controls.Add(this.labelyinjian); + this.groupBox2.Controls.Add(this.labelruanjian); + this.groupBox2.Location = new System.Drawing.Point(816, 108); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(174, 184); + this.groupBox2.TabIndex = 149; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "设备信息"; + // + // labelyinjian + // + this.labelyinjian.AutoSize = true; + this.labelyinjian.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.labelyinjian.Location = new System.Drawing.Point(6, 140); + this.labelyinjian.Name = "labelyinjian"; + this.labelyinjian.Size = new System.Drawing.Size(95, 16); + this.labelyinjian.TabIndex = 24; + this.labelyinjian.Text = "硬件版本号:"; + // + // labelruanjian + // + this.labelruanjian.AutoSize = true; + this.labelruanjian.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.labelruanjian.Location = new System.Drawing.Point(6, 71); + this.labelruanjian.Name = "labelruanjian"; + this.labelruanjian.Size = new System.Drawing.Size(95, 16); + this.labelruanjian.TabIndex = 23; + this.labelruanjian.Text = "软件版本号:"; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1034, 617); + this.ClientSize = new System.Drawing.Size(1045, 617); + this.Controls.Add(this.groupBox2); this.Controls.Add(this.zhanhao); this.Controls.Add(this.button2); this.Controls.Add(this.progressBar1); @@ -1614,6 +1651,8 @@ this.myGroupBox3.PerformLayout(); this.myGroupBox1.ResumeLayout(false); this.myGroupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -1772,5 +1811,8 @@ public System.Windows.Forms.Button BtnBreak; public System.Windows.Forms.ComboBox UDPResults; public System.Windows.Forms.Button TCPconnect; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Label labelyinjian; + private System.Windows.Forms.Label labelruanjian; } } \ No newline at end of file diff --git a/C-Windows-1/Form1.cs b/C-Windows-1/Form1.cs index 905d65d..cc8d9aa 100644 --- a/C-Windows-1/Form1.cs +++ b/C-Windows-1/Form1.cs @@ -57,7 +57,7 @@ namespace C_Windows_1 private UdpClient udpClient; private const int Port = 9999; // 监听端口号 - private const int ReceiveTimeout = 5000; // 超时时间(毫秒) + private const int ReceiveTimeout = 3000; // 超时时间(毫秒) private bool isListening = false; // 监听标志位,控制是否继续监听 private Timer timeoutTimer; // 定时器用于控制超时 @@ -301,7 +301,7 @@ namespace C_Windows_1 - int i = 0; + int progressvalue = 0; public void ModbusRtuint(ModbusRtu X, byte station, string COM, int Bund, int numberbit, StopBits stopbit, Parity parity) { @@ -399,21 +399,21 @@ namespace C_Windows_1 case (int)yiqi.test://读取检测数据以及判断仪器是否结束 //operateResult21=Modbusread(170, 23, ReadData); Booltomath(2, ReadData); - progressBar2.Value = i; - i++; + progressBar2.Value = progressvalue; + progressvalue += 2; Modbusread(1013, 16, ReadData);//各项参数 Modbusread(1034, 26, ReadData); //Modbusread(25, 24, ReadData); //test(ReadData); //int ba = progressBar2.Value + 2; - //if (ba >= progressBar2.Maximum) - // ba = progressBar2.Maximum; - //progressBar2.Value = ba; + if (progressvalue >= progressBar2.Maximum) + progressvalue = progressBar2.Maximum; + progressBar2.Value = progressvalue; //if (!(grovalue > 99.8)) //{ // grovalue += grovalueone; - + // progressBar2.Value = (int)grovalue; //} //else @@ -421,7 +421,7 @@ namespace C_Windows_1 // progressBar2.Maximum = (int)grovalue; //} - + if (ReadData[2] == 0 && (ReadData[1041] == 1 || ReadData[1041] == 2))//当仪器状态位不为0且有结果时 { workstation = (int)yiqi.finish; @@ -467,13 +467,14 @@ namespace C_Windows_1 timerbar.Stop(); DataGridView1.Invoke(new System.Action(Display)); CreateFile(); - Passzong.Text = ChanPass.ToString(); - Sunzong.Text = ChanSum.ToString(); - string path = System.Environment.CurrentDirectory + "\\Config\\Config.ini"; - ConfigINI config = new ConfigINI(path); - config.IniWriteValue("Config", "Passzong", Passzong.Text); - config.IniWriteValue("Config", "Sunzong", Sunzong.Text); + //Passzong.Text = ChanPass.ToString(); + //Sunzong.Text = ChanSum.ToString(); + //string path = System.Environment.CurrentDirectory + "\\Config\\Config.ini"; + //ConfigINI config = new ConfigINI(path); + //config.IniWriteValue("Config", "Passzong", Passzong.Text); + //config.IniWriteValue("Config", "Sunzong", Sunzong.Text); Code.Clear(); + progressvalue = 0; workstation = (int)yiqi.standby; @@ -1011,15 +1012,15 @@ namespace C_Windows_1 if (ReadData[1041] == 2) { - ChanSum++; + //ChanSum++; Tlight.Text = "NG"; Tlight.ForeColor = Color.Red; } if (ReadData[1041] == 1) { - ChanPass++; - ChanSum++; + //ChanPass++; + //ChanSum++; Tlight.Text = "OK"; Tlight.ForeColor = Color.Green; } @@ -1141,42 +1142,42 @@ namespace C_Windows_1 workstation = (int)yiqi.standby; while (true) { - //Thread.Sleep(500); - //if (connectflag==1) - //{ - - // connect = modbusClient.Read("1006", 1);//判断连接是否正常 - // if (connect.IsSuccess) - // { - // TCPconnect.Enabled = false; - // PortNum.Text = modbusClient.IpAddress; - // label6.Text = modbusClient.Port.ToString(); - // label6.ForeColor = Color.Green; - // //Code.Focus(); - // } - // else - // { - // connectflag = 0; - // TCPconnect.Enabled = true; - // PortNum.Text = ""; - // label6.Text = "未连接"; - // label6.ForeColor = Color.Red; - // } - // machine2();//仪器读取线程 - // MachineDisplay();//仪器显示线程 + Thread.Sleep(500); + if (connectflag == 1) + { - // //if (MachineStatus.Text == "待机中" && connect.IsSuccess) - // //{ - // // Thread.Sleep(3000); - // // workstation = (int)yiqi.start; + connect = modbusClient.Read("1006", 1);//判断连接是否正常 + if (connect.IsSuccess) + { + TCPconnect.Enabled = false; + PortNum.Text = modbusClient.IpAddress; + label6.Text = modbusClient.Port.ToString(); + label6.ForeColor = Color.Green; + //Code.Focus(); + } + else + { + connectflag = 0; + TCPconnect.Enabled = true; + PortNum.Text = ""; + label6.Text = "未连接"; + label6.ForeColor = Color.Red; + } + machine2();//仪器读取线程 + MachineDisplay();//仪器显示线程 - // // MachineStatus.Text = ""; - // //} - //} - + // //if (MachineStatus.Text == "待机中" && connect.IsSuccess) + // //{ + // // Thread.Sleep(3000); + // // workstation = (int)yiqi.start; + + // // MachineStatus.Text = ""; + // //} + } - } + + } } ); @@ -1184,14 +1185,30 @@ namespace C_Windows_1 } + public string GetLocalIPAddress() + { + string localIP = ""; + foreach (var addr in Dns.GetHostAddresses(Dns.GetHostName())) + { + if (addr.AddressFamily == AddressFamily.InterNetwork) // 选择 IPv4 地址 + { + localIP = addr.ToString(); + break; + } + } + return localIP; + } + //点击“连接串口”按钮,连接串口 private void BtnCon1_Click(object sender, EventArgs e) { UDPResults.Items.Clear(); byte[] data = Encoding.ASCII.GetBytes("hello,udp server"); System.Net.IPAddress ip; - ip = System.Net.IPAddress.Parse("192.168.1.255"); - // 广播到 192.168.1.255 + string localip=GetLocalIPAddress(); + localip = localip.Substring(0, 10) + "255"; + ip = System.Net.IPAddress.Parse(localip); + // 获本机IP频段广播到 .255 IPEndPoint endPoint = new IPEndPoint(ip, Port); try @@ -3115,6 +3132,9 @@ namespace C_Windows_1 label6.ForeColor = Color.Green; station2 = Convert.ToUInt16(stationIP); station = station2.ToString("X2"); + Modbusread(360, 4, ReadData); + labelruanjian.Text = "软件版本号:" + ReadData[360].ToString("X4") + ReadData[361].ToString("X4"); + labelyinjian.Text = "硬件版本号:" + ReadData[362].ToString("X4") + ReadData[363].ToString("X4"); } diff --git a/C-Windows-1/TestPara.cs b/C-Windows-1/TestPara.cs index 25881b5..d3cac4e 100644 --- a/C-Windows-1/TestPara.cs +++ b/C-Windows-1/TestPara.cs @@ -123,11 +123,20 @@ namespace C_Windows_1 short g = Convert.ToInt16(Convert.ToDouble(DelayTime2.Text) * 10);//延时2 Form1.f1.modbusClient.Write("1012", g); - short h = Convert.ToInt16(Convert.ToDouble(BLeakTPre.Text));//平衡压差上限 - Form1.f1.modbusClient.Write("1017", h); - short i = Convert.ToInt16(Convert.ToDouble(BLeakLPre.Text));//平衡压差下限 - Form1.f1.modbusClient.Write("1019", i); + + List bigleakmax = new List();//压差上限 + bigleakmax.AddRange(XdrFloat(Convert.ToSingle(BLeakTPre.Text))); + byte[] bigleakda = bigleakmax.ToArray(); + Form1.f1.modbusClient.Write("1017", bigleakda); + + List bigleakmin = new List();//压差下限 + bigleakmin.AddRange(XdrFloat(Convert.ToSingle(BLeakLPre.Text))); + byte[] bigleakxiao = bigleakmin.ToArray(); + Form1.f1.modbusClient.Write("1019", bigleakxiao); + //BLeakLPre + + List parmEvolume = new List();//等效容积 parmEvolume.AddRange(XdrFloat(Convert.ToSingle(Evolume.Text))); byte[] pEvolume = parmEvolume.ToArray(); diff --git a/C-Windows-1/bin/Debug/Config/Config.ini b/C-Windows-1/bin/Debug/Config/Config.ini index e1026be..95f2d22 100644 --- a/C-Windows-1/bin/Debug/Config/Config.ini +++ b/C-Windows-1/bin/Debug/Config/Config.ini @@ -1,3 +1,3 @@ [Config] -Passzong=2810 -Sunzong=3039 +Passzong=2812 +Sunzong=3041 diff --git a/C-Windows-1/bin/Debug/LL28-Control.exe b/C-Windows-1/bin/Debug/LL28-Control.exe index 63e53c0..1075d0c 100644 Binary files a/C-Windows-1/bin/Debug/LL28-Control.exe and b/C-Windows-1/bin/Debug/LL28-Control.exe differ diff --git a/C-Windows-1/obj/Debug/LL28-Control.exe b/C-Windows-1/obj/Debug/LL28-Control.exe index 63e53c0..1075d0c 100644 Binary files a/C-Windows-1/obj/Debug/LL28-Control.exe and b/C-Windows-1/obj/Debug/LL28-Control.exe differ