|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjcontrol.comm.RS232
public class RS232
Implements RS232 communication for JControl.
all |
Field Summary | |
---|---|
static int |
ECHO
Enables echo for received characters. |
static int |
FLOWCONTROL_RTSCTS
Enables hardware handshaking using RTS and CTS lines. |
static int |
FLOWCONTROL_XONXOFF
Enables software handshaking using XON and XOFF symbols. |
static int |
PARITY_EVEN
Enables even parity "8E1" (default: no parity "8N1"). |
static int |
PARITY_ODD
Enables odd parity "8O1" (default: no parity "8N1"). |
Fields inherited from interface jcontrol.comm.ConsoleOutputStream |
---|
STD_LF |
Fields inherited from interface jcontrol.comm.ConsoleInputStream |
---|
LF_CHARS |
Constructor Summary | |
---|---|
RS232()
Constructs a new RS232 I/O-stream using the default baudrate. |
|
RS232(int baudrate)
Constructs a new RS232 I/O-stream using the specified baudrate. |
Method Summary | |
---|---|
int |
available()
Returns the number of available characters in the input buffer. |
void |
close()
Closes the stream, further writes and reads are not possible, the RS232 hardware will be turned off. |
int |
errorCode()
Returns the current Error-Code. |
void |
print(String text)
Writes a String to the serial line. |
void |
println()
Writes a linefeed to the serial line. |
void |
println(String text)
Writes a String and a linefeed to the serial line. |
char |
read()
Reads the next available character from the input buffer. |
int |
read(byte[] buffer,
int index,
int length)
Reads a byte array from the input buffer. |
String |
readLine()
Reads a single String from the serial line. |
String |
readUTF8()
Reads a String from the serial line using Java coding with 2 size bytes first. |
void |
setBaudrate(int baudrate)
Sets the serial port baudrate. |
void |
setParams(int params)
Sets some serial port feature parameters. |
int |
write(byte[] buffer,
int index,
int length)
Writes a block of bytes to the serial port -- as it is. |
void |
write(char data)
Writes one byte to the serial port. |
void |
writeUTF8(String text)
Writes a String to the serial line using Java coding with 2 size bytes first. |
Methods inherited from class java.lang.Object |
---|
clone, equals, notifyAll, wait |
Field Detail |
---|
public static final int ECHO
setParams(int)
,
Constant Field Valuespublic static final int FLOWCONTROL_RTSCTS
RTS
and CTS
lines.
May be ignored on some devices. Do not use in conjunction with FLOWCONTROL_XONXOFF
.
setParams(int)
,
Constant Field Valuespublic static final int FLOWCONTROL_XONXOFF
XON
and XOFF
symbols.
Use only for ASCII based communication. Do not use in conjunction with FLOWCONTROL_RTSCTS
.
setParams(int)
,
Constant Field Valuespublic static final int PARITY_EVEN
PARITY_ODD
.
setParams(int)
,
PARITY_ODD
,
Constant Field Valuespublic static final int PARITY_ODD
PARITY_EVEN
.
setParams(int)
,
PARITY_EVEN
,
Constant Field ValuesConstructor Detail |
---|
public RS232() throws IOException
rs232.baudrate
".
IOException
- if port is in usepublic RS232(int baudrate) throws IOException
baudrate
- the bautrate to use, possible values are: 2400, 9600, 19200 (default), 31250,
63 (62500), 125 (125000), 250 (250000). This is controller dependent.
IOException
- if port is in usesetBaudrate(int)
Method Detail |
---|
public int available()
public void close()
close
in interface BasicInputStream
close
in interface BasicOutputStream
public int errorCode()
IOException
) the cause may be found here.
The Error-Code is cleared after readout (if not, the error remains active and every RS232 access will throw
another IOException
). If an overrun error is indicated the FIFO should be cleared using read(...)
.
readLine()
is waiting for a linefeed characterpublic void print(String text)
String
to the serial line. Unicode characters will not be decoded.
print
in interface ConsoleOutputStream
text
- String
to write, its temporary stored in heapString
public void println()
println
in interface ConsoleOutputStream
public void println(String text)
String
and a linefeed to the serial line. Unicode characters will not be decoded.
println
in interface ConsoleOutputStream
text
- String
to write, its temporary stored in heapString
public char read() throws IOException
read
in interface BasicInputStream
IOException
- if an error occursavailable()
public int read(byte[] buffer, int index, int length) throws IOException
read
in interface BasicInputStream
buffer
- the byte array to fillindex
- the index to start filling the arraylength
- number of bytes to read; the array is filled from index
to
index
+length
-1
IOException
- if an error occurspublic String readLine() throws IOException
String
from the serial line.
The String is received character-by-character until an linefeed character defined in ConsoleInputStream
is received. There is a buffer if size BUFFERSIZE
allocated to store the received bytes, if the buffer
is full a linefeed is forced.
readLine
in interface ConsoleInputStream
String
read
IOException
- if an error occursString
public String readUTF8() throws IOException
String
from the serial line using Java coding with 2 size bytes first.
readUTF8
in interface ComplexInputStream
String
IOException
- if an error occursString
public void setBaudrate(int baudrate)
baudrate
- the baudrate to use, possible values are:
Baudrate | Parameter |
600 | 600 |
1200 | 1200 |
2400 | 2400 |
4800 | 4800 |
9600 | 9600 |
19.200 | 19200 |
31.250 | 31250 |
38.400 | 38 |
62.500 | 62 |
125.000 | 125 |
250.000 | 250 |
Baudrate | Parameter |
300 | 300 |
600 | 600 |
1200 | 1200 |
2400 | 2400 |
4800 | 4800 |
9600 | 9600 |
19.200 | 19200 |
31.250 | 31250 |
62.500 | 62 |
125.000 | 125 |
250.000 | 250 |
rs232.baudrate
".public void setParams(int params)
rs232.params
".
params
- bitmask with parametersPARITY_EVEN
,
PARITY_ODD
,
ECHO
,
FLOWCONTROL_XONXOFF
,
FLOWCONTROL_RTSCTS
public int write(byte[] buffer, int index, int length) throws IOException
write
in interface BasicOutputStream
buffer
- the byte array to sendindex
- the index to start reading the arraylength
- number of bytes to write; the array is read from index
to
index
+length
-1
IOException
- if an error occurswrite(char c)
public void write(char data) throws IOException
write
in interface BasicOutputStream
data
- the byte to send (coded in a short allowing a range 0 ... 255)
IOException
- if an error occurswrite(byte[],int,int)
public void writeUTF8(String text) throws IOException
String
to the serial line using Java coding with 2 size bytes first.
writeUTF8
in interface ComplexOutputStream
text
- String
to write, its temporary stored in heap
IOException
- if an error occursString
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |