public abstract class ModbusMaster extends Object implements FrameEventListenerList
| Constructor and Description |
|---|
ModbusMaster(ModbusConnection conn) |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(FrameEventListener listener) |
void |
connect() |
protected void |
connectImpl()
this method allows you to implement your own behavior of connect method.
|
int |
countListeners() |
abstract void |
diagnosticsChangeAsciiInputDelimiter(int serverAddress,
int delimiter)
The character passed in the request data field becomes the end of message delimiter
for future messages (replacing the default LF character).
|
abstract void |
diagnosticsClearCountersAndDiagnosticRegister(int serverAddress)
The goal is to clear all counters and the diagnostic register.
|
abstract void |
diagnosticsClearOverrunCounterAndFlag(int serverAddress)
Clears the overrun error counter and reset the error flag.
|
abstract void |
diagnosticsForceListenOnlyMode(int serverAddress)
Forces the addressed remote device to its Listen Only Mode for MODBUS communications.
|
abstract void |
diagnosticsRestartCommunicationsOption(int serverAddress,
boolean clearLog)
The remote device serial line port must be initialized and restarted, and all of its
communications event counters are cleared.
|
abstract int |
diagnosticsReturnBusCharacterOverrunCount(int serverAddress)
The response data field returns the quantity of messages addressed to the remote device that
it could not handle due to a character overrun condition, since its last restart, clear counters
operation, or power–up.
|
abstract int |
diagnosticsReturnBusCommunicationErrorCount(int serverAddress)
The response data field returns the quantity of CRC errors encountered by the remote device
since its last restart, clear counters operation, or power–up.
|
abstract int |
diagnosticsReturnBusExceptionErrorCount(int serverAddress)
The response data field returns the quantity of MODBUS exception responses returned by the
remote device since its last restart, clear counters operation, or power–up.
|
abstract int |
diagnosticsReturnBusMessageCount(int serverAddress)
The response data field returns the quantity of messages that the remote device has detected
on the communications system since its last restart, clear counters operation, or power–up.
|
abstract int |
diagnosticsReturnDiagnosticRegister(int serverAddress)
Returns the contents of the remote device’s 16–bit diagnostic register are returned in the response.
|
abstract void |
diagnosticsReturnQueryData(int serverAddress,
int queryData)
The data passed in the request data field is to be returned (looped back) in the response.
|
abstract int |
diagnosticsReturnSlaveBusyCount(int serverAddress)
The response data field returns the quantity of messages addressed to the remote device for
which it returned a Slave Device Busy exception response, since its last restart, clear
counters operation, or power–up.
|
abstract int |
diagnosticsReturnSlaveMessageCount(int serverAddress)
The response data field returns the quantity of messages addressed to the remote device, or
broadcast, that the remote device has processed since its last restart, clear counters
operation, or power–up.
|
abstract int |
diagnosticsReturnSlaveNAKCount(int serverAddress)
The response data field returns the quantity of messages addressed to the remote device for
which it returned a Negative Acknowledge (NAK) exception response, since its last restart,
clear counters operation, or power–up.
|
abstract int |
diagnosticsReturnSlaveNoResponseCount(int serverAddress)
The response data field returns the quantity of messages addressed to the remote device for
which it has returned no response (neither a normal response nor an exception response),
since its last restart, clear counters operation, or power–up.
|
void |
disconnect() |
protected void |
disconnectImpl()
this method allows you to implement your own behavior of disconnect method.
|
void |
fireFrameReceivedEvent(FrameEvent event) |
void |
fireFrameSentEvent(FrameEvent event) |
abstract CommStatus |
getCommEventCounter(int serverAddress)
This function code is used to get a status word and an event count from the remote device's
communication event counter.
|
abstract CommStatus |
getCommEventLog(int serverAddress)
This function code is used to get a status word, event count, message count, and a field of
event bytes from the remote device.
|
protected ModbusConnection |
getConnection() |
int |
getTransactionId() |
boolean |
isConnected() |
void |
maskWriteRegister(int serverAddress,
int startAddress,
int and,
int or)
This function code is used to modify the contents of a specified holding register using a
combination of an AND mask, an OR mask, and the register's current contents.
|
ModbusResponse |
processRequest(ModbusRequest request)
this function allows you to process your own ModbusRequest.
|
boolean[] |
readCoils(int serverAddress,
int startAddress,
int quantity)
This function code is used to read from 1 to 2000 contiguous status of coils in a remote
device.
|
MEIReadDeviceIdentification |
readDeviceIdentification(int serverAddress,
int objectId,
ReadDeviceIdentificationCode readDeviceId)
This function code allows reading the identification and additional information relative to the
physical and functional description of a remote device, only.
|
boolean[] |
readDiscreteInputs(int serverAddress,
int startAddress,
int quantity)
This function code is used to read from 1 to 2000 contiguous status of discrete inputs in a
remote device.
|
abstract int |
readExceptionStatus(int serverAddress)
This function code is used to read the contents of eight Exception Status outputs in a remote
device.
|
int[] |
readFifoQueue(int serverAddress,
int fifoPointerAddress)
This function code allows to read the contents of a First-In-First-Out (FIFO) queue of register
in a remote device.
|
ModbusFileRecord[] |
readFileRecord(int serverAddress,
ModbusFileRecord[] records)
This function code is used to perform a file record read.
|
int[] |
readHoldingRegisters(int serverAddress,
int startAddress,
int quantity)
This function code is used to read the contents of a contiguous block of holding registers in a
remote device.
|
int[] |
readInputRegisters(int serverAddress,
int startAddress,
int quantity)
This function code is used to read from 1 to 125 contiguous input registers in a remote
device.
|
protected ModbusMessage |
readResponse(ModbusRequest request) |
int[] |
readWriteMultipleRegisters(int serverAddress,
int readAddress,
int readQuantity,
int writeAddress,
int[] registers)
This function code performs a combination of one read operation and one write operation in a
single MODBUS transaction.
|
void |
removeListener(FrameEventListener listener) |
void |
removeListeners() |
abstract byte[] |
reportSlaveId(int serverAddress)
This function code is used to read the description of the type, the current status, and other
information specific to a remote device.
|
protected void |
sendRequest(ModbusMessage msg) |
void |
setResponseTimeout(int timeout)
ModbusMaster will block for only this amount of time.
|
void |
setTransactionId(int transactionId) |
void |
writeFileRecord(int serverAddress,
ModbusFileRecord record)
This function code is used to perform a file record write.
|
void |
writeMultipleCoils(int serverAddress,
int startAddress,
boolean[] coils)
This function code is used to force each coil in a sequence of coils to either ON or OFF in a
remote device.
|
void |
writeMultipleRegisters(int serverAddress,
int startAddress,
int[] registers)
This function code is used to write a block of contiguous registers (1 to 123 registers) in a
remote device.
|
void |
writeSingleCoil(int serverAddress,
int startAddress,
boolean flag)
This function code is used to write a single output to either ON or OFF in a remote device.
|
void |
writeSingleRegister(int serverAddress,
int startAddress,
int register)
This function code is used to write a single holding register in a remote device.
|
public ModbusMaster(ModbusConnection conn)
public int getTransactionId()
public void setTransactionId(int transactionId)
protected ModbusConnection getConnection()
protected void connectImpl()
throws ModbusIOException
ModbusIOExceptionprotected void disconnectImpl()
throws ModbusIOException
ModbusIOExceptionpublic final void connect()
throws ModbusIOException
ModbusIOExceptionpublic final void disconnect()
throws ModbusIOException
ModbusIOExceptionpublic boolean isConnected()
protected void sendRequest(ModbusMessage msg) throws ModbusIOException
ModbusIOExceptionprotected ModbusMessage readResponse(ModbusRequest request) throws ModbusProtocolException, ModbusNumberException, ModbusIOException
public ModbusResponse processRequest(ModbusRequest request) throws ModbusProtocolException, ModbusIOException
request - an instance of ModbusRequest.ModbusProtocolExceptionModbusIOExceptionModbusRequestFactory,
ModbusRequest,
ModbusResponse,
com.intelligt.modbus.jlibmodbus.msg.request,
com.intelligt.modbus.jlibmodbus.msg.requestpublic void setResponseTimeout(int timeout)
timeout - the specified timeout, in milliseconds.public final int[] readHoldingRegisters(int serverAddress,
int startAddress,
int quantity)
throws ModbusProtocolException,
ModbusNumberException,
ModbusIOException
serverAddress - a slave addressstartAddress - starting register addressquantity - the number of registersModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic final int[] readInputRegisters(int serverAddress,
int startAddress,
int quantity)
throws ModbusProtocolException,
ModbusNumberException,
ModbusIOException
serverAddress - a slave addressstartAddress - starting register addressquantity - the number of registersModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic final boolean[] readCoils(int serverAddress,
int startAddress,
int quantity)
throws ModbusProtocolException,
ModbusNumberException,
ModbusIOException
serverAddress - a slave addressstartAddress - the address of the first coilquantity - the number of coilsModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic final boolean[] readDiscreteInputs(int serverAddress,
int startAddress,
int quantity)
throws ModbusProtocolException,
ModbusNumberException,
ModbusIOException
serverAddress - a slave addressstartAddress - the address of the first inputquantity - the number of inputsModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic final void writeSingleCoil(int serverAddress,
int startAddress,
boolean flag)
throws ModbusProtocolException,
ModbusNumberException,
ModbusIOException
serverAddress - a slave addressstartAddress - the address of the coil to be forcedflag - the request data fieldModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic final void writeSingleRegister(int serverAddress,
int startAddress,
int register)
throws ModbusProtocolException,
ModbusNumberException,
ModbusIOException
serverAddress - a slave addressstartAddress - the address of the register to be writtenregister - valueModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic final void writeMultipleCoils(int serverAddress,
int startAddress,
boolean[] coils)
throws ModbusProtocolException,
ModbusNumberException,
ModbusIOException
serverAddress - a slave addressstartAddress - the address of the coils to be writtencoils - the coilsModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic final void writeMultipleRegisters(int serverAddress,
int startAddress,
int[] registers)
throws ModbusProtocolException,
ModbusNumberException,
ModbusIOException
serverAddress - a slave addressstartAddress - the address of the registers to be writtenregisters - the register dataModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic final int[] readWriteMultipleRegisters(int serverAddress,
int readAddress,
int readQuantity,
int writeAddress,
int[] registers)
throws ModbusProtocolException,
ModbusNumberException,
ModbusIOException
serverAddress - a slave addressreadAddress - the address of the registers to be readreadQuantity - the number of registers to be readwriteAddress - the address of the registers to be writtenregisters - the number of registers to be writtenModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic final int[] readFifoQueue(int serverAddress,
int fifoPointerAddress)
throws ModbusProtocolException,
ModbusNumberException,
ModbusIOException
serverAddress - a slave addressfifoPointerAddress - address of a fifo pointer registerModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic final ModbusFileRecord[] readFileRecord(int serverAddress, ModbusFileRecord[] records) throws ModbusProtocolException, ModbusNumberException, ModbusIOException
serverAddress - a slave addressrecords - array of ModbusFileRecordModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic final void writeFileRecord(int serverAddress,
ModbusFileRecord record)
throws ModbusProtocolException,
ModbusNumberException,
ModbusIOException
serverAddress - a server addressrecord - the ModbusFileRecord to be writtenModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic final void maskWriteRegister(int serverAddress,
int startAddress,
int and,
int or)
throws ModbusProtocolException,
ModbusNumberException,
ModbusIOException
(NOT And_Mask)= 0D 0000 1101
Result = 17 0001 0111
Note: y If the Or_Mask value is zero, the result is simply the logical ANDing of the current contents and And_Mask. If the And_Mask value is zero, the result is equal to the Or_Mask value. y The contents of the register can be read with the Read Holding Registers function (function code 03). They could, however, be changed subsequently as the controller scans its user logic program.
serverAddress - slave idstartAddress - reference addressand - the AND maskor - the OR maskModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic abstract int readExceptionStatus(int serverAddress)
throws ModbusProtocolException,
ModbusNumberException,
ModbusIOException
serverAddress - a slave addressModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic abstract byte[] reportSlaveId(int serverAddress)
throws ModbusProtocolException,
ModbusNumberException,
ModbusIOException
serverAddress - slave addressModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailablepublic abstract CommStatus getCommEventCounter(int serverAddress) throws ModbusProtocolException, ModbusNumberException, ModbusIOException
serverAddress - a slave addressModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailableCommStatuspublic abstract CommStatus getCommEventLog(int serverAddress) throws ModbusProtocolException, ModbusNumberException, ModbusIOException
serverAddress - a slave addressModbusProtocolException - if modbus-exception is receivedModbusNumberException - if response is invalidModbusIOException - if remote slave is unavailableCommStatuspublic abstract void diagnosticsReturnQueryData(int serverAddress,
int queryData)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressqueryData - request data fieldModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic abstract void diagnosticsRestartCommunicationsOption(int serverAddress,
boolean clearLog)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressclearLog - causes the port’s Communications Event Log to be clearedModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic abstract int diagnosticsReturnDiagnosticRegister(int serverAddress)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic abstract void diagnosticsChangeAsciiInputDelimiter(int serverAddress,
int delimiter)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressdelimiter - request data fieldModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic abstract void diagnosticsForceListenOnlyMode(int serverAddress)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic abstract void diagnosticsClearCountersAndDiagnosticRegister(int serverAddress)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic abstract int diagnosticsReturnBusMessageCount(int serverAddress)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic abstract int diagnosticsReturnBusCommunicationErrorCount(int serverAddress)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic abstract int diagnosticsReturnBusExceptionErrorCount(int serverAddress)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic abstract int diagnosticsReturnSlaveMessageCount(int serverAddress)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic abstract int diagnosticsReturnSlaveNoResponseCount(int serverAddress)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic abstract int diagnosticsReturnSlaveNAKCount(int serverAddress)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic abstract int diagnosticsReturnSlaveBusyCount(int serverAddress)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic abstract int diagnosticsReturnBusCharacterOverrunCount(int serverAddress)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic abstract void diagnosticsClearOverrunCounterAndFlag(int serverAddress)
throws ModbusNumberException,
ModbusProtocolException,
ModbusIOException
serverAddress - a slave addressModbusNumberException - if server address is in-validModbusProtocolExceptionModbusIOExceptionpublic final MEIReadDeviceIdentification readDeviceIdentification(int serverAddress, int objectId, ReadDeviceIdentificationCode readDeviceId) throws ModbusProtocolException, ModbusNumberException, ModbusIOException
public void addListener(FrameEventListener listener)
addListener in interface FrameEventListenerListpublic void removeListener(FrameEventListener listener)
removeListener in interface FrameEventListenerListpublic void removeListeners()
removeListeners in interface FrameEventListenerListpublic void fireFrameReceivedEvent(FrameEvent event)
fireFrameReceivedEvent in interface FrameEventListenerListpublic void fireFrameSentEvent(FrameEvent event)
fireFrameSentEvent in interface FrameEventListenerListpublic int countListeners()
countListeners in interface FrameEventListenerListCopyright © 2018. All rights reserved.