diff --git a/C-Windows-1/C-Windows-LL18.csproj b/C-Windows-1/C-Windows-LL18.csproj index 61ddbed..bfada0d 100644 --- a/C-Windows-1/C-Windows-LL18.csproj +++ b/C-Windows-1/C-Windows-LL18.csproj @@ -7,7 +7,7 @@ {A74FBD1F-1F9C-45CE-B3E2-6E80278C02B0} WinExe C_Windows_1 - LL18-Control + LL28-Control v4.7.2 512 true diff --git a/C-Windows-1/Form1.Designer.cs b/C-Windows-1/Form1.Designer.cs index c349d8b..388564e 100644 --- a/C-Windows-1/Form1.Designer.cs +++ b/C-Windows-1/Form1.Designer.cs @@ -111,6 +111,10 @@ this.Sunzong = new System.Windows.Forms.Label(); this.label28 = new System.Windows.Forms.Label(); this.CodePort1 = new System.IO.Ports.SerialPort(this.components); + this.timerbar = new System.Windows.Forms.Timer(this.components); + this.progressBar1 = new System.Windows.Forms.ProgressBar(); + this.button2 = new System.Windows.Forms.Button(); + this.zhanhao = new System.Windows.Forms.TextBox(); this.myGroupBox4 = new C_Windows_1.MyGroupBox(this.components); this.PUnit = new System.Windows.Forms.ComboBox(); this.label47 = new System.Windows.Forms.Label(); @@ -178,10 +182,6 @@ this.BtnCon1 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); - this.timerbar = new System.Windows.Forms.Timer(this.components); - this.progressBar1 = new System.Windows.Forms.ProgressBar(); - this.button2 = new System.Windows.Forms.Button(); - this.zhanhao = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView1)).BeginInit(); this.menuStrip1.SuspendLayout(); this.groupBox1.SuspendLayout(); @@ -538,7 +538,7 @@ // this.label18.AutoSize = true; this.label18.Font = new System.Drawing.Font("宋体", 15F); - this.label18.Location = new System.Drawing.Point(179, 38); + this.label18.Location = new System.Drawing.Point(189, 35); this.label18.Name = "label18"; this.label18.Size = new System.Drawing.Size(69, 20); this.label18.TabIndex = 70; @@ -547,7 +547,7 @@ // Code // this.Code.Font = new System.Drawing.Font("宋体", 18F); - this.Code.Location = new System.Drawing.Point(254, 28); + this.Code.Location = new System.Drawing.Point(264, 28); this.Code.Name = "Code"; this.Code.Size = new System.Drawing.Size(533, 35); this.Code.TabIndex = 51; @@ -785,7 +785,7 @@ // this.Scancode.AutoSize = true; this.Scancode.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.Scancode.Location = new System.Drawing.Point(790, 38); + this.Scancode.Location = new System.Drawing.Point(800, 38); this.Scancode.Name = "Scancode"; this.Scancode.Size = new System.Drawing.Size(90, 20); this.Scancode.TabIndex = 144; @@ -864,6 +864,35 @@ // this.CodePort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.CodePort1_DataReceived_1); // + // timerbar + // + this.timerbar.Interval = 200; + this.timerbar.Tick += new System.EventHandler(this.timerbar_Tick); + // + // progressBar1 + // + this.progressBar1.Location = new System.Drawing.Point(410, 258); + this.progressBar1.Name = "progressBar1"; + this.progressBar1.Size = new System.Drawing.Size(100, 23); + this.progressBar1.TabIndex = 146; + // + // button2 + // + this.button2.Location = new System.Drawing.Point(925, 351); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(84, 38); + this.button2.TabIndex = 147; + this.button2.Text = "修改站号"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // zhanhao + // + this.zhanhao.Location = new System.Drawing.Point(909, 319); + this.zhanhao.Name = "zhanhao"; + this.zhanhao.Size = new System.Drawing.Size(113, 21); + this.zhanhao.TabIndex = 148; + // // myGroupBox4 // this.myGroupBox4.Controls.Add(this.PUnit); @@ -1433,7 +1462,7 @@ this.myGroupBox1.Font = new System.Drawing.Font("宋体", 12F); this.myGroupBox1.Location = new System.Drawing.Point(6, 28); this.myGroupBox1.Name = "myGroupBox1"; - this.myGroupBox1.Size = new System.Drawing.Size(167, 240); + this.myGroupBox1.Size = new System.Drawing.Size(182, 240); this.myGroupBox1.TabIndex = 119; this.myGroupBox1.TabStop = false; this.myGroupBox1.Text = "连接设置"; @@ -1453,7 +1482,7 @@ this.UDPResults.FormattingEnabled = true; this.UDPResults.Location = new System.Drawing.Point(6, 48); this.UDPResults.Name = "UDPResults"; - this.UDPResults.Size = new System.Drawing.Size(153, 24); + this.UDPResults.Size = new System.Drawing.Size(170, 24); this.UDPResults.TabIndex = 63; // // PortNum @@ -1518,35 +1547,6 @@ this.label6.TabIndex = 15; this.label6.Text = "9999"; // - // timerbar - // - this.timerbar.Interval = 200; - this.timerbar.Tick += new System.EventHandler(this.timerbar_Tick); - // - // progressBar1 - // - this.progressBar1.Location = new System.Drawing.Point(410, 258); - this.progressBar1.Name = "progressBar1"; - this.progressBar1.Size = new System.Drawing.Size(100, 23); - this.progressBar1.TabIndex = 146; - // - // button2 - // - this.button2.Location = new System.Drawing.Point(925, 351); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(84, 38); - this.button2.TabIndex = 147; - this.button2.Text = "修改站号"; - this.button2.UseVisualStyleBackColor = true; - this.button2.Click += new System.EventHandler(this.button2_Click); - // - // zhanhao - // - this.zhanhao.Location = new System.Drawing.Point(909, 319); - this.zhanhao.Name = "zhanhao"; - this.zhanhao.Size = new System.Drawing.Size(113, 21); - this.zhanhao.TabIndex = 148; - // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -1620,7 +1620,6 @@ } #endregion - private System.Windows.Forms.Button BtnBreak; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox ReceiveText; private System.Windows.Forms.TextBox SendText; @@ -1765,12 +1764,13 @@ private System.Windows.Forms.DataGridViewTextBoxColumn Column17; private System.Windows.Forms.DataGridViewTextBoxColumn Column14; private System.Windows.Forms.DataGridViewTextBoxColumn Column15; - private System.Windows.Forms.ComboBox UDPResults; - private System.Windows.Forms.Button TCPconnect; private System.Windows.Forms.Timer timerbar; private System.Windows.Forms.ProgressBar progressBar1; private System.Windows.Forms.Button button2; private System.Windows.Forms.TextBox zhanhao; public System.Windows.Forms.TextBox Code; + public System.Windows.Forms.Button BtnBreak; + public System.Windows.Forms.ComboBox UDPResults; + public System.Windows.Forms.Button TCPconnect; } } \ No newline at end of file diff --git a/C-Windows-1/Form1.cs b/C-Windows-1/Form1.cs index 617e569..8e4c729 100644 --- a/C-Windows-1/Form1.cs +++ b/C-Windows-1/Form1.cs @@ -23,6 +23,7 @@ using System.Net.Sockets; using Timer = System.Windows.Forms.Timer; using System.Net; using static System.Windows.Forms.VisualStyles.VisualStyleElement; +using Org.BouncyCastle.Utilities.Net; namespace C_Windows_1 { @@ -47,7 +48,7 @@ namespace C_Windows_1 //public ModbusTcpNet modbusClient; public ModbusRtuOverTcp modbusClient /*= new ModbusRtuOverTcp("192.168.1.174", 9999)*/; //产测计数 - + // public static Form1 f1; public int ChanSum; public int ChanPass; @@ -60,7 +61,7 @@ namespace C_Windows_1 private bool isListening = false; // 监听标志位,控制是否继续监听 private Timer timeoutTimer; // 定时器用于控制超时 - int connectflag = 0; + public int connectflag = 0; public Form1() { f1 = this; @@ -1083,7 +1084,7 @@ namespace C_Windows_1 } - + OperateResult connect; @@ -1123,12 +1124,11 @@ namespace C_Windows_1 udpClient = new UdpClient(); udpClient.EnableBroadcast = true; udpClient.Client.ReceiveTimeout = ReceiveTimeout; - + //modbusClient.ReceiveTimeOut = 1000; - //modbusClient.ConnectTimeOut = 100; - //modbusClient.ReceiveTimeOut = 100; + @@ -1140,38 +1140,38 @@ namespace C_Windows_1 workstation = (int)yiqi.standby; while (true) { - Thread.Sleep(500); - if (connectflag==1) - { + //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();//仪器显示线程 + // 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();//仪器显示线程 - //if (MachineStatus.Text == "待机中" && connect.IsSuccess) - //{ - // Thread.Sleep(3000); - // workstation = (int)yiqi.start; + // //if (MachineStatus.Text == "待机中" && connect.IsSuccess) + // //{ + // // Thread.Sleep(3000); + // // workstation = (int)yiqi.start; - // MachineStatus.Text = ""; - //} - } + // // MachineStatus.Text = ""; + // //} + //} @@ -1188,8 +1188,8 @@ namespace C_Windows_1 { UDPResults.Items.Clear(); byte[] data = Encoding.ASCII.GetBytes("hello,udp server"); - IPAddress ip; - ip = IPAddress.Parse("192.168.1.255"); + System.Net.IPAddress ip; + ip = System.Net.IPAddress.Parse("192.168.1.255"); // 广播到 192.168.1.255 IPEndPoint endPoint = new IPEndPoint(ip, Port); @@ -1214,7 +1214,7 @@ namespace C_Windows_1 { if (!isListening) return; - IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, Port); + IPEndPoint remoteEndPoint = new IPEndPoint(System.Net.IPAddress.Any, Port); byte[] receivedData = udpClient.EndReceive(ar, ref remoteEndPoint); string receivedMessage = Encoding.ASCII.GetString(receivedData); @@ -1242,7 +1242,7 @@ namespace C_Windows_1 try { connectflag = 0; - if (connect.IsSuccess) + //if (connect.IsSuccess) { connectflag = 0; modbusClient.ConnectClose(); @@ -1911,13 +1911,13 @@ namespace C_Windows_1 //{ // MessageBox.Show("条码长度设置错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; //} - //modbusClient.Write("0", true); - workstation = (int)yiqi.start; - Code.Focus(); - //workstation = (int)yiqi.start; - - + modbusClient.Write("0", true); + //workstation = (int)yiqi.start; + + + //workstation = (int)yiqi.start; + //Code.Focus(); } @@ -2035,9 +2035,10 @@ namespace C_Windows_1 { try { - workstation = (int)yiqi.rst; - //Code.Clear(); - Code.Focus(); + //workstation = (int)yiqi.rst; + + //Code.Focus(); + modbusClient.Write("1", true); } catch (Exception ex) { @@ -3081,32 +3082,41 @@ namespace C_Windows_1 { } + string stationIP; + string ipAddress; private void TCPconnect_Click(object sender, EventArgs e) { - //根据:符号分割站号和密码 + //根据:符号分割站号和IP string[] parts = UDPResults.Text.Split(':'); // 确保分割结果符合预期 if (parts.Length == 2) { // 站号 - string station = parts[0]; + stationIP = parts[0]; // IP 地址 - string ipAddress = parts[1]; + ipAddress = parts[1]; - modbusClient = new ModbusRtuOverTcp(ipAddress, 9999, Convert.ToByte(station)); - if(modbusClient.ConnectServer().IsSuccess) + modbusClient = new ModbusRtuOverTcp(ipAddress, 9999, Convert.ToByte(stationIP)); + //modbusClient.ConnectTimeOut = 1000; + //modbusClient.ReceiveTimeOut = 1000; + if (modbusClient.ConnectServer().IsSuccess) { connectflag = 1; TCPconnect.Enabled = false; + PortNum.Text = modbusClient.IpAddress; + label6.Text = modbusClient.Port.ToString(); + label6.ForeColor = Color.Green; + station2 = Convert.ToUInt16(stationIP); + station = station2.ToString("X2"); } - + } else { @@ -3123,10 +3133,37 @@ namespace C_Windows_1 } + OperateResult changestation=new OperateResult(); + public static string station; + + public static ushort station2; + private void button2_Click(object sender, EventArgs e) { - ushort station = Convert.ToUInt16(zhanhao.Text); - modbusClient.Write("1076", station); + station2 = Convert.ToUInt16(zhanhao.Text); + modbusClient.Read("0", (ushort)1); + changestation =modbusClient.Write("1076", station2); + if (changestation.IsSuccess) + { + + station = station2.ToString("X2"); + connectflag = 0; + modbusClient.ConnectClose(); + Thread.Sleep(200); + modbusClient = new ModbusRtuOverTcp(ipAddress, 9999, Convert.ToByte(station2)); + Thread.Sleep(200); + if (modbusClient.ConnectServer().IsSuccess) + { + connectflag = 1; + TCPconnect.Enabled = false; + PortNum.Text = modbusClient.IpAddress; + label6.Text = modbusClient.Port.ToString(); + UDPResults.Text = station2.ToString() + ":" + modbusClient.IpAddress; + label6.ForeColor = Color.Green; + + MessageBox.Show("仪器站号修改为" + station2); + } + } } private void label28_Click(object sender, EventArgs e) diff --git a/C-Windows-1/bin/28修改站号IP.rar b/C-Windows-1/bin/28修改站号IP.rar new file mode 100644 index 0000000..2de08b4 Binary files /dev/null and b/C-Windows-1/bin/28修改站号IP.rar differ diff --git a/C-Windows-1/bin/Debug/LL18-Control.exe b/C-Windows-1/bin/Debug/LL28-Control.exe similarity index 85% rename from C-Windows-1/bin/Debug/LL18-Control.exe rename to C-Windows-1/bin/Debug/LL28-Control.exe index 0c4b964..63e53c0 100644 Binary files a/C-Windows-1/bin/Debug/LL18-Control.exe and b/C-Windows-1/bin/Debug/LL28-Control.exe differ diff --git a/C-Windows-1/bin/Debug/LL18-Control.exe.config b/C-Windows-1/bin/Debug/LL28-Control.exe.config similarity index 100% rename from C-Windows-1/bin/Debug/LL18-Control.exe.config rename to C-Windows-1/bin/Debug/LL28-Control.exe.config diff --git a/C-Windows-1/configIP.cs b/C-Windows-1/configIP.cs index abadb8e..84b1266 100644 --- a/C-Windows-1/configIP.cs +++ b/C-Windows-1/configIP.cs @@ -1,4 +1,5 @@ using HslCommunication; +using HslCommunication.ModBus; using NPOI.SS.Formula.Functions; using System; using System.Collections.Generic; @@ -6,7 +7,9 @@ using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; +using System.Reflection.Emit; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -22,10 +25,10 @@ namespace C_Windows_1 private void configIP_Load(object sender, EventArgs e) { IPAddress.Text = "192.168.1.XXX"; - IPGateway.Text = "255.255.255.0"; - SubnetMask.Text = "192.168.1.1"; + IPGateway.Text = "192.168.1.1"; + SubnetMask.Text = "255.255.255.0"; } - + private void Save_Click(object sender, EventArgs e) { @@ -66,22 +69,47 @@ namespace C_Windows_1 int a = 435; string ARD = "0435"; string ARD2 = "0000"; - string SendText = "0110" + ARD + "0007" + "0e" + ipone + iptwo + wgone + wgtwo + zwone + zwtwo + ARD2; + string SendText = "01" + "10" + ARD + "0007" + "0e" + ipone + iptwo + wgone + wgtwo + zwone + zwtwo + ARD2; if (FixedIP.Checked == true) { ARD2 = "0001"; - SendText = "0110" + ARD + "0007" + "0e" + ipone + iptwo + wgone + wgtwo + zwone + zwtwo + ARD2; + SendText = Form1.station+"10" + ARD + "0007" + "0e" + ipone + iptwo + wgone + wgtwo + zwone + zwtwo + ARD2; } else { ARD2 = "0000"; - SendText = "0110" + ARD + "0007" + "0e" + ipone + iptwo + wgone + wgtwo + zwone + zwtwo + ARD2; + SendText = Form1.station+"10" + ARD + "0007" + "0e" + ipone + iptwo + wgone + wgtwo + zwone + zwtwo + ARD2; } - + Form1.f1.modbusClient.Read("0", (ushort)1); OperateResult read = Form1.f1.modbusClient.ReadFromCoreServer(HslCommunication.BasicFramework.SoftBasic.HexStringToBytes(SendText)); if (read.IsSuccess) { - Form1.f1.Code.Text = "结果:" + HslCommunication.BasicFramework.SoftBasic.ByteToHexString(read.Content, ' '); + // Form1.f1.Code.Text = "结果:" + HslCommunication.BasicFramework.SoftBasic.ByteToHexString(read.Content, ' '); + + //Form1.f1.connectflag = 0; + //Form1.f1.modbusClient.ConnectClose(); + ////Thread.Sleep(200); + //Form1.f1.modbusClient = new ModbusRtuOverTcp(IPAddress.Text, 9999, Convert.ToByte(Form1.station2)); + //Thread.Sleep(200); + //if (Form1.f1.modbusClient.ConnectServer().IsSuccess) + //{ + // Form1.f1.connectflag = 1; + // Form1.f1.TCPconnect.Enabled = false; + // Form1.f1.PortNum.Text = Form1.f1.modbusClient.IpAddress; + // Form1.f1.label6.Text = Form1.f1.modbusClient.Port.ToString(); + // Form1.f1.UDPResults.Text = Form1.station2.ToString() + ":" + IPAddress.Text; + // Form1.f1.label6.ForeColor = Color.Green; + // MessageBox.Show("IP修改成功"); + + //} + + Form1.f1.connectflag = 0; + Form1.f1.TCPconnect.Enabled = true; + Form1.f1.PortNum.Text = Form1.f1.modbusClient.IpAddress; + Form1.f1.label6.Text = Form1.f1.modbusClient.Port.ToString(); + Form1.f1.UDPResults.Text = Form1.station2.ToString() + ":" + IPAddress.Text; + Form1.f1.label6.ForeColor = Color.Red; + MessageBox.Show("IP修改成功"); } else { diff --git a/C-Windows-1/obj/Debug/C-Windows-LL18.csproj.FileListAbsolute.txt b/C-Windows-1/obj/Debug/C-Windows-LL18.csproj.FileListAbsolute.txt index 8b8b487..b348d5f 100644 --- a/C-Windows-1/obj/Debug/C-Windows-LL18.csproj.FileListAbsolute.txt +++ b/C-Windows-1/obj/Debug/C-Windows-LL18.csproj.FileListAbsolute.txt @@ -881,9 +881,6 @@ D:\新28\新TCP28上位机\C-Windows-1\obj\Debug\C-Windows-LL18.csproj.CoreCompi D:\新28\新TCP28上位机\C-Windows-1\obj\Debug\C-Window.5B87B986.Up2Date D:\新28\新TCP28上位机\C-Windows-1\obj\Debug\LL18-Control.exe D:\新28\新TCP28上位机\C-Windows-1\obj\Debug\LL18-Control.pdb -D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\bin\Debug\LL18-Control.exe.config -D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\bin\Debug\LL18-Control.exe -D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\bin\Debug\LL18-Control.pdb D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\bin\Debug\BouncyCastle.Cryptography.dll D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\bin\Debug\Enums.NET.dll D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\bin\Debug\ExtendedNumerics.BigDecimal.dll @@ -958,6 +955,9 @@ D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\obj\Debug\C_Windows_1.UserPassword D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\obj\Debug\C-Windows-LL18.csproj.GenerateResource.cache D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\obj\Debug\C-Windows-LL18.csproj.CoreCompileInputs.cache D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\obj\Debug\C-Window.5B87B986.Up2Date -D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\obj\Debug\LL18-Control.exe -D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\obj\Debug\LL18-Control.pdb D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\obj\Debug\C_Windows_1.configIP.resources +D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\bin\Debug\LL28-Control.exe.config +D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\bin\Debug\LL28-Control.exe +D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\bin\Debug\LL28-Control.pdb +D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\obj\Debug\LL28-Control.exe +D:\tcpoverrtu28\新TCP28上位机\C-Windows-1\obj\Debug\LL28-Control.pdb diff --git a/C-Windows-1/obj/Debug/LL18-Control.exe b/C-Windows-1/obj/Debug/LL28-Control.exe similarity index 85% rename from C-Windows-1/obj/Debug/LL18-Control.exe rename to C-Windows-1/obj/Debug/LL28-Control.exe index 0c4b964..63e53c0 100644 Binary files a/C-Windows-1/obj/Debug/LL18-Control.exe and b/C-Windows-1/obj/Debug/LL28-Control.exe differ