Package net.solarnetwork.node.io.modbus
Class ModbusRegisterData
java.lang.Object
net.solarnetwork.node.io.modbus.ModbusRegisterData
Data for a Modbus register set.
- Since:
- 4.2
- Version:
- 1.0
- Author:
- matt
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAPI for performing updates to a bit register block. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.ModbusRegisterData(BitSet coils, BitSet discretes, ModbusData holdings, ModbusData inputs) Constructor.Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptioncopy()Create a copy of this object.final voidexpire(ModbusRegisterBlockType blockType) Force a data timestamp to be expired.getCoils()Get the coil register data.getDataTimestamp(ModbusRegisterBlockType blockType) Get the data timestamp (last update time) for a given data block.Get the discrete register data.Get the holding register data.Get the input register data.Get the word order.booleanTest if there is holding or input register data.booleanisEmpty()Test if the registers are all empty.final booleanisOlderThan(ModbusRegisterBlockType blockType, long date) Test if a block of data was updated before a specific date.final voidperformBitUpdates(ModbusRegisterBlockType blockType, ModbusRegisterData.ModbusBitsUpdateAction action) Perform a set of updates to saved register data.final ModbusDataperformRegisterUpdates(ModbusRegisterBlockType blockType, ModbusData.ModbusDataUpdateAction action) Perform a set of updates to saved register data.<T> TreadBits(ModbusRegisterBlockType blockType, Function<BitSet, T> action) Perform a thread-safe read action on a register block.readCoils(int address, int count) Read a set of coil values.readDiscretes(int address, int count) Read a set of discrete values.byte[]readHoldings(int address, int count) Read holding register data into a byte array.byte[]readInputs(int address, int count) Read holding register data into a byte array.<T> TreadRegisters(ModbusRegisterBlockType blockType, Function<ModbusData, T> action) Perform a thread-safe read action on a register block.voidsetWordOrder(ModbusWordOrder order) Set the word order.toString()voidwriteBit(ModbusRegisterBlockType blockType, int address, boolean value) Write a bit to a coil or discrete block type.voidwriteBits(ModbusRegisterBlockType blockType, int address, int count, BitSet set) Write a set of bits to a coil or discrete block type.voidwriteCoil(int address, boolean value) Write a single coil register value.voidwriteCoils(int address, int count, BitSet set) Write a set of coil register values.voidwriteDiscrete(int address, boolean value) Write a single discrete register value.voidwriteDiscretes(int address, int count, BitSet set) Write a set of discrete register values.voidwriteHolding(int address, short value) Write a holding register value.voidwriteHoldings(int address, short[] values) Write holding register values.voidwriteInput(int address, short value) Write an input register value.voidwriteInputs(int address, short[] values) Write input register values.voidwriteRegisters(ModbusRegisterBlockType blockType, int address, short[] dataValue) Write to a set of registers.voidwriteValue(ModbusRegisterBlockType blockType, ModbusDataType dataType, int address, int count, Object value) Write a non-bit register value.
-
Constructor Details
-
ModbusRegisterData
public ModbusRegisterData()Constructor. -
ModbusRegisterData
Constructor.If any argument is null a new instance will be created and used for that value.
- Parameters:
coils- the coil register datadiscretes- the discrete register dataholdings- the holding register datainputs- the input register data
-
ModbusRegisterData
Copy constructor.This method provides a thread-safe way to get a copy of the current data.
- Parameters:
other- the object to copy
-
-
Method Details
-
toString
-
copy
Create a copy of this object.This method provides a thread-safe way to get a copy of the current data.
- Returns:
- the new instance
- See Also:
-
isEmpty
public boolean isEmpty()Test if the registers are all empty.- Returns:
- true if no registers or bits have been set
-
hasRegisterData
public boolean hasRegisterData()Test if there is holding or input register data.- Returns:
- true if either holding or input registers have been set
-
getDataTimestamp
Get the data timestamp (last update time) for a given data block.- Parameters:
blockType- the block type- Returns:
- the update timestamp, or null if never updated
-
expire
Force a data timestamp to be expired.Calling this method will reset the data timestamp to zero, effectively expiring the data.
- Parameters:
blockType- the type of register block to expire
-
isOlderThan
Test if a block of data was updated before a specific date.- Parameters:
blockType- the type of register block to compare the data timestamp againstdate- the date to compare- Returns:
- true if the block's data timestamp is older than
date
-
getWordOrder
Get the word order.- Returns:
- the word order
-
setWordOrder
Set the word order.- Parameters:
order- the word order
-
writeBit
Write a bit to a coil or discrete block type.- Parameters:
blockType- the block type, must be either Coil or Discreteaddress- the address to write tovalue- the bit value- Throws:
IllegalArgumentException- ifblockTypeis not valid
-
writeBits
Write a set of bits to a coil or discrete block type.- Parameters:
blockType- the block type, must be either Coil or Discreteaddress- the address to write tocount- the number of bits to updateset- the bit values- Throws:
IllegalArgumentException- ifblockTypeis not valid
-
writeValue
public void writeValue(ModbusRegisterBlockType blockType, ModbusDataType dataType, int address, int count, Object value) Write a non-bit register value.- Parameters:
blockType- the block type, must be either Holding or InputdataType- the desired data type to writeaddress- the address to write tocount- the number of registers to write to, for variable-length data typesvalue- the value to write- Throws:
IllegalArgumentException- ifblockTypeis not valid
-
writeRegisters
Write to a set of registers.- Parameters:
blockType- the block type to updateaddress- the starting register address to write todataValue- the register values to write
-
readCoils
Read a set of coil values.The returned set starts at index
0, meaning the indexes are shifted down byaddresspositions.- Parameters:
address- the starting register addresscount- the number of registers to read- Returns:
- the result set
-
writeCoil
public void writeCoil(int address, boolean value) Write a single coil register value.- Parameters:
address- the register addressvalue- the value
-
writeCoils
Write a set of coil register values.- Parameters:
address- the register address to start atcount- the count of registers to readset- the set of coil values to write, starting from index 0
-
writeDiscrete
public void writeDiscrete(int address, boolean value) Write a single discrete register value.- Parameters:
address- the register addressvalue- the value
-
writeDiscretes
Write a set of discrete register values.- Parameters:
address- the register address to start atcount- the count of registers to readset- the set of coil values to write, starting from index 0
-
readDiscretes
Read a set of discrete values.The returned set starts at index
0, meaning the indexes are shifted down byaddresspositions.- Parameters:
address- the starting register addresscount- the number of registers to read- Returns:
- the result set
-
readHoldings
public byte[] readHoldings(int address, int count) Read holding register data into a byte array.- Parameters:
address- the starting addresscount- the number of registers- Returns:
- the register data, of length
count * 2
-
readInputs
public byte[] readInputs(int address, int count) Read holding register data into a byte array.- Parameters:
address- the starting addresscount- the number of registers- Returns:
- the register data, of length
count * 2
-
readRegisters
Perform a thread-safe read action on a register block.- Type Parameters:
T- the result type- Parameters:
blockType- the block type, must beHoldingorInputaction- the action to perform- Returns:
- the action result
-
readBits
Perform a thread-safe read action on a register block.- Type Parameters:
T- the result type- Parameters:
blockType- the block type, must beCoilorDiscreteaction- the action to perform- Returns:
- the action result
-
writeHolding
public void writeHolding(int address, short value) Write a holding register value.- Parameters:
address- the register address to savevalue- the value to save
-
writeHoldings
public void writeHoldings(int address, short[] values) Write holding register values.- Parameters:
address- the starting register address to savevalues- the values to save
-
writeInput
public void writeInput(int address, short value) Write an input register value.- Parameters:
address- the register address to savevalue- the value to save
-
writeInputs
public void writeInputs(int address, short[] values) Write input register values.- Parameters:
address- the starting register address to savevalues- the values to save
-
performRegisterUpdates
public final ModbusData performRegisterUpdates(ModbusRegisterBlockType blockType, ModbusData.ModbusDataUpdateAction action) throws IOException Perform a set of updates to saved register data.- Parameters:
blockType- the register block type to perform updates on; must beHoldingorInputaction- the callback to perform the updates on- Returns:
- this updated data
- Throws:
IOException- if any communication error occurs
-
performBitUpdates
public final void performBitUpdates(ModbusRegisterBlockType blockType, ModbusRegisterData.ModbusBitsUpdateAction action) throws IOException Perform a set of updates to saved register data.- Parameters:
blockType- the register block type to perform updates on; must beCoilorDiscreteaction- the callback to perform the updates on; return true to update the associated data timestamp- Throws:
IOException- if any communication error occurs
-
getCoils
Get the coil register data.- Returns:
- the coil registers, never null
-
getDiscretes
Get the discrete register data.- Returns:
- the discrete registers, never null
-
getInputs
Get the input register data.- Returns:
- the input registers, never null
-
getHoldings
Get the holding register data.- Returns:
- the holding registers, never null
-