|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.comm.CommPort
javax.comm.SerialPort
com.sun.comm.LinuxSerial
| Nested Class Summary | |
private class |
LinuxSerial.SSCheckStatusThread
|
class |
LinuxSerial.SSInputStream
|
class |
LinuxSerial.SSOutputStream
|
private class |
LinuxSerial.SSReaderThread
|
| Field Summary | |
private int |
baud
|
private LinuxSerial.SSCheckStatusThread |
checkStatus
|
private int |
databits
|
private int |
flowcontrol
|
private int |
framing_byte
|
private int |
ibuffer_size
|
private LinuxSerial.SSInputStream |
inputStream
|
private SerialPortEventListener |
listener
|
private int |
notificationMask
|
private static int |
NOTIFY_BreakInterrupt
|
private static int |
NOTIFY_CarrierDetect
|
private static int |
NOTIFY_CTS
|
private static int |
NOTIFY_DataAvailable
|
private static int |
NOTIFY_DSR
|
private static int |
NOTIFY_FramingError
|
private static int |
NOTIFY_OutputEmpty
|
private static int |
NOTIFY_OverrunError
|
private static int |
NOTIFY_ParityError
|
private static int |
NOTIFY_RingIndicator
|
private int |
obuffer_size
|
private LinuxSerial.SSOutputStream |
outputStream
|
private int |
parity
|
private int |
port_fd
|
private boolean |
portInError
|
private int |
rcvThreshold
|
private int |
rcvTimeout
|
private LinuxSerial.SSReaderThread |
readerThread
|
private static int |
STATUS_CD
|
private static int |
STATUS_CTS
|
private static int |
STATUS_DATA_AVAIL
|
private static int |
STATUS_DSR
|
private static int |
STATUS_DTR
|
private static int |
STATUS_OUTPUTEMPTY
|
private static int |
STATUS_RI
|
private static int |
STATUS_RTS
|
private int |
stopbits
|
private boolean |
write_finished_flag
|
private java.lang.Object |
write_finished_flag_lock
|
| Fields inherited from class javax.comm.SerialPort |
DATABITS_5, DATABITS_6, DATABITS_7, DATABITS_8, FLOWCONTROL_NONE, FLOWCONTROL_RTSCTS_IN, FLOWCONTROL_RTSCTS_OUT, FLOWCONTROL_XONXOFF_IN, FLOWCONTROL_XONXOFF_OUT, PARITY_EVEN, PARITY_MARK, PARITY_NONE, PARITY_ODD, PARITY_SPACE, STOPBITS_1, STOPBITS_1_5, STOPBITS_2 |
| Fields inherited from class javax.comm.CommPort |
name |
| Constructor Summary | |
LinuxSerial(java.lang.String theName)
|
|
| Method Summary | |
void |
addEventListener(SerialPortEventListener lsnr)
Registers a SerialPortEventListener object to listen
for SerialEvents. |
void |
close()
Closes the communications port. |
void |
disableReceiveFraming()
Disables receive framing. |
void |
disableReceiveThreshold()
Disables receive threshold. |
void |
disableReceiveTimeout()
Disables receive timeout. |
void |
enableReceiveFraming(int framingByte)
Enables receive framing, if this feature is supported by the driver. |
void |
enableReceiveThreshold(int thresh)
Enables receive threshold, if this feature is supported by the driver. |
void |
enableReceiveTimeout(int timeout)
Enables receive timeout, if this feature is supported by the driver. |
int |
getBaudRate()
Gets the currently configured baud rate. |
int |
getDataBits()
Gets the currently configured number of data bits. |
int |
getFlowControlMode()
Gets the currently configured flow control mode. |
int |
getInputBufferSize()
Gets the input buffer size. |
java.io.InputStream |
getInputStream()
Returns an input stream. |
int |
getOutputBufferSize()
Gets the output buffer size. |
java.io.OutputStream |
getOutputStream()
Returns an output stream. |
int |
getParity()
Get the currently configured parity setting. |
int |
getReceiveFramingByte()
Gets the current byte used for receive framing. |
int |
getReceiveThreshold()
Gets the integer value of the receive threshold. |
int |
getReceiveTimeout()
Gets the integer value of the receive timeout. |
int |
getStopBits()
Gets the currently defined stop bits. |
boolean |
isCD()
Gets the state of the CD (Carrier Detect) bit in the UART, if supported by the underlying implementation. |
boolean |
isCTS()
Gets the state of the CTS (Clear To Send) bit in the UART, if supported by the underlying implementation. |
boolean |
isDSR()
Gets the state of the DSR (Data Set Ready) bit in the UART, if supported by the underlying implementation. |
boolean |
isDTR()
Gets the state of the DTR (Data Terminal Ready) bit in the UART, if supported by the underlying implementation. |
boolean |
isReceiveFramingEnabled()
Checks if receive framing is enabled. |
boolean |
isReceiveThresholdEnabled()
Checks if receive threshold is enabled. |
boolean |
isReceiveTimeoutEnabled()
Checks if receive timeout is enabled. |
boolean |
isRI()
Gets the state of the RI (Ring Indicator) bit in the UART, if supported by the underlying implementation. |
boolean |
isRTS()
Gets the state of the RTS (Request To Send) bit in the UART, if supported by the underlying implementation. |
private int |
nativeAvailable(int port_fd)
|
private int |
nativeCheckBreak(int port_fd)
|
private int |
nativeCheckParityErrors(int port_fd)
|
private void |
nativeClosePort(int port_fd)
|
private int |
nativeFlush(int port_fd)
|
private int |
nativeGetBaudRate(int port_fd)
|
private int |
nativeGetDataBits(int port_fd)
|
private int |
nativeGetFlowControlMode(int port_fd)
|
private int |
nativeGetParity(int port_fd)
|
private int |
nativeGetStatusFlags(int port_fd)
|
private int |
nativeGetStopBits(int port_fd)
|
private int |
nativeOpenPort(java.lang.String name)
|
private int |
nativeRead(int port_fd,
byte[] buf,
int offset,
int len,
int timeout,
int threshold)
|
private int |
nativeReaderThread(int port_fd)
|
private void |
nativeSendBreak(int port_fd,
int millis)
|
private void |
nativeSetDTR(int port_fd,
boolean dtr)
|
private void |
nativeSetFramingByte(int port_fd,
int framingByte)
|
private void |
nativeSetRTS(int port_fd,
boolean rts)
|
private void |
nativeSetSerialPortParams(int port_fd,
int baudRate,
int dataBits,
int stopBits,
int parity,
int flowControl)
|
private void |
nativeWaitForEvent(int port_fd)
|
private int |
nativeWrite(int port_fd,
byte[] buf,
int offset,
int len)
|
void |
notifyOnBreakInterrupt(boolean enable)
Expresses interest in receiving notification when there is a break interrupt on the line. |
void |
notifyOnCarrierDetect(boolean enable)
Expresses interest in receiving notification when the CD (Carrier Detect) bit changes. |
void |
notifyOnCTS(boolean enable)
Expresses interest in receiving notification when the CTS (Clear To Send) bit changes. |
void |
notifyOnDataAvailable(boolean enable)
Expresses interest in receiving notification when input data is available. |
void |
notifyOnDSR(boolean enable)
Expresses interest in receiving notification when the DSR (Data Set Ready) bit changes. |
void |
notifyOnFramingError(boolean enable)
Expresses interest in receiving notification when there is a framing error. |
void |
notifyOnOutputEmpty(boolean enable)
Expresses interest in receiving notification when the output buffer is empty. |
void |
notifyOnOverrunError(boolean enable)
Expresses interest in receiving notification when there is an overrun error. |
void |
notifyOnParityError(boolean enable)
Expresses interest in receiving notification when there is a parity error. |
void |
notifyOnRingIndicator(boolean enable)
Expresses interest in receiving notification when the RI (Ring Indicator) bit changes. |
void |
removeEventListener()
Deregisters event listener registered using addEventListener. |
void |
sendBreak(int millis)
Sends a break of millis milliseconds duration. |
void |
setDTR(boolean dtr)
Sets or clears the DTR (Data Terminal Ready) bit in the UART, if supported by the underlying implementation. |
void |
setFlowControlMode(int FlowControl)
Sets the flow control mode. |
void |
setInputBufferSize(int size)
Sets the input buffer size. |
void |
setOutputBufferSize(int size)
Sets the output buffer size. |
void |
setRTS(boolean rts)
Sets or clears the RTS (Request To Send) bit in the UART, if supported by the underlying implementation. |
void |
setSerialPortParams(int baudrate,
int dataBits,
int stopBits,
int parity)
Sets serial port parameters. |
| Methods inherited from class javax.comm.SerialPort |
setRcvFifoTrigger |
| Methods inherited from class javax.comm.CommPort |
getName, toString |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
private int port_fd
private int rcvThreshold
private int rcvTimeout
private int framing_byte
private int ibuffer_size
private int obuffer_size
private SerialPortEventListener listener
private LinuxSerial.SSCheckStatusThread checkStatus
private LinuxSerial.SSReaderThread readerThread
private LinuxSerial.SSInputStream inputStream
private LinuxSerial.SSOutputStream outputStream
private int baud
private int databits
private int parity
private int stopbits
private int flowcontrol
private boolean portInError
private boolean write_finished_flag
private java.lang.Object write_finished_flag_lock
private static final int STATUS_DTR
private static final int STATUS_RTS
private static final int STATUS_CTS
private static final int STATUS_DSR
private static final int STATUS_RI
private static final int STATUS_CD
private static final int STATUS_DATA_AVAIL
private static final int STATUS_OUTPUTEMPTY
private int notificationMask
private static final int NOTIFY_DataAvailable
private static final int NOTIFY_OutputEmpty
private static final int NOTIFY_CTS
private static final int NOTIFY_DSR
private static final int NOTIFY_RingIndicator
private static final int NOTIFY_CarrierDetect
private static final int NOTIFY_OverrunError
private static final int NOTIFY_ParityError
private static final int NOTIFY_FramingError
private static final int NOTIFY_BreakInterrupt
| Constructor Detail |
public LinuxSerial(java.lang.String theName)
throws java.io.IOException
| Method Detail |
private int nativeOpenPort(java.lang.String name)
throws java.io.IOException
java.io.IOExceptionpublic int getBaudRate()
SerialPort
getBaudRate in class SerialPortprivate int nativeGetBaudRate(int port_fd)
public int getDataBits()
SerialPort
getDataBits in class SerialPortprivate int nativeGetDataBits(int port_fd)
public int getStopBits()
SerialPort
getStopBits in class SerialPortprivate int nativeGetStopBits(int port_fd)
public int getParity()
SerialPort
getParity in class SerialPortprivate int nativeGetParity(int port_fd)
public void sendBreak(int millis)
SerialPortmillis milliseconds duration.
Note that it may not be possible to time the duration of the break
under certain Operating Systems. Hence this parameter is advisory.
sendBreak in class SerialPortmillis - duration of break to send
private void nativeSendBreak(int port_fd,
int millis)
public int getFlowControlMode()
SerialPort
getFlowControlMode in class SerialPortprivate int nativeGetFlowControlMode(int port_fd)
public int getInputBufferSize()
CommPort
getInputBufferSize in class CommPortpublic void setInputBufferSize(int size)
CommPort
setInputBufferSize in class CommPortsize - size of the input bufferpublic int getOutputBufferSize()
CommPort
getOutputBufferSize in class CommPortpublic void disableReceiveTimeout()
CommPort
disableReceiveTimeout in class CommPort
public void enableReceiveTimeout(int timeout)
throws UnsupportedCommOperationException
CommPortread
from the input stream for this port will return immediately.
enableReceiveTimeout is an advisory method which the driver
may not implement. By default, receive timeout is not enabled.
An application can determine whether the driver supports this feature
by first calling the enableReceiveTimeout method and then
calling the isReceiveTimeout method. If
isReceiveTimeout still returns false, then receive timeout
is not supported by the driver.
See getInputStream for description of exact behaviour.
enableReceiveTimeout in class CommPorttimeout - when this many milliseconds have elapsed, return
immediately from read, regardless of bytes in
input buffer.
UnsupportedCommOperationException - is thrown if receive
timeout is not supported by the underlying driver.public int getReceiveTimeout()
CommPort
getReceiveTimeout in class CommPortpublic boolean isReceiveTimeoutEnabled()
CommPort
isReceiveTimeoutEnabled in class CommPortpublic void setOutputBufferSize(int size)
CommPort
setOutputBufferSize in class CommPortsize - size of the output bufferpublic boolean isCD()
SerialPort
isCD in class SerialPortpublic boolean isCTS()
SerialPort
isCTS in class SerialPortpublic boolean isDSR()
SerialPort
isDSR in class SerialPortpublic boolean isDTR()
SerialPort
isDTR in class SerialPortpublic boolean isRI()
SerialPort
isRI in class SerialPortpublic boolean isRTS()
SerialPort
isRTS in class SerialPortprivate int nativeGetStatusFlags(int port_fd)
public void setDTR(boolean dtr)
SerialPort
setDTR in class SerialPortdtr -
private void nativeSetDTR(int port_fd,
boolean dtr)
public void setRTS(boolean rts)
SerialPort
setRTS in class SerialPortrts -
private void nativeSetRTS(int port_fd,
boolean rts)
public boolean isReceiveFramingEnabled()
CommPort
isReceiveFramingEnabled in class CommPort
public void enableReceiveFraming(int framingByte)
throws UnsupportedCommOperationException
CommPortread
from the input stream for this port will return immediately.
enableReceiveFraming is an advisory method which the driver
may not implement. By default, receive framing is not enabled.
An application can determine whether the driver supports this feature
by first calling the enableReceiveFraming method and then
calling the isReceiveFramingEnabled method. If
isReceiveFramingEnabled still returns false, then receive
framing is not supported by the driver.
Note: As implemented in this method, framing is not related to bit-level framing at the hardware level, and is not associated with data errors.
enableReceiveFraming in class CommPortframingByte - this byte in the input stream
suggests the end of the received frame. Blocked reads
will return immediately. Only the low 8 bits of framingByte
are used while the upper 24 bits are masked off. A value outside the range
of 0-255 will be converted to the value of its lowest 8 bits.
UnsupportedCommOperationException - is thrown if receive
timeout is not supported by the underlying driver.public void disableReceiveFraming()
CommPort
disableReceiveFraming in class CommPortpublic int getReceiveFramingByte()
CommPortgetReceiveFramingByte
is an integer, the low 8 bits of which represent the current byte
used for receive framing.
Note: As implemented in this method, framing is not related to bit-level framing at the hardware level, and is not associated with data errors.
getReceiveFramingByte in class CommPort
private void nativeSetFramingByte(int port_fd,
int framingByte)
public boolean isReceiveThresholdEnabled()
CommPort
isReceiveThresholdEnabled in class CommPort
public void enableReceiveThreshold(int thresh)
throws UnsupportedCommOperationException
CommPortread
from the input stream for this port will return immediately.
enableReceiveThreshold is an advisory method which the driver
may not implement. By default, receive threshold is not enabled.
An application can determine whether the driver supports this feature
by first calling the enableReceiveThreshold method and then
calling the isReceiveThresholdEnabled method. If
isReceiveThresholdEnabled still returns false, then receive
threshold is not supported by the driver. If the driver does not implement
this feature, it will return from blocking reads at an appropriate time.
See getInputStream for description of exact behaviour.
enableReceiveThreshold in class CommPortthresh - when this many bytes are in the input buffer, return
immediately from read.
UnsupportedCommOperationException - is thrown if receive
threshold is not supported by the underlying driver.public void disableReceiveThreshold()
CommPort
disableReceiveThreshold in class CommPortpublic int getReceiveThreshold()
CommPort
getReceiveThreshold in class CommPort
public void setSerialPortParams(int baudrate,
int dataBits,
int stopBits,
int parity)
throws UnsupportedCommOperationException
SerialPort
setSerialPortParams in class SerialPortbaudrate - If the baudrate passed in by the application is unsupported by the
driver, the driver will throw an UnsupportedCommOperationExceptiondataBits - stopBits - parity - UnsupportedCommOperationException - if any of the
above parameters are specified incorrectly.
All four of the parameters will revert to the
values before the call was made.
DEFAULT: 9600 baud, 8 data bits, 1 stop bit, no parity
private void nativeSetSerialPortParams(int port_fd,
int baudRate,
int dataBits,
int stopBits,
int parity,
int flowControl)
public void setFlowControlMode(int FlowControl)
throws UnsupportedCommOperationException
SerialPort
setFlowControlMode in class SerialPortFlowControl - Can be a bitmask combination of
UnsupportedCommOperationException - if any of the
flow control mode was not supported by the underline
OS, or if input and output flow control are set to
different values, i.e. one hardware and one software.
The flow control mode will revert to the
value before the call was made.
public void notifyOnBreakInterrupt(boolean enable)
SerialPortThis notification is hardware dependent and may not be supported by all implementations.
notifyOnBreakInterrupt in class SerialPortenable - public void notifyOnCarrierDetect(boolean enable)
SerialPortThis notification is hardware dependent and may not be supported by all implementations.
notifyOnCarrierDetect in class SerialPortenable - public void notifyOnCTS(boolean enable)
SerialPortThis notification is hardware dependent and may not be supported by all implementations.
notifyOnCTS in class SerialPortenable - public void notifyOnDataAvailable(boolean enable)
SerialPortaddEventListener.
The event will be generated once when new data arrive at the serial port. Even if the user doesn't read the data, it won't be generated again until next time new data arrive.
notifyOnDataAvailable in class SerialPortenable - public void notifyOnDSR(boolean enable)
SerialPortThis notification is hardware dependent and may not be supported by all implementations.
notifyOnDSR in class SerialPortenable - public void notifyOnFramingError(boolean enable)
SerialPortThis notification is hardware dependent and may not be supported by all implementations.
notifyOnFramingError in class SerialPortenable - public void notifyOnOutputEmpty(boolean enable)
SerialPortaddEventListener.
The event will be generated after a write is completed, when the system
buffer becomes empty again.
This notification is hardware dependent and may not be supported by all implementations.
notifyOnOutputEmpty in class SerialPortenable - public void notifyOnOverrunError(boolean enable)
SerialPortThis notification is hardware dependent and may not be supported by all implementations.
notifyOnOverrunError in class SerialPortenable - public void notifyOnParityError(boolean enable)
SerialPortThis notification is hardware dependent and may not be supported by all implementations.
notifyOnParityError in class SerialPortenable - public void notifyOnRingIndicator(boolean enable)
SerialPortThis notification is hardware dependent and may not be supported by all implementations.
notifyOnRingIndicator in class SerialPortenable - public void close()
CommPortclose when it is done with the port.
Notification of this ownership change will be propagated to all classes
registered using addPortOwnershipListener.
close in class CommPortprivate void nativeClosePort(int port_fd)
private int nativeAvailable(int port_fd)
private int nativeRead(int port_fd,
byte[] buf,
int offset,
int len,
int timeout,
int threshold)
private int nativeWrite(int port_fd,
byte[] buf,
int offset,
int len)
private int nativeFlush(int port_fd)
private void nativeWaitForEvent(int port_fd)
private int nativeCheckBreak(int port_fd)
private int nativeCheckParityErrors(int port_fd)
public void addEventListener(SerialPortEventListener lsnr)
throws java.util.TooManyListenersException
SerialPortSerialPortEventListener object to listen
for SerialEvents. Interest in specific events may
be expressed using the notifyOnXXX calls. The
serialEvent method of SerialPortEventListener
will be called with a SerialEvent object describing
the event.
The current implementation only allows one listener per SerialPort.
Once a listener is registered, subsequent call attempts to addEventListener
will throw a TooManyListenersException without effecting the listener already registered.
All the events received by this listener are generated by one
dedicated thread that belongs to the SerialPort object. After the port
is closed, no more event will be generated. Another call to
open() of the port's CommPortIdentifier
object will return a new CommPort object, and the lsnr
has to be added again to the new CommPort object to
receive event from this port.
addEventListener in class SerialPortlsnr - The SerialPortEventListener object
whose serialEvent method will be called
with a SerialEvent describing the event.
java.util.TooManyListenersException - If an initial attempt to
attach a listener succeeds,
subsequent attempts will throw
TooManyListenersException without effecting
the first listener.public void removeEventListener()
SerialPortaddEventListener.
This is done automatically at port close.
removeEventListener in class SerialPort
public java.io.InputStream getInputStream()
throws java.io.IOException
CommPortgetInputStream
returns null.
The read behaviour of the input stream returned by
getInputStream depends on combination of the
threshold and timeout values. The possible behaviours are
described in the table below:
| Threshold | Timeout | Read Buffer Size | Read Behaviour | ||
|---|---|---|---|---|---|
| State | Value | State | Value | ||
| disabled | - | disabled | - | n bytes | block until any data is available |
| enabled | m bytes | disabled | - | n bytes | block until min(m,n) bytes are available |
| disabled | - | enabled | x ms | n bytes | block for x ms or until any data is available |
| enabled | m bytes | enabled | x ms | n bytes | block for x ms or until min(m,n) bytes are available |
Note, however, that framing errors may cause the Timeout and Threshold values to complete prematurely without raising an exception.
Enabling the Timeout OR Threshold with a value a zero is a special case. This causes the underlying driver to poll for incoming data instead being event driven. Otherwise, the behaviour is identical to having both the Timeout and Threshold disabled.
getInputStream in class CommPortjava.io.IOException - if an I/O error occurred
public java.io.OutputStream getOutputStream()
throws java.io.IOException
CommPortgetOutputStream
returns null.
getOutputStream in class CommPortjava.io.IOException - if an I/O error occurredprivate int nativeReaderThread(int port_fd)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||