All Packages Class Hierarchy This Package Previous Next Index
Class com.bulletproof.io.SerialPort
java.lang.Object
|
+----com.bulletproof.io.SerialPort
- public class SerialPort
- extends Object
A class that includes a set of special functions
-
SerialPort(int, int)
-
Open a serial port with settings of 8 bits, no parity and 1 stop bit.
-
SerialPort(int, int, int, boolean, int)
-
-
close()
- Closes the port.
-
isOpen()
- Returns true if the port is open and false otherwise.
-
readBytes(byte[], int, int)
- Reads bytes from the port into a byte array.
-
readCheck()
- Returns the number of bytes currently available to be read from the
serial port's queue.
-
setFlowControl(boolean)
- Turns RTS/CTS flow control (hardware flow control) on or off.
-
setReadTimeout(int)
- Sets the timeout value for read operations.
-
writeBytes(byte[], int, int)
- Writes to the port.
SerialPort
public SerialPort(int number,
int baudRate,
int bits,
boolean parity,
int stopBits)
SerialPort
public SerialPort(int number,
int baudRate)
- Open a serial port with settings of 8 bits, no parity and 1 stop bit.
These are the most commonly used serial port settings.
close
public boolean close()
- Closes the port. Returns true if the operation is successful
and false otherwise.
isOpen
public boolean isOpen()
- Returns true if the port is open and false otherwise. This can
be used to check if opening the serial port was successful.
setFlowControl
public boolean setFlowControl(boolean on)
- Turns RTS/CTS flow control (hardware flow control) on or off.
- Parameters:
- on - pass true to set flow control on and false to set it off
setReadTimeout
public boolean setReadTimeout(int millis)
- Sets the timeout value for read operations. The value specifies
the number of milliseconds to wait from the time of last activity
before timing out a read operation. Passing a value of 0 sets
no timeout causing any read operation to return immediately with
or without data. The default timeout is 100 milliseconds. This
method returns true if successful and false if the value passed
is negative or the port is not open.
- Parameters:
- millis - timeout in milliseconds
readBytes
public int readBytes(byte buf[],
int start,
int count)
- Reads bytes from the port into a byte array. Returns the
number of bytes actually read or -1 if an error prevented the read
operation from occurring. The read will timeout if no activity
takes place within the timeout value for the port.
- Parameters:
- buf - the byte array to read data into
- start - the start position in the byte array
- count - the number of bytes to read
- See Also:
- setReadTimeout
readCheck
public int readCheck()
- Returns the number of bytes currently available to be read from the
serial port's queue. This method only works under PalmOS and not WinCE
due to limitations in the Win32 CE API. Under Win32 and Java,
this method will always return -1.
writeBytes
public int writeBytes(byte buf[],
int start,
int count)
- Writes to the port. Returns the number of bytes written or -1
if an error prevented the write operation from occurring. If data
can't be written to the port and flow control is on, the write
operation will time out and fail after approximately 2 seconds.
- Parameters:
- buf - the byte array to write data from
- start - the start position in the byte array
- count - the number of bytes to write
All Packages Class Hierarchy This Package Previous Next Index