类 ModbusMaster
java.lang.Object
com.huangjian.modbus4j.Modbus
com.huangjian.modbus4j.ModbusMaster
- 直接已知子类:
SerialMaster,TcpListener,TcpMaster,UdpMaster
Abstract ModbusMaster class.
-
字段概要
字段修饰符和类型字段说明protected booleanIf connection is established with slave/slavesprotected booleanprotected booleanShould we validate the responses: - ensure that the requested slave id is what is in the response从类继承的字段 com.huangjian.modbus4j.Modbus
DEFAULT_MAX_READ_BIT_COUNT, DEFAULT_MAX_READ_REGISTER_COUNT, DEFAULT_MAX_WRITE_REGISTER_COUNT -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected voidcloseMessageControl.abstract voiddestroy()destroy.intGetter for the fielddiscardDataDelay.getePoll()Getter for the fieldePoll.getIoLog()Getter for the fieldioLog.protected MessageControlgetMessageControl.intGetter for the fieldretries.intGetter for the fieldtimeout.<T> TgetValue(BaseLocator<T> locator) Returns a value from the modbus network according to the given locator information.abstract voidinit()init.booleanisConnected.booleanisInitialized.booleanisMultipleWritesOnly.Node scanning.scanForSlaveNodes.<K> BatchResults<K> Useful for sending a number of polling commands at once, or at least in as optimal a batch as possible.final ModbusResponsesend(ModbusRequest request) send.abstract ModbusResponsesendImpl(ModbusRequest request) sendImpl.voidsetConnected(boolean connected) Setter for the fieldconnected.voidsetDiscardDataDelay(int discardDataDelay) Setter for the fielddiscardDataDelay.voidsetePoll(InputStreamEPollWrapper ePoll) Setter for the fieldePoll.voidSetter for the fieldioLog.voidsetMultipleWritesOnly(boolean multipleWritesOnly) Setter for the fieldmultipleWritesOnly.voidsetRetries(int retries) Setter for the fieldretries.voidsetTimeout(int timeout) Setter for the fieldtimeout.<T> voidsetValue(BaseLocator<T> locator, Object value) Sets the given value in the modbus network according to the given locator information.booleantestSlaveNode(int node) testSlaveNode.
-
字段详细资料
-
validateResponse
protected boolean validateResponseShould we validate the responses: - ensure that the requested slave id is what is in the response -
connected
protected boolean connectedIf connection is established with slave/slaves -
initialized
protected boolean initialized
-
-
构造器详细资料
-
ModbusMaster
public ModbusMaster()
-
-
方法详细资料
-
isConnected
public boolean isConnected()isConnected.
- 返回:
- a boolean.
-
setConnected
public void setConnected(boolean connected) Setter for the field
connected.- 参数:
connected- a boolean.
-
init
init.
- 抛出:
ModbusInitException- if any.
-
isInitialized
public boolean isInitialized()isInitialized.
- 返回:
- a boolean.
-
destroy
public abstract void destroy()destroy.
-
send
send.
- 参数:
request- aModbusRequestobject.- 返回:
- a
ModbusResponseobject. - 抛出:
ModbusTransportException- if any.
-
sendImpl
sendImpl.
- 参数:
request- aModbusRequestobject.- 返回:
- a
ModbusResponseobject. - 抛出:
ModbusTransportException- if any.
-
getValue
public <T> T getValue(BaseLocator<T> locator) throws ModbusTransportException, ErrorResponseException Returns a value from the modbus network according to the given locator information. Various data types are allowed to be requested including multi-word types. The determination of the correct request message to send is handled automatically.- 类型参数:
T- a T object.- 参数:
locator- the information required to locate the value in the modbus network.- 返回:
- an object representing the value found. This will be one of Boolean, Short, Integer, Long, BigInteger, Float, or Double. See the DataType enumeration for details on which type to expect.
- 抛出:
ModbusTransportException- if there was an IO error or other technical failure while sending the messageErrorResponseException- if the response returned from the slave was an exception.
-
setValue
public <T> void setValue(BaseLocator<T> locator, Object value) throws ModbusTransportException, ErrorResponseException Sets the given value in the modbus network according to the given locator information. Various data types are allowed to be set including including multi-word types. The determination of the correct write message to send is handled automatically.- 类型参数:
T- type of locator- 参数:
locator- the information required to locate the value in the modbus network.value- an object representing the value to be set. This will be one of Boolean, Short, Integer, Long, BigInteger, Float, or Double. See the DataType enumeration for details on which type to expect.- 抛出:
ModbusTransportException- if there was an IO error or other technical failure while sending the messageErrorResponseException- if the response returned from the slave was an exception.
-
scanForSlaveNodes
Node scanning. Returns a list of slave nodes that respond to a read exception status request (perhaps with an error, but respond nonetheless). Note: a similar scan could be done for registers in nodes, but, for one thing, it would take some time to run, and in any case the results would not be meaningful since there would be no semantic information accompanying the results.- 返回:
- a
Listobject.
-
scanForSlaveNodes
scanForSlaveNodes.
- 参数:
l- aNodeScanListenerobject.- 返回:
- a
ProgressiveTaskobject.
-
testSlaveNode
public boolean testSlaveNode(int node) testSlaveNode.
- 参数:
node- a int.- 返回:
- a boolean.
-
getRetries
public int getRetries()Getter for the field
retries.- 返回:
- a int.
-
setRetries
public void setRetries(int retries) Setter for the field
retries.- 参数:
retries- a int.
-
getTimeout
public int getTimeout()Getter for the field
timeout.- 返回:
- a int.
-
setTimeout
public void setTimeout(int timeout) Setter for the field
timeout.- 参数:
timeout- a int.
-
isMultipleWritesOnly
public boolean isMultipleWritesOnly()isMultipleWritesOnly.
- 返回:
- a boolean.
-
setMultipleWritesOnly
public void setMultipleWritesOnly(boolean multipleWritesOnly) Setter for the field
multipleWritesOnly.- 参数:
multipleWritesOnly- a boolean.
-
getDiscardDataDelay
public int getDiscardDataDelay()Getter for the field
discardDataDelay.- 返回:
- a int.
-
setDiscardDataDelay
public void setDiscardDataDelay(int discardDataDelay) Setter for the field
discardDataDelay.- 参数:
discardDataDelay- a int.
-
getIoLog
Getter for the field
ioLog.- 返回:
- a
BaseIOLogobject.
-
setIoLog
Setter for the field
ioLog.- 参数:
ioLog- aBaseIOLogobject.
-
getePoll
Getter for the field
ePoll.- 返回:
- a
InputStreamEPollWrapperobject.
-
setePoll
Setter for the field
ePoll.- 参数:
ePoll- aInputStreamEPollWrapperobject.
-
send
public <K> BatchResults<K> send(BatchRead<K> batch) throws ModbusTransportException, ErrorResponseException Useful for sending a number of polling commands at once, or at least in as optimal a batch as possible.- 类型参数:
K- type of result- 参数:
batch- aBatchReadobject.- 返回:
- a
BatchResultsobject. - 抛出:
ModbusTransportException- if any.ErrorResponseException- if any.
-
getMessageControl
getMessageControl.
- 返回:
- a
MessageControlobject.
-
closeMessageControl
closeMessageControl.
- 参数:
conn- aMessageControlobject.
-