Class StaticDataMapReadonlyModbusConnection
- All Implemented Interfaces:
Closeable,AutoCloseable,ModbusConnection
- Direct Known Subclasses:
StaticDataMapModbusConnection
ModbusConnection for reading static data.
This class can be useful in tests working with Modbus connections.
- Since:
- 2.16
- Version:
- 2.0
- Author:
- matt
-
Constructor Summary
ConstructorsConstructorDescriptionStaticDataMapReadonlyModbusConnection(int[] data) Constructor.StaticDataMapReadonlyModbusConnection(int[] data, int address) Constructor.StaticDataMapReadonlyModbusConnection(short[] data, int address) Constructor.StaticDataMapReadonlyModbusConnection(net.solarnetwork.util.IntShortMap data) Construct with the data. -
Method Summary
Modifier and TypeMethodDescriptionprotected net.solarnetwork.util.IntShortMapgetData()Get the data map.byte[]readBytes(ModbusReadFunction function, int address, int count) Get the raw bytes of specific registers.readDiscreetValues(int[] addresses, int count) Get the values of a set of "coil" type registers, as a BitSet.readDiscreetValues(int address, int count) Get the values of a set of "coil" type registers, as a BitSet.readInputDiscreteValues(int address, int count) Get the values of a set of "input discrete" type registers, as a BitSet.readString(ModbusReadFunction function, int address, int count, boolean trim, Charset charset) Read a set of registers as bytes and interpret as a string.short[]readWords(ModbusReadFunction function, int address, int count) Get the values of specific 16-bit Modbus registers as an array of 16-bit words.int[]readWordsUnsigned(ModbusReadFunction function, int address, int count) Get the values of specific 16-bit Modbus registers as an array of unsigned 16-bit words.Methods inherited from class net.solarnetwork.node.io.modbus.support.ModbusConnectionSupport
close, open, writeBytes, writeDiscreetValues, writeString, writeWords, writeWordsMethods inherited from class net.solarnetwork.node.io.modbus.support.AbstractModbusConnection
getRetries, getRetryDelayMs, getUnitId, isHeadless, isRetryReconnect, setRetries, setRetryDelayMs, setRetryReconnectMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.solarnetwork.node.io.modbus.ModbusConnection
getUnitId, readDiscreteValues, readDiscreteValues, writeDiscreteValues
-
Constructor Details
-
StaticDataMapReadonlyModbusConnection
public StaticDataMapReadonlyModbusConnection(net.solarnetwork.util.IntShortMap data) Construct with the data.- Parameters:
data- the starting data
-
StaticDataMapReadonlyModbusConnection
public StaticDataMapReadonlyModbusConnection(int[] data) Constructor.- Parameters:
data- the starting data, starting from Modbus register address 0
-
StaticDataMapReadonlyModbusConnection
public StaticDataMapReadonlyModbusConnection(int[] data, int address) Constructor.- Parameters:
data- the starting dataaddress- the starting Modbus register address fordata
-
StaticDataMapReadonlyModbusConnection
public StaticDataMapReadonlyModbusConnection(short[] data, int address) Constructor.- Parameters:
data- the starting dataaddress- the starting Modbus register address fordata
-
-
Method Details
-
getData
protected net.solarnetwork.util.IntShortMap getData()Get the data map.- Returns:
- the data
-
readWordsUnsigned
Description copied from interface:ModbusConnectionGet the values of specific 16-bit Modbus registers as an array of unsigned 16-bit words.Note that the raw int values can be treated as signed shorts by casting them to shorts, like
short signed = (short)s. Thus the values returned by this method are technically the same as those returned byModbusConnection.readWords(ModbusReadFunction, int, int), having been cast to ints.- Specified by:
readWordsUnsignedin interfaceModbusConnection- Overrides:
readWordsUnsignedin classModbusConnectionSupport- Parameters:
function- the Modbus function code to useaddress- the 0-based Modbus register address to start reading fromcount- the number of 16-bit Modbus registers to read- Returns:
- array of register values; the result will have a length equal to
count
-
readString
public String readString(ModbusReadFunction function, int address, int count, boolean trim, Charset charset) Description copied from interface:ModbusConnectionRead a set of registers as bytes and interpret as a string.- Specified by:
readStringin interfaceModbusConnection- Overrides:
readStringin classModbusConnectionSupport- Parameters:
function- the Modbus function code to useaddress- the 0-based Modbus register address to start reading fromcount- the number of Modbus 16-bit registers to readtrim- if true then remove leading/trailing whitespace from the resulting stringcharset- the character set to interpret the bytes as- Returns:
- String from interpreting raw bytes as a string
- See Also:
-
readWords
Description copied from interface:ModbusConnectionGet the values of specific 16-bit Modbus registers as an array of 16-bit words.Note that the raw short values can be treated as unsigned shorts by converting them to integers, like
int unsigned = ((int)s) && 0xFFFF, or by callingShort.toUnsignedInt(short). Thus the values returned by this method are technically the same as those returned byModbusConnection.readWordsUnsigned(ModbusReadFunction, int, int), without having been cast to ints.- Specified by:
readWordsin interfaceModbusConnection- Overrides:
readWordsin classModbusConnectionSupport- Parameters:
function- the Modbus function code to useaddress- the 0-based Modbus register address to start reading fromcount- the number of Modbus 16-bit registers to read- Returns:
- array of register values; the result will have a length equal to
count
-
readInputDiscreteValues
Description copied from interface:ModbusConnectionGet the values of a set of "input discrete" type registers, as a BitSet.This uses a Modbus function code 2 request. The returned bitset will have
countvalues set, from 0 tocount - 1.- Specified by:
readInputDiscreteValuesin interfaceModbusConnection- Overrides:
readInputDiscreteValuesin classModbusConnectionSupport- Parameters:
address- the Modbus register addresses to start reading fromcount- the count of registers to read- Returns:
- BitSet, with each 0 to
countindexes
-
readDiscreetValues
Description copied from interface:ModbusConnectionGet the values of a set of "coil" type registers, as a BitSet.This uses a Modbus function code 1 request.
This method is required but deprecated to preserve backwards compatibility.
- Specified by:
readDiscreetValuesin interfaceModbusConnection- Overrides:
readDiscreetValuesin classModbusConnectionSupport- Parameters:
address- the 0-based Modbus register address to readcount- the count of discreet registers to read- Returns:
- BitSet, with indexes set from 0 to a
count - 1
-
readDiscreetValues
Description copied from interface:ModbusConnectionGet the values of a set of "coil" type registers, as a BitSet.This uses a Modbus function code 1 request. The returned set will have a size equal to
addresses.length * count.This method is required but deprecated to preserve backwards compatibility.
- Specified by:
readDiscreetValuesin interfaceModbusConnection- Overrides:
readDiscreetValuesin classModbusConnectionSupport- Parameters:
addresses- the 0-based Modbus register addresses to readcount- the count of coils to read with each address- Returns:
- BitSet, with each
countindexes for each index in theaddressesparameter
-
readBytes
Description copied from interface:ModbusConnectionGet the raw bytes of specific registers.Each 16-bit modbus register value will be decomposed into two output bytes, so that the returned result will have a length equal to
count * 2.- Specified by:
readBytesin interfaceModbusConnection- Overrides:
readBytesin classModbusConnectionSupport- Parameters:
function- the Modbus function code to useaddress- the 0-based Modbus register address to start reading fromcount- the number of Modbus 16-bit registers to read- Returns:
- register words as an array of bytes
-