修改站号和IP
This commit is contained in:
@@ -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<byte[]> 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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user