org.openmuc.jmbus
public class MBusSap extends java.lang.Object
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 serial port.
|
void |
deselectComponent()
Deselects the previously selected meter.
|
int |
getTimeout()
Returns the timeout in ms.
|
void |
open()
Opens the serial port.
|
VariableDataStructure |
read(int primaryAddress)
Reads a meter using primary addressing.
|
void |
selectComponent(SecondaryAddress secondaryAddress)
Selects the meter with the specified secondary address.
|
void |
setTimeout(int timeout)
Sets the maximum time in ms to wait for new data from the remote device.
|
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.public void open() throws java.io.IOException
java.io.IOException
- if any kind of error occurs opening the serial port.public void close()
public void setTimeout(int timeout)
timeout
- the maximum time in ms to wait for new data.public int getTimeout()
public VariableDataStructure read(int primaryAddress) throws java.io.IOException, java.util.concurrent.TimeoutException
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.java.util.concurrent.TimeoutException
- if no response at all (not even a single byte) was received from the meter within the timeout span.public void selectComponent(SecondaryAddress secondaryAddress) throws java.io.IOException, java.util.concurrent.TimeoutException
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.java.util.concurrent.TimeoutException
- 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, java.util.concurrent.TimeoutException
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.java.util.concurrent.TimeoutException
- if no response at all (not even a single byte) was received from the meter within the timeout span.