public class SerialPort extends Object
| Constructor and Description |
|---|
SerialPort()
Constructor.
|
SerialPort(String name)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
closePort()
closes the port.
|
int |
getInputBufferBytesCount()
get the number of bytes available in the buffer (ie non blocking)
|
void |
openPort(String name)
Opens the port.
|
int |
read(byte[] buff,
int offset,
int timeout)
Reads available data into a byte array.
|
byte[] |
readBytes()
read as many bytes as available without blocking.
|
byte[] |
readBytes(int byteCount)
read a given number of bytes from the serial port.
|
byte[] |
readBytes(int byteCount,
int timeout)
read bytes from the serial port.
|
String |
readString()
read all available bytes from the serial port, return as a String
|
String |
readString(int byteCount)
read bytes from the serial port.
|
String |
readString(int byteCount,
int timeout)
read bytes from the serial port.
|
String |
readUntilCRLF()
reads a String until CR+LF occurs.
|
String |
readUntilCRLF(int timeout)
reads a String until CR+LF occurs, with explicit timeout
|
String |
readUntilLF()
reads a String until LF occurs.
|
String |
readUntilLF(int timeout)
reads a String until LF occurs, with explicit timeout
|
String |
readUntilSUPSP()
reads a String until "> " or "< " occurs.
|
String |
readUntilSUPSP(int timeout)
reads a String until "> " or "< " occurs, with explicit timeout
|
boolean |
setFlowControlMode(int mask)
set the flow control mode.
|
boolean |
setParams(int baudRate,
int dataBits,
int stopBits,
int parity)
Set the communication parameters
|
boolean |
writeByte(byte singleByte)
sends a single byte
|
boolean |
writeBytes(byte[] buffer)
sends a byte array
|
boolean |
writeString(String string)
sends a String as byte array
|
void |
writeStringCR(String s)
sends a String + CR as byte array
|
void |
writeStringCRLF(String s)
sends a String + CR + LF as byte array
|
void |
writeStringLF(String s)
sends a String + LF as byte array
|
public SerialPort()
public SerialPort(String name) throws org.lsst.ccs.drivers.commons.DriverException
name - the os-dependant name of the port (eg /dev/ttyXX).org.lsst.ccs.drivers.commons.DriverExceptionpublic void openPort(String name) throws org.lsst.ccs.drivers.commons.DriverException
name - the os-dependant name of the port (eg /dev/ttyXX).org.lsst.ccs.drivers.commons.DriverExceptionpublic boolean closePort()
throws org.lsst.ccs.drivers.commons.DriverException
org.lsst.ccs.drivers.commons.DriverExceptionpublic int getInputBufferBytesCount()
throws org.lsst.ccs.drivers.commons.DriverException
org.lsst.ccs.drivers.commons.DriverExceptionpublic byte[] readBytes()
throws org.lsst.ccs.drivers.commons.DriverException
org.lsst.ccs.drivers.commons.DriverExceptionpublic byte[] readBytes(int byteCount,
int timeout)
throws org.lsst.ccs.drivers.commons.DriverException
byteCount - the number of bytes to readtimeout - milliseconds before failing on timeoutorg.lsst.ccs.drivers.commons.DriverExceptionpublic byte[] readBytes(int byteCount)
throws org.lsst.ccs.drivers.commons.DriverException
byteCount - the number of bytes to readorg.lsst.ccs.drivers.commons.DriverExceptionpublic String readString() throws org.lsst.ccs.drivers.commons.DriverException
org.lsst.ccs.drivers.commons.DriverExceptionpublic String readString(int byteCount, int timeout) throws org.lsst.ccs.drivers.commons.DriverException
byteCount - the number of bytes to readtimeout - milliseconds before failing on timeoutorg.lsst.ccs.drivers.commons.DriverExceptionpublic String readString(int byteCount) throws org.lsst.ccs.drivers.commons.DriverException
byteCount - the number of bytes to readtimeout - milliseconds before failing on timeoutorg.lsst.ccs.drivers.commons.DriverExceptionpublic boolean setFlowControlMode(int mask)
throws org.lsst.ccs.drivers.commons.DriverException
mask - bitfield
0 : NONE
1 : RTSCTS_IN
2 : RTSCTS_OUT
4 : XONXOFF_IN
8 : XONXOFF_OUTorg.lsst.ccs.drivers.commons.DriverExceptionpublic boolean setParams(int baudRate,
int dataBits,
int stopBits,
int parity)
throws org.lsst.ccs.drivers.commons.DriverException
baudRate - baud rate (110, 300, 600, 1200, 4800, 9600, 14400, 19200,
38400, 57600, 115200, 128000, 256000)dataBits - data bits (5, 6, 7, 8)stopBits - stop bits (1, 2, 3 for 1.5)parity - parity (0 none, 1 odd, 2 even, 3 mark, 4 space)org.lsst.ccs.drivers.commons.DriverExceptionpublic boolean writeByte(byte singleByte)
throws org.lsst.ccs.drivers.commons.DriverException
singleByte - the byte to sendorg.lsst.ccs.drivers.commons.DriverExceptionpublic boolean writeBytes(byte[] buffer)
throws org.lsst.ccs.drivers.commons.DriverException
buffer - the byte array to sendorg.lsst.ccs.drivers.commons.DriverExceptionpublic boolean writeString(String string) throws org.lsst.ccs.drivers.commons.DriverException
string - the string to sendorg.lsst.ccs.drivers.commons.DriverExceptionpublic void writeStringCRLF(String s) throws org.lsst.ccs.drivers.commons.DriverException
string - the string to sendorg.lsst.ccs.drivers.commons.DriverExceptionpublic void writeStringLF(String s) throws org.lsst.ccs.drivers.commons.DriverException
string - the string to sendorg.lsst.ccs.drivers.commons.DriverExceptionpublic void writeStringCR(String s) throws org.lsst.ccs.drivers.commons.DriverException
string - the string to sendorg.lsst.ccs.drivers.commons.DriverExceptionpublic String readUntilCRLF() throws org.lsst.ccs.drivers.commons.DriverException
org.lsst.ccs.drivers.commons.DriverExceptionpublic String readUntilLF() throws org.lsst.ccs.drivers.commons.DriverException
org.lsst.ccs.drivers.commons.DriverExceptionpublic String readUntilSUPSP() throws org.lsst.ccs.drivers.commons.DriverException
org.lsst.ccs.drivers.commons.DriverExceptionpublic String readUntilSUPSP(int timeout) throws org.lsst.ccs.drivers.commons.DriverException
timeout - the timeout in msorg.lsst.ccs.drivers.commons.DriverExceptionpublic String readUntilLF(int timeout) throws org.lsst.ccs.drivers.commons.DriverException
timeout - the timeout in msorg.lsst.ccs.drivers.commons.DriverExceptionpublic String readUntilCRLF(int timeout) throws org.lsst.ccs.drivers.commons.DriverException
timeout - the timeout in msorg.lsst.ccs.drivers.commons.DriverExceptionpublic int read(byte[] buff,
int offset,
int timeout)
throws org.lsst.ccs.drivers.commons.DriverException
buff - The buffer to receive the response dataoffset - The offset to the first available byte in the buffertimeout - the timeout in msorg.lsst.ccs.drivers.commons.DriverExceptionCopyright © 2014 LSST. All rights reserved.