public class ModbusTCPMaster extends Object
| Constructor and Description |
|---|
ModbusTCPMaster(String addr)
Constructs a new master facade instance for communication
with a given slave.
|
ModbusTCPMaster(String addr,
int port)
Constructs a new master facade instance for communication
with a given slave.
|
| Modifier and Type | Method and Description |
|---|---|
void |
connect()
Connects this ModbusTCPMaster with the slave.
|
void |
disconnect()
Disconnects this ModbusTCPMaster from the slave.
|
boolean |
isReconnecting()
Tests if a constant connection is maintained or if a new
connection is established for every transaction.
|
BitVector |
readCoils(int ref,
int count)
Reads a given number of coil states from the slave.
|
BitVector |
readInputDiscretes(int ref,
int count)
Reads a given number of input discrete states from the slave.
|
InputRegister[] |
readInputRegisters(int ref,
int count)
Reads a given number of input registers from the slave.
|
Register[] |
readMultipleRegisters(int ref,
int count)
Reads a given number of registers from the slave.
|
void |
setReconnecting(boolean b)
Sets the flag that specifies whether to maintain a
constant connection or reconnect for every transaction.
|
boolean |
writeCoil(int unitid,
int ref,
boolean state)
Writes a coil state to the slave.
|
void |
writeMultipleCoils(int ref,
BitVector coils)
Writes a given number of coil states to the slave.
|
void |
writeMultipleRegisters(int ref,
Register[] registers)
Writes a number of registers to the slave.
|
void |
writeSingleRegister(int ref,
Register register)
Writes a single register to the slave.
|
public ModbusTCPMaster(String addr)
addr - an internet address as resolvable IP name or IP number, specifying the slave to communicate with.public ModbusTCPMaster(String addr, int port)
addr - an internet address as resolvable IP name or IP number, specifying the slave to communicate with.port - the port the slave is listening to.public void connect()
throws Exception
Exception - if the connection cannot be established.public void disconnect()
public void setReconnecting(boolean b)
b - true if a new connection should be established for each transaction, false otherwise.public boolean isReconnecting()
public BitVector readCoils(int ref, int count) throws ModbusException
Note that the number of bits in the bit vector will be forced to the number originally requested.
ref - the offset of the coil to start reading from.count - the number of coil states to be read.ModbusException - if an I/O error, a slave exception or a transaction error occurs.public boolean writeCoil(int unitid,
int ref,
boolean state)
throws ModbusException
unitid - the slave unit id.ref - the offset of the coil to be written.state - the coil state to be written.ModbusException - if an I/O error, a slave exception or a transaction error occurs.public void writeMultipleCoils(int ref,
BitVector coils)
throws ModbusException
Note that the number of coils to be written is given
implicitly, through BitVector.size().
ref - the offset of the coil to start writing to.coils - a BitVector which holds the coil states to be written.ModbusException - if an I/O error, a slave exception or a transaction error occurs.public BitVector readInputDiscretes(int ref, int count) throws ModbusException
Note that the number of bits in the bit vector will be forced to the number originally requested.
ref - the offset of the input discrete to start reading from.count - the number of input discrete states to be read.ModbusException - if an I/O error, a slave exception or a transaction error occurs.public InputRegister[] readInputRegisters(int ref, int count) throws ModbusException
Note that the number of input registers returned (i.e. array length) will be according to the number received in the slave response.
ref - the offset of the input register to start reading from.count - the number of input registers to be read.ModbusException - if an I/O error, a slave exception or a transaction error occurs.public Register[] readMultipleRegisters(int ref, int count) throws ModbusException
Note that the number of registers returned (i.e. array length) will be according to the number received in the slave response.
ref - the offset of the register to start reading from.count - the number of registers to be read.ModbusException - if an I/O error, a slave exception or a transaction error occurs.public void writeSingleRegister(int ref,
Register register)
throws ModbusException
ref - the offset of the register to be written.register - a Register holding the value of the register to be written.ModbusException - if an I/O error, a slave exception or a transaction error occurs.public void writeMultipleRegisters(int ref,
Register[] registers)
throws ModbusException
ref - the offset of the register to start writing to.registers - a Register[] holding the values of the registers to be written.ModbusException - if an I/O error, a slave exception or a transaction error occurs.Copyright © 2017. All rights reserved.