-
Notifications
You must be signed in to change notification settings - Fork 59
Methods ModbusClient
ModbusClient()
Constructor - Executed when Object is created
ModbusClient(string ipAddress, int port)
Constructor - Executed when object is created
Parameter ipAddress: IP-Address of Modbus-TCP Server
Parameter port: Port of Modbus-TCP Server listening
void Connect()
Connects to the Modbus-TCP Server or Modbus-RTU Slave
void Connect(string ipAddress, int port)
Connects to the Modbus-TCP Server with a different IP-Address or Port as specified in constructor
Parameter ipAddress: IP-Address of Modbus-TCP Server
Parameter port: Port of Modbus-TCP Server listening
boolean[] ReadDiscreteInputs(int startingAddress, int quantity)
Read discrete Inputs from Server (Function Code 2)
boolean[] ReadCoils(int startingAddress, int quantity)
Read coils from Server (Function Code 1)
int[] ReadHoldingRegisters(int startingAddress, int quantity)
Read holding registers from Server (Function Code 3)
int[] ReadInputRegisters(int startingAddress, int quantity)
Read Input registers from Server (Function Code 4)
void WriteSingleCoil(int startingAddress, boolean value)
Write single Coil to Server (Function Code 5)
void WriteSingleRegister(int startingAddress, int value)
Write single Register to Server (Function Code 6)
void WriteMultipleCoils(int startingAddress, boolean[] values)
Write multiple coils to Server (Function Code 15)
void WriteMultipleRegisters(int startingAddress, int[] values)
Write multiple registers to server (Function Code 16)
int[] ReadWriteMultipleRegisters(int startingAddressRead, int quantityRead, int startingAddressWrite, int quantityWrite)
Reads and Writes Multiple Registers (Function Code 23)
void Disconnect()
close connection to Server
static float ConvertRegistersToFloat(int[] registers)
Converts two registers into float value - can be used to read float values from server
First sent Register must be the "Low Register" - Second "High Register"
Parameter int[] registers: Two Registers will be connected for the float value
Example to read float values from server:
EasyModbus.ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(19,2));
static float ConvertRegistersToFloat(int[] registers, RegisterOrder registerOrder)
Converts two registers into float value - can be used to read float values from server
Parameter int[] registers: Two Registers will be connected for the float value
Parameter RegisterOrder registerOrder: The order of High Register and Low Register can determined
Example to read float values from server:
EasyModbus.ModbusClient.ConvertRegistersToFloat(modbusClient.ReadHoldingRegisters(19,2), RegisterOrder.LowHigh);
static Int ConvertRegistersToDouble(int[] registers)
Converts two registers into 32Bit value - can be used to read Dauble values from server
First sent Register must be the "Low Register" - Second "High Register"
Parameter int[] registers: Two Registers will be connected for the double value
Example to read double values from server:
EasyModbus.ModbusClient.ConvertRegistersToDouble(modbusClient.ReadHoldingRegisters(19,2));
static float ConvertRegistersToDouble(int[] registers, RegisterOrder registerOrder)
Converts two registers into 32Bit value - can be used to read double values from server
Parameter int[] registers: Two Registers will be connected for the double value
Parameter RegisterOrder registerOrder: The order of High Register and Low Register can determined
Example to read double values from server:
EasyModbus.ModbusClient.ConvertRegistersToDouble(modbusClient.ReadHoldingRegisters(19,2), RegisterOrder.LowHigh);
static int[] ConvertFloatToTwoRegisters(float floatValue)
Converts float value into two registers - can be used to write float values to server
Example to write float value into server:
modbusClient.WriteMultipleRegisters(24, EasyModbus.ModbusClient.ConvertFloatToTwoRegisters((float)1.22));
static int[] ConvertFloatToTwoRegisters(float floatValue, RegisterOrder registerOrder)
Converts float value into two registers - can be used to write float values to server
Parameter RegisterOrder registerOrder: The order of High Register and Low Register can determined
Example to write float value into server:
modbusClient.WriteMultipleRegisters(24, EasyModbus.ModbusClient.ConvertFloatToTwoRegisters((float)1.22), RegisterOrder.LowHigh);
static int[] ConvertDoubleToTwoRegisters(Int32 doubleValue)
Converts 32Bit value into two registers - can be used to write double values to server
Example to write double value into server:
modbusClient.WriteMultipleRegisters(24, EasyModbus.ModbusClient.ConvertDoubleToTwoRegisters((Int32)122546));
static int[] ConvertDoubleToTwoRegisters(Int32 doubleValue, RegisterOrder registerOrder)
Converts 32Bit value into two registers - can be used to write double values to server
Parameter RegisterOrder registerOrder: The order of High Register and Low Register can determined
Example to write double value into server:
modbusClient.WriteMultipleRegisters(24, EasyModbus.ModbusClient.ConvertDoubleToTwoRegisters((Int32)122546), RegisterOrder.LowHigh);
boolean isConnected()
returns the state of the TCP-connection. TRUE if connected, FALSE if disconnected
String getipAddress()
returns the IP-Address of the Server to connect with
void setipAddress(String ipAddress)
sets the IP-Address of the Server to connect with
int getPort()
returns the Port of the Server listening
void setPort(int port)
sets the Port of the Server listening
boolean getUDPFlag()
returns the UDP Flag, which enables Modbus UDP and disables Modbus TCP
void setUDPFlag(boolean udpFlag)
sets the UDP Flag, which enables Modbus UDP and disables Modbus TCP
int getConnectionTimeout()
returns the connection Timeout time
void setConnectionTimeout(int connectionTimeout)
sets the connection Timeout time
void addReveiveDataChangedListener(ReceiveDataChangedListener toAdd)
Adds a class, which implements the Interface ReceiveDataChangedListener, to notice any change of the Receive data
void addSendDataChangedListener(SendDataChangedListener toAdd)
Adds a class, which implements the Interface SendDataChangedListener, to notice any change of the Send data