嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
Modbus通信,Modbus做为服务器客户端实现方式;
try
{
if (modbusClient.Connected)
modbusClient.Disconnect();
if (cbbSelctionModbus.SelectedIndex == 0)
{
modbusClient.IPAddress = txtIpAddressInput.Text;
modbusClient.Port = int.Parse(txtPortInput.Text);
modbusClient.SerialPort = null;
//modbusClient.receiveDataChanged = new EasyModbus.ModbusClient.ReceiveDataChanged(UpdateReceiveData);
//modbusClient.sendDataChanged = new EasyModbus.ModbusClient.SendDataChanged(UpdateSendData);
//modbusClient.connectedChanged = new EasyModbus.ModbusClient.ConnectedChanged(UpdateConnectedChanged);
modbusClient.Connect();
}
if (cbbSelctionModbus.SelectedIndex == 1)
{
modbusClient.SerialPort = cbbSelectComPort.SelectedItem.ToString();
modbusClient.UnitIdentifier = byte.Parse(txtSlaveAddressInput.Text);
modbusClient.Baudrate = int.Parse(txtBaudrate.Text);
if (cbbParity.SelectedIndex == 0)
modbusClient.Parity = System.IO.Ports.Parity.Even;
if (cbbParity.SelectedIndex == 1)
modbusClient.Parity = System.IO.Ports.Parity.Odd;
if (cbbParity.SelectedIndex == 2)
modbusClient.Parity = System.IO.Ports.Parity.None;
if (cbbStopbits.SelectedIndex == 0)
modbusClient.StopBits = System.IO.Ports.StopBits.One;
if (cbbStopbits.SelectedIndex == 1)
modbusClient.StopBits = System.IO.Ports.StopBits.OnePointFive;
if (cbbStopbits.SelectedIndex == 2)
modbusClient.StopBits = System.IO.Ports.StopBits.Two;
modbusClient.Connect();
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, "Unable to connect to Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
}