org.openmuc.j62056
public class Connection extends java.lang.Object
Constructor and Description |
---|
Connection(java.lang.String serialPort)
Creates a Connection object.
|
Connection(java.lang.String serialPort,
boolean handleEcho,
int baudRateChangeDelay)
Creates a Connection object.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
int |
getTimeout()
Returns the timeout in ms.
|
void |
open()
Opens the serial port associated with this connection.
|
java.util.List<DataSet> |
read()
Requests a data message from the remote device using IEC 62056-21 Mode C.
|
void |
setTimeout(int timeout)
Sets the maximum time in ms to wait for new data from the remote device.
|
public Connection(java.lang.String serialPort, boolean handleEcho, int baudRateChangeDelay)
open()
before calling read()
in order to
read data. The timeout is set by default to 5s.serialPort
- examples for serial port identifiers on Linux are "/dev/ttyS0" or "/dev/ttyUSB0" and on Windows "COM1"handleEcho
- tells the connection to throw away echos of outgoing messages. Echos are caused by some optical
transceivers.baudRateChangeDelay
- tells the connection the time in ms to wait before changing the baud rate during message exchange.
This parameter can usually be set to zero for regular serial ports. If a USB to serial converter is
used, you might have to use a delay of around 250ms because otherwise the baud rate is changed before
the previous message (i.e. the acknowledgment) has been completely sent.public Connection(java.lang.String serialPort)
serialPort
- examples for serial port identifiers on Linux are "/dev/ttyS0" or "/dev/ttyUSB0" and on Windows "COM1"public void setTimeout(int timeout)
timeout
- the maximum time in ms to wait for new data.public int getTimeout()
public void open() throws java.io.IOException
java.io.IOException
- if any kind of error occurs opening the serial port.public java.util.List<DataSet> read() throws java.io.IOException
java.io.IOException
- if any kind of error (including timeout) occurs while trying to read the remote device. The
connection is not closed when an IOException is thrown.public void close()