public class MBusConnection
extends java.lang.Object
implements java.lang.AutoCloseable
Use this access point to communicate using the M-Bus wired protocol.
Modifier and Type | Class and Description |
---|---|
static class |
MBusConnection.MBusSerialBuilder |
static class |
MBusConnection.MBusTcpBuilder |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the service access point.
|
void |
deselectComponent()
Deselects the previously selected meter.
|
void |
linkReset(int primaryAddress)
Sends a SND_NKE message to reset the FCB (frame counter bit).
|
static MBusConnection.MBusSerialBuilder |
newSerialBuilder(java.lang.String serialPortName)
Create a new builder to connect to a serial.
|
static MBusConnection.MBusTcpBuilder |
newTcpBuilder(java.lang.String hostAddress,
int port) |
VariableDataStructure |
read(int primaryAddress)
Reads a meter using primary addressing.
|
void |
resetReadout(int primaryAddress)
Sends a application reset to the slave with specified primary address.
|
java.util.List<SecondaryAddress> |
scan(java.lang.String wildcardMask,
SecondaryAddressListener secondaryAddressListener,
long delay)
Scans for secondary addresses and returns all detected devices in a list and if SecondaryAddressListener not null
to the listen listener.
|
void |
selectComponent(SecondaryAddress secondaryAddress)
Selects the meter with the specified secondary address.
|
void |
selectForReadout(int primaryAddress,
java.util.List<DataRecord> dataRecords)
Selection of wanted records.
|
MBusMessage |
sendLongMessage(int primaryAddr,
int controlField,
int ci,
byte[] data,
boolean responseExpected)
Sends a long message with individual parameters.
|
MBusMessage |
sendShortMessage(int primaryAddr,
int cmd,
boolean responseExpected)
Sends a short message with individual parameters.
|
void |
setVerboseMessageListener(VerboseMessageListener verboseMessageListener)
Sets the verbose mode on if a implementation of debugMessageListener has been set.
|
void |
write(int primaryAddress,
byte[] data)
Writes to a meter using primary addressing.
|
public void close()
close
in interface java.lang.AutoCloseable
public void setVerboseMessageListener(VerboseMessageListener verboseMessageListener)
verboseMessageListener
- Implementation of debugMessageListenerpublic java.util.List<SecondaryAddress> scan(java.lang.String wildcardMask, SecondaryAddressListener secondaryAddressListener, long delay) throws java.io.IOException
wildcardMask
- a wildcard mask for maskingsecondaryAddressListener
- listener to get scan messages and scanned secondary address just at time.delay
- delay between every sent message. Sometimes needed for slow devices. Deactivated if 0 or less.java.io.IOException
- if any kind of error (including timeout) occurs while writing to the remote device. Note that the
connection is not closed when an IOException is thrown.public VariableDataStructure read(int primaryAddress) throws java.io.IOException
primaryAddress
- the primary address of the meter to read. For secondary address use 0xfd.java.io.IOException
- if any kind of error (including timeout) occurs while trying to read the remote device. Note that the
connection is not closed when an IOException is thrown.public MBusMessage sendLongMessage(int primaryAddr, int controlField, int ci, byte[] data, boolean responseExpected) throws java.io.IOException
MBusConnection
.null
if hasResponse is
false
primaryAddr
- the primary address of the meter to read. For secondary address use 0xfd.controlField
- control field (C Field) has the size of 1 byte.ci
- control information field (CI Field) has the size of 1 byte.data
- the data to sends to the meter.responseExpected
- set this flag to false
if no response is expected else true
. If false
returns null
boolean hasResponse
is false
.MBusMessage
if a message received.java.io.IOException
- if any kind of error (including timeout) occurs while trying to send to or read the remote device.
Note that the connection is not closed when an IOException is thrown.public MBusMessage sendShortMessage(int primaryAddr, int cmd, boolean responseExpected) throws java.io.IOException
MBusConnection
.read(int)
.null
if hasResponse is
false
primaryAddr
- the primary address of the meter to read. For secondary address use 0xfd.cmd
- the command to send to the meter.responseExpected
- set this flag to false
if no response is expected else true
. If false
returns null
boolean hasResponse
is false
.MBusMessage
if a message received.java.io.IOException
- f any kind of error (including timeout) occurs while trying to send to or read the remote device.
Note that the connection is not closed when an IOException is thrown.public void write(int primaryAddress, byte[] data) throws java.io.IOException
primaryAddress
- the primary address of the meter to write. For secondary address use 0xfd.data
- the data to sends to the meter.java.io.IOException
- if any kind of error (including timeout) occurs while writing to the remote device. Note that the
connection is not closed when an IOException is thrown.public void selectComponent(SecondaryAddress secondaryAddress) throws java.io.IOException
secondaryAddress
- the secondary address of the meter to select.java.io.IOException
- if any kind of error (including timeout) occurs while trying to read the remote device. Note that the
connection is not closed when an IOException is thrown.public void deselectComponent() throws java.io.IOException
java.io.IOException
- if any kind of error (including timeout) occurs while trying to read the remote device. Note that the
connection is not closed when an IOException is thrown.public void selectForReadout(int primaryAddress, java.util.List<DataRecord> dataRecords) throws java.io.IOException
primaryAddress
- primary address of the slavedataRecords
- data record to selectjava.io.IOException
- if any kind of error (including timeout) occurs while trying to read the remote device. Note that the
connection is not closed when an IOException is thrown.public void resetReadout(int primaryAddress) throws java.io.IOException
primaryAddress
- primary address of the slavejava.io.IOException
- if any kind of error (including timeout) occurs while trying to read the remote device. Note that the
connection is not closed when an IOException is thrown.public void linkReset(int primaryAddress) throws java.io.IOException
primaryAddress
- the primary address of the meter to reset.java.io.IOException
- if an error occurs during the reset process.public static MBusConnection.MBusTcpBuilder newTcpBuilder(java.lang.String hostAddress, int port)
public static MBusConnection.MBusSerialBuilder newSerialBuilder(java.lang.String serialPortName)
serialPortName
- the serial port. e.g. /dev/ttyS0
.