public class SerialDevice extends Object implements SerialDataListener
Constructor and Description |
---|
SerialDevice(String portName)
Constructor that takes the port name to connect to and the rate at which
to connect.
|
SerialDevice(String portName,
int dataRate,
int dataBits,
int stopBits,
int parity)
Complete constructor that takes all the information required to connect
to a port.
|
Modifier and Type | Method and Description |
---|---|
void |
addSerialDataListener(SerialDataListener sdl)
Add the given
SerialDataListener to the listener list. |
void |
close()
Close the connection to the serial port.
|
void |
dataReceived(String data)
Called when data is received on a serial port.
|
protected void |
finalize() |
protected void |
fireSerialDataEvent(String data)
Fires the serial data event when data is received on the port.
|
InputStream |
getInputStream()
Returns the input stream for this device.
|
OutputStream |
getOutputStream()
Returns the output stream for this device.
|
String |
getRegex()
Returns the regular expression being used to split incoming strings.
|
static HashSet<String> |
getSerialPorts() |
void |
removeSerialDataListener(SerialDataListener sdl)
Remove the given
SerialDataListener from the listener list |
void |
setRegex(String regex)
Set the regular expression to use to split incoming strings.
|
public SerialDevice(String portName) throws Exception
portName
- The port name to connect to.Exception
public SerialDevice(String portName, int dataRate, int dataBits, int stopBits, int parity) throws Exception
portName
- The port name to connect to.dataRate
- The data rate to read from the port.dataBits
- The number of data bitsstopBits
- The number of stop bitsparity
- The bit parityException
protected void finalize() throws Throwable
finalize
in class Object
Throwable
Object.finalize()
public void close() throws IOException
IOException
public void addSerialDataListener(SerialDataListener sdl)
SerialDataListener
to the listener list.sdl
- The SerialDataListener
to add.public void removeSerialDataListener(SerialDataListener sdl)
SerialDataListener
from the listener listsdl
- The SerialDataListener
to remove.protected void fireSerialDataEvent(String data)
data
- The data that was receivedpublic String getRegex()
public void setRegex(String regex)
regex
- the regex to split incoming stringspublic InputStream getInputStream()
public OutputStream getOutputStream()
public void dataReceived(String data)
dataReceived
in interface SerialDataListener
data
- The data that was received as a string.SerialDataListener.dataReceived(java.lang.String)
public static HashSet<String> getSerialPorts()