|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.rm5248.serial.SerialPort
public class SerialPort
A SerialPort object represents a SerialPort object on the system.
When creating a SerialPort object, you give the SerialPort the name of the port that you
wish to open.
When opening a SerialPort and setting values, an IllegalArgumentException
may be thrown
if any of the values are NULL.
When getting and settings the properties of the SerialPort using one of the getXXX()
or setXXX()
methods, an IllegalStateException will be thrown if the port has been closed.
Nested Class Summary | |
---|---|
static class |
SerialPort.BaudRate
Represents the BaudRate that the SerialPort uses. |
static class |
SerialPort.DataBits
Represents the number of bits that the serial port uses. |
static class |
SerialPort.FlowControl
The Flow control scheme for the data, typically None. |
static class |
SerialPort.Parity
The parity bit for the data. |
static class |
SerialPort.StopBits
The number of stop bits for data. |
Constructor Summary | |
---|---|
SerialPort(java.lang.String portName)
Open the specified port, 9600 baud, 8 data bits, 1 stop bit, no parity, no flow control |
|
SerialPort(java.lang.String portName,
boolean keepSettings)
Open up a serial port, but allow the user to keep the current settings of the serial port. |
|
SerialPort(java.lang.String portName,
SerialPort.BaudRate rate)
Open the specified port, no flow control |
|
SerialPort(java.lang.String portName,
SerialPort.BaudRate rate,
SerialPort.DataBits data)
Open the specified port, no flow control |
|
SerialPort(java.lang.String portName,
SerialPort.BaudRate rate,
SerialPort.DataBits data,
SerialPort.StopBits stop)
Open the specified port, no parity or flow control |
|
SerialPort(java.lang.String portName,
SerialPort.BaudRate rate,
SerialPort.DataBits data,
SerialPort.StopBits stop,
SerialPort.Parity parity)
Open the specified port, no flow control |
|
SerialPort(java.lang.String portName,
SerialPort.BaudRate rate,
SerialPort.DataBits data,
SerialPort.StopBits stop,
SerialPort.Parity parity,
SerialPort.FlowControl flow)
Open the specified port, defining all options |
Method Summary | |
---|---|
void |
close()
Close the serial port, and all input streams |
void |
finalize()
|
SerialPort.BaudRate |
getBaudRate()
Get the baud rate of the serial port. |
SerialPort.DataBits |
getDataBits()
Get the number of data bits. |
SerialPort.FlowControl |
getFlowControl()
Get the flow control for the serial port. |
java.io.InputStream |
getInputStream()
Get the input stream to be used to read from this SerialPort. |
static int |
getMajorNativeVersion()
Get the major version of the native code. |
static int |
getMajorVersion()
Get the major version of this library. |
static int |
getMinorNativeVersion()
Get the minor version of the native code. |
static int |
getMinorVersion()
Get the minor version of this library. |
java.io.OutputStream |
getOutputStream()
Get the output stream used to write data to this device. |
SerialPort.Parity |
getParity()
Get the parity of the serial port. |
java.lang.String |
getPortName()
Get the name of the serial port that this object represents. |
SerialLineState |
getSerialLineState()
Get the serial line state for the specified serial port. |
static java.lang.String[] |
getSerialPorts()
Get an array of all the serial ports on the system. |
SerialPort.StopBits |
getStopBits()
Get the number of stop bits. |
boolean |
isClosed()
See if the port has been closed already. |
void |
setBaudRate(SerialPort.BaudRate rate)
Set the Baud Rate for this port. |
void |
setDataSize(SerialPort.DataBits data)
Set the data bits size, after the port has been opened. |
void |
setFlowControl(SerialPort.FlowControl flow)
Set the flow control for the serial port |
void |
setParity(SerialPort.Parity parity)
Set the parity of the serial port, after the port has been opened. |
void |
setSerialChangeListener(SerialChangeListener listen)
Set the listener which will get events when there is activity on the serial port. |
void |
setSerialLineState(SerialLineState state)
Set the serial line state to the parameters given. |
void |
setStopBits(SerialPort.StopBits stop)
Set the stop bits of the serial port, after the port has been opened. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SerialPort(java.lang.String portName) throws NoSuchPortException, NotASerialPortException
portName
- The name of the port to open
NoSuchPortException
- If this port does not exist
NotASerialPortException
- If the specified port is not a serial portpublic SerialPort(java.lang.String portName, boolean keepSettings) throws NoSuchPortException, NotASerialPortException
portName
- The port to openkeepSettings
- If true, will simply open the serial port without setting anything. If false, this method
acts the same as SerialPort( String portName )
NoSuchPortException
- If the port does not exist
NotASerialPortException
- If the port is not in fact a serial portpublic SerialPort(java.lang.String portName, SerialPort.BaudRate rate) throws NoSuchPortException, NotASerialPortException
portName
- The name of the port to openrate
- The Baud Rate to open this port at
NoSuchPortException
- If this port does not exist
NotASerialPortException
- If the specified port is not a serial portpublic SerialPort(java.lang.String portName, SerialPort.BaudRate rate, SerialPort.DataBits data) throws NoSuchPortException, NotASerialPortException
portName
- The name of the port to openrate
- The Baud Rate to open this port atdata
- The number of data bits
NoSuchPortException
- If this port does not exist
NotASerialPortException
- If the specified port is not a serial portpublic SerialPort(java.lang.String portName, SerialPort.BaudRate rate, SerialPort.DataBits data, SerialPort.StopBits stop) throws NoSuchPortException, NotASerialPortException
portName
- The name of the port to openrate
- The Baud Rate to open this port atdata
- The number of data bitsstop
- The number of stop bits
NoSuchPortException
- If this port does not exist
NotASerialPortException
- If the specified port is not a serial portpublic SerialPort(java.lang.String portName, SerialPort.BaudRate rate, SerialPort.DataBits data, SerialPort.StopBits stop, SerialPort.Parity parity) throws NoSuchPortException, NotASerialPortException
portName
- The name of the port to openrate
- The Baud Rate to open this port atdata
- The number of data bitsstop
- The number of stop bitsparity
- The parity of the line
NoSuchPortException
- If this port does not exist
NotASerialPortException
- If the specified port is not a serial portpublic SerialPort(java.lang.String portName, SerialPort.BaudRate rate, SerialPort.DataBits data, SerialPort.StopBits stop, SerialPort.Parity parity, SerialPort.FlowControl flow) throws NoSuchPortException, NotASerialPortException
portName
- The name of the port to openrate
- The Buad Rate to open this port atdata
- The number of data bitsstop
- The number of stop bitsparity
- The parity of the lineflow
- The flow control of the line
NoSuchPortException
- If this port does not exist
NotASerialPortException
- If the specified port is not a serial portMethod Detail |
---|
public void setBaudRate(SerialPort.BaudRate rate)
rate
- public java.io.InputStream getInputStream()
public java.io.OutputStream getOutputStream()
public void close()
close
in interface java.io.Closeable
public boolean isClosed()
public void finalize()
finalize
in class java.lang.Object
public void setStopBits(SerialPort.StopBits stop)
stop
- public void setDataSize(SerialPort.DataBits data)
data
- public void setParity(SerialPort.Parity parity)
parity
- public SerialLineState getSerialLineState() throws java.io.IOException
java.io.IOException
public void setSerialLineState(SerialLineState state)
state
- public SerialPort.BaudRate getBaudRate()
public SerialPort.DataBits getDataBits()
public SerialPort.StopBits getStopBits()
public SerialPort.Parity getParity()
public SerialPort.FlowControl getFlowControl()
public void setFlowControl(SerialPort.FlowControl flow)
flow
- public void setSerialChangeListener(SerialChangeListener listen)
listen
- The listener which gets eventspublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getPortName()
public static int getMajorVersion()
public static int getMinorVersion()
public static int getMajorNativeVersion()
getMajorVersion()
, although this is not
guaranteed. For example, if this is version 0.2, this returns 0
public static int getMinorNativeVersion()
getMinorVersion()
, although this is not
guaranteed. For example, if this is version 0.2, this returns 2.
public static java.lang.String[] getSerialPorts()
Get an array of all the serial ports on the system. For example, on
Windows this will return { "COM1", "COM3", .... }
depending on how
many serial devices you have plugged in. On Linux, this returns
{ "/dev/ttyS0", "/dev/ttyUSB0", "/dev/symlink", ... }
It will not resolve symlinks, such that if there is a symlink
from /dev/symlink
to /dev/ttyUSB0
, they will both show up.
NOTE: this will only return ports that you have permissions to open.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |