基于Java的Modbus TCP Client 通讯示例代码

package run;
import de.re.easymodbus.modbusclient.*;

public class run {
	public static void main(String[] args)
	{
		ModbusClient modbusClient = new ModbusClient("127.0.0.1",502);
		try
		{
			modbusClient.Connect();
			modbusClient.WriteSingleCoil(0, true);
			modbusClient.WriteSingleRegister(0, 1234);
			modbusClient.WriteMultipleRegisters(11, ModbusClient.ConvertFloatToTwoRegisters((float) 123.56));
			System.out.println(modbusClient.ReadCoils(0, 1)[0]);
			System.out.println(modbusClient.ReadHoldingRegisters(0, 1)[0]);
			System.out.println(ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(11, 2)));
		}
		catch (Exception e)
		{		
		}	
	}
}

相关新闻

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

邮箱

cloud@modbus.cn

QQ
QQ
微信
微信
SHARE
TOP