public class MBusSap
extends java.lang.Object
implements java.lang.AutoCloseable
Use this access point to communicate using the M-Bus wired protocol.
Constructor and Description |
---|
MBusSap(java.lang.String serialPortName,
int baudRate)
Creates an M-Bus Service Access Point that is used to read meters.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the M-Bus SAP.
|
void |
deselectComponent()
Deselects the previously selected meter.
|
int |
getTimeout()
Returns the timeout in milliseconds (ms).
|
void |
linkReset(int primaryAddress)
Sends a SND_NKE message to reset the FCB (frame counter bit).
|
void |
open()
Opens the serial 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.
|
boolean |
scanSelection(SecondaryAddress wildcard)
Scans if any device response to the given wildcard.
|
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.
|
void |
setEchoCancellation(boolean echoCancellation)
Set true for activating echo cancellation.
|
void |
setTimeout(int timeout)
Sets the maximum time in ms to wait for new data from the remote device.
|
void |
setVerboseMessageListener(VerboseMessageListener verboseMessageListener)
Sets the verbose mode on if a implementation of debugMessageListener is setted.
|
boolean |
write(int primaryAddress,
byte[] data)
Writes to a meter using primary addressing.
|
public MBusSap(java.lang.String serialPortName, int baudRate)
serialPortName
- examples for serial port identifiers are on Linux "/dev/ttyS0" or "/dev/ttyUSB0" and on Windows "COM1"baudRate
- the baud rate to use.open()
public void open() throws java.io.IOException
java.io.IOException
- if any kind of error occurs opening the serial port.public void close()
close
in interface java.lang.AutoCloseable
public void setTimeout(int timeout)
timeout
- the maximum time in ms to wait for new data. Must be greater then 0.public int getTimeout()
public void setVerboseMessageListener(VerboseMessageListener verboseMessageListener)
verboseMessageListener
- Implementation of debugMessageListenerpublic void setEchoCancellation(boolean echoCancellation)
Note: UNTESTED!
echoCancellation
- for activating true else falsepublic VariableDataStructure read(int primaryAddress) throws java.io.IOException, org.openmuc.jrxtx.SerialPortTimeoutException
primaryAddress
- the primary address of the meter to read. For secondary address use 0xfd.java.io.InterruptedIOException
- if no response at all (not even a single byte) was received from the meter within the timeout span.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.org.openmuc.jrxtx.SerialPortTimeoutException
- if no response at all (not even a single byte) was received from the meter within the timeout span.public boolean write(int primaryAddress, byte[] data) throws java.io.IOException, org.openmuc.jrxtx.SerialPortTimeoutException
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 trying to read the remote device. Note that the
connection is not closed when an IOException is thrown.org.openmuc.jrxtx.SerialPortTimeoutException
- if no response at all (not even a single byte) was received from the meter within the timeout span.public boolean scanSelection(SecondaryAddress wildcard)
wildcard
- secondary address wildcard e.g. f1ffffffffffffffpublic void selectComponent(SecondaryAddress secondaryAddress) throws java.io.IOException, org.openmuc.jrxtx.SerialPortTimeoutException
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.org.openmuc.jrxtx.SerialPortTimeoutException
- if no response at all (not even a single byte) was received from the meter within the timeout span.public void deselectComponent() throws java.io.IOException, org.openmuc.jrxtx.SerialPortTimeoutException
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.org.openmuc.jrxtx.SerialPortTimeoutException
- if no response at all (not even a single byte) was received from the meter within the timeout span.public void selectForReadout(int primaryAddress, java.util.List<DataRecord> dataRecords) throws java.io.IOException, org.openmuc.jrxtx.SerialPortTimeoutException
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.org.openmuc.jrxtx.SerialPortTimeoutException
- if no response at all (not even a single byte) was received from the meter within the timeout span.public void resetReadout(int primaryAddress) throws java.io.IOException, org.openmuc.jrxtx.SerialPortTimeoutException
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.org.openmuc.jrxtx.SerialPortTimeoutException
- if no response at all (not even a single byte) was received from the meter within the timeout span.public void linkReset(int primaryAddress) throws java.io.IOException, org.openmuc.jrxtx.SerialPortTimeoutException
primaryAddress
- the primary address of the meter to reset.java.io.InterruptedIOException
- if the slave does not answer with an 0xe5 message within the configured timeout span.java.io.IOException
- if an error occurs during the reset process.org.openmuc.jrxtx.SerialPortTimeoutException
- - * if the slave does not answer with an 0xe5 message within the configured timeout span.