public abstract class AbstractModbusMaster extends Object
| Constructor and Description |
|---|
AbstractModbusMaster() |
| Modifier and Type | Method and Description |
|---|---|
abstract void |
connect()
Connects this ModbusTCPMaster with the slave.
|
abstract void |
disconnect()
Disconnects this ModbusTCPMaster from the slave.
|
int |
getTimeout()
Returns the receive timeout in milliseconds
|
abstract AbstractModbusTransport |
getTransport()
Returns the transport being used by the
|
abstract boolean |
isConnected()
Returns true if the master is connected
|
boolean |
maskWriteRegister(int ref,
int andMask,
int orMask)
Mask write a single register to the slave.
|
boolean |
maskWriteRegister(int unitId,
int ref,
int andMask,
int orMask)
Mask write a single register to the slave.
|
BitVector |
readCoils(int ref,
int count)
Reads a given number of coil states from the slave.
|
BitVector |
readCoils(int unitId,
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.
|
BitVector |
readInputDiscretes(int unitId,
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.
|
InputRegister[] |
readInputRegisters(int unitId,
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.
|
Register[] |
readMultipleRegisters(int unitId,
int ref,
int count)
Reads a given number of registers from the slave.
|
void |
setCheckingValidity(boolean b)
Sets the flag that controls whether the
validity of a transaction will be checked.
|
void |
setRetries(int retries)
Set the amount of retries for opening
the connection for executing the transaction.
|
void |
setTimeout(int timeout)
Sets the receive timeout
|
boolean |
writeCoil(int ref,
boolean state)
Writes a coil state to the slave.
|
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 |
writeMultipleCoils(int unitId,
int ref,
BitVector coils)
Writes a given number of coil states to the slave.
|
int |
writeMultipleRegisters(int unitId,
int ref,
Register[] registers)
Writes a number of registers to the slave.
|
int |
writeMultipleRegisters(int ref,
Register[] registers)
Writes a number of registers to the slave.
|
int |
writeSingleRegister(int unitId,
int ref,
Register register)
Writes a single register to the slave.
|
int |
writeSingleRegister(int ref,
Register register)
Writes a single register to the slave.
|
public abstract void connect()
throws Exception
Exception - if the connection cannot be established.public abstract void disconnect()
public BitVector readCoils(int unitId, int ref, int count) throws ModbusException
unitId - the slave unit id.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 unitId,
int ref,
BitVector coils)
throws ModbusException
BitVector.size().unitId - the slave unit id.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 unitId, int ref, int count) throws ModbusException
unitId - the slave unit id.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 unitId, int ref, int count) throws ModbusException
unitId - the slave unit id.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 unitId, int ref, int count) throws ModbusException
unitId - the slave unit id.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 int writeSingleRegister(int unitId,
int ref,
Register register)
throws ModbusException
unitId - the slave unit id.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 int writeMultipleRegisters(int unitId,
int ref,
Register[] registers)
throws ModbusException
unitId - the slave unit id.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.public boolean maskWriteRegister(int unitId,
int ref,
int andMask,
int orMask)
throws ModbusException
unitId - the slave unit id.ref - the offset of the register to start writing to.andMask - AND mask.orMask - OR mask.ModbusException - if an I/O error, a slave exception or
a transaction error occurs.public BitVector readCoils(int ref, int count) throws ModbusException
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 ref,
boolean state)
throws ModbusException
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
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
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
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
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 int 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 int 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.public boolean maskWriteRegister(int ref,
int andMask,
int orMask)
throws ModbusException
ref - the offset of the register to start writing to.andMask - AND mask.orMask - OR mask.ModbusException - if an I/O error, a slave exception or
a transaction error occurs.public int getTimeout()
public void setTimeout(int timeout)
timeout - Timeout in millisecondspublic void setRetries(int retries)
retries - the amount of retries as int.public void setCheckingValidity(boolean b)
b - true if checking validity, false otherwise.public abstract AbstractModbusTransport getTransport()
public abstract boolean isConnected()
Copyright © 2025. All Rights Reserved.