sp.setBaudRate(SerialPort.SPEED_300);
}
NOTE: Changing the speed on any of the streams (stdin, stdout, stderr) causes
all streams to change to the speed.
....
|
Constructor Summary |
SerialPort(int portnum,
int stream)
Constructs a new serial port object. |
|
Method Summary |
int |
available()
Returns the number of bytes available on the port. |
void |
close()
Close the serial port. |
void |
disableReceiveTimeout()
disables the receive timeout. |
void |
enableReceiveTimeout()
enables the receive timeout - currently not implemented. |
int |
getInputBufferSize()
Gets the size of the input buffer. |
java.io.InputStream |
getInputStream()
Gets the serial port input stream |
int |
getOutputBufferSize()
Gets the size of the output buffer. |
java.io.OutputStream |
getOutputStream()
Gets the serial port output stream |
boolean |
isReceiveTimeoutEnabled()
Returns true if the receive timeout is enabled. |
void |
open()
Opens the serial port. |
int |
read()
Reads an integer from the serial port. |
int |
read(byte[] arr,
int offset,
int len)
Reads len bytes of array arr from offset to the serial port. |
void |
sendBreak(int timeMS)
Sends a break on the serial port. |
void |
setBaudRate(int speed)
Sets the baud rate for the port. |
void |
setInputBufferSize(int size)
Sets the size of the input buffer. |
void |
setOutputBufferSize(int size)
Sets the size of the output buffer. |
void |
setReceiveTimeout(int timeout)
sets the receive timeout to the given value. |
void |
write(byte[] arr)
Writes the entire byte array arr to the serial port. |
void |
write(byte[] arr,
int offset,
int len)
Writes len bytes of array arr from offset to the serial port. |
void |
write(int value)
Writes the integer value to the serial port. |
| Methods inherited from class java.lang.Object |
equals,
hashCode,
toString |
SERIAL0
public static final int SERIAL0
- Serial port 0
SERIAL1
public static final int SERIAL1
- Serial port 1
COMMAND
public static final int COMMAND
- Deprecated.
- Command stream
STDIN
public static final int STDIN
- Standard in
STDOUT
public static final int STDOUT
- Standard out
STDERR
public static final int STDERR
- Standard error
GENERIC
public static final int GENERIC
- Deprecated.
- Generic stream
SPEED_300
public static final int SPEED_300
- Baud Rate 300 bps
SPEED_600
public static final int SPEED_600
- Baud Rate 600 bps
SPEED_1200
public static final int SPEED_1200
- Baud Rate 1200 bps
SPEED_2400
public static final int SPEED_2400
- Baud Rate 2400 bps
SPEED_4800
public static final int SPEED_4800
- Baud Rate 4800 bps
SPEED_9600
public static final int SPEED_9600
- Baud Rate 9600 bps
SPEED_19200
public static final int SPEED_19200
- Baud Rate 19200 bps
SPEED_38400
public static final int SPEED_38400
- Baud Rate 38400 bps
SPEED_57600
public static final int SPEED_57600
- Baud Rate 57600 bps
SPEED_115200
public static final int SPEED_115200
- Baud Rate 115200 bps
SERIALDEFAULTREADTIMEOUT
public static final int SERIALDEFAULTREADTIMEOUT
- Default serial port read timeout (not currently used)
SerialPort
public SerialPort(int portnum,
int stream)
throws java.io.IOException
- Constructs a new serial port object.
- Parameters:
portnum - - the serial port number that this should be associated with.stream - - the stream to open.- Throws:
- java.io.IOException -
- See Also:
open
public void open()
- Opens the serial port. This should not be called directly.
In the future, you will be able to use this method, but for now it is broken.
The port is opened by the input/otuput stream classes.
- Overrides:
- open in class CommPort
close
public void close()
throws java.io.IOException
- Close the serial port. This should not be called directly.
In the future, you will be able to use this method, but for now it is broken.
The port is closed by the input/otuput stream classes.
- Throws:
- java.io.IOException -
- Overrides:
- close in class CommPort
write
public void write(byte[] arr)
throws java.io.IOException
- Writes the entire byte array
arr to the serial port.
- Parameters:
arr - the array to be written to the serial port.- Throws:
- java.io.IOException -
write
public void write(byte[] arr,
int offset,
int len)
throws java.io.IOException
- Writes
len bytes of array arr from offset to the serial port.
- Parameters:
arr - the array to be written.offset - the offset in the array to begin sending.len - the number of bytes to send.- Throws:
- java.io.IOException -
write
public void write(int value)
throws java.io.IOException
- Writes the integer
value to the serial port.
- Parameters:
value - the integer to be written.- Throws:
- java.io.IOException -
read
public int read(byte[] arr,
int offset,
int len)
throws java.io.IOException
- Reads
len bytes of array arr from offset to the serial port.
- Parameters:
arr - the array for the data read to be placed in.offset - the offset to begin saving data.len - the number of bytes to read.- Throws:
- java.io.IOException -
read
public int read()
throws java.io.IOException
- Reads an integer from the serial port.
- Returns:
- the byte read.
- Throws:
- java.io.IOException -
getInputStream
public java.io.InputStream getInputStream()
throws java.io.IOException
- Gets the serial port input stream
- Returns:
- InputStream
- Throws:
- throws - IOException
- Overrides:
- getInputStream in class CommPort
getOutputStream
public java.io.OutputStream getOutputStream()
throws java.io.IOException
- Gets the serial port output stream
- Returns:
- OutputStream
- Throws:
- throws - IOException
- Overrides:
- getOutputStream in class CommPort
enableReceiveTimeout
public void enableReceiveTimeout()
throws UnsupportedCommOperationException
- enables the receive timeout - currently not implemented.
- Throws:
- UnsupportedCommOperationException -
- Overrides:
- enableReceiveTimeout in class CommPort
disableReceiveTimeout
public void disableReceiveTimeout()
throws UnsupportedCommOperationException
- disables the receive timeout. - currently not implemented.
Receive timeout is alway on.
- Throws:
- UnsupportedCommOperationException -
- Overrides:
- disableReceiveTimeout in class CommPort
setReceiveTimeout
public void setReceiveTimeout(int timeout)
throws UnsupportedCommOperationException
- sets the receive timeout to the given value.
- Parameters:
timeout - the value to delay before timeing out.- Throws:
- UnsupportedCommOperationException -
- Overrides:
- setReceiveTimeout in class CommPort
isReceiveTimeoutEnabled
public boolean isReceiveTimeoutEnabled()
- Returns true if the receive timeout is enabled.
currently always returns true.
- Returns:
- boolean true if receive timeout is enabled
- Overrides:
- isReceiveTimeoutEnabled in class CommPort
getInputBufferSize
public int getInputBufferSize()
- Gets the size of the input buffer. This method
currently returns 1 which is not necessarily the correct size.
- Returns:
- the size of the input buffer.
- Overrides:
- getInputBufferSize in class CommPort
getOutputBufferSize
public int getOutputBufferSize()
- Gets the size of the output buffer. This method
currently returns 1 which is not necessarily the correct size.
- Returns:
- the size of the output buffer.
- Overrides:
- getOutputBufferSize in class CommPort
setInputBufferSize
public void setInputBufferSize(int size)
throws UnsupportedCommOperationException
- Sets the size of the input buffer.
- Parameters:
size - the size of the input buffer.- Throws:
- UnsupportedCommOperationException - thrown if
the buffer cannot be resized.
- Overrides:
- setInputBufferSize in class CommPort
setOutputBufferSize
public void setOutputBufferSize(int size)
throws UnsupportedCommOperationException
- Sets the size of the output buffer.
- Parameters:
size - the size of the output buffer.- Throws:
- UnsupportedCommOperationException - thrown if
the output buffer cannot be resized.
- Overrides:
- setOutputBufferSize in class CommPort
setBaudRate
public void setBaudRate(int speed)
throws UnsupportedCommOperationException
- Sets the baud rate for the port.
- Parameters:
speed - use the static final ints- Throws:
- UnsupportedCommOperationException -
- See Also:
sendBreak
public void sendBreak(int timeMS)
- Sends a break on the serial port.
- Parameters:
timeMS - the duration of the break.- See Also:
available
public int available()
- Returns the number of bytes available on the port.
- Returns:
- the number of bytes available.
- See Also: