|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--serial.Serial
The Serial class is designed to control serial devices. This is the base class for all serial devices we use.
Field Summary | |
protected int |
answerTimeout
|
protected boolean |
cancelEcho
|
protected String |
device
|
protected javax.comm.SerialPortEventListener |
listener
|
protected Semaphore |
semaphore
|
protected javax.comm.SerialPort |
serial
|
protected BufferedReader |
serial_in
|
protected OutputStream |
serial_out
|
protected int |
timeout_wait
|
protected boolean |
waitingForResponse
|
Constructor Summary | |
Serial()
|
Method Summary | |
boolean |
addEventListener(javax.comm.SerialPortEventListener lsnr)
Allows you to add a listener that will listen on the stuff comming from the serial port |
void |
close()
Closes the port. |
static Serial |
getNewInstance()
This method is here so that children of this class can override it so that main() calls appropriate constructor |
static void |
main(String[] args)
Used for standalone debugging and hardware tests. |
void |
open(String in_device)
|
void |
open(String sInDevice,
int iSpeed,
int iDatabits,
int iStopbits,
int iParity)
Opens a com port. |
void |
open(String sInDevice,
int iSpeed,
int iDatabits,
int iStopbits,
int iParity,
int iFlowControl)
Opens a com port. |
void |
openNoParams(String in_device)
I cannot remember why I added this method but it should not be used - KZG |
protected boolean |
processSerialEvent(javax.comm.SerialPortEvent spe)
This method can be overriden in classes that extend this one. |
int |
read()
Reads a byte from the buffer (if nothing to read, returns EOF) |
byte[] |
readBytes()
like readString but returns an array of bytes |
String |
readString()
This method will read everything that is currently available in the buffer and return it as a string |
boolean |
ready()
Tells you if there is any data waiting to be fetched from the buffer |
void |
send(byte[] cmd)
Sends your message down the serial port |
void |
send(String cmd)
|
String |
sendSynch(byte[] cmd,
int timeout,
boolean force)
this method will send your command to the serial port and wait for a response from the serial port and pass this response back to you. |
String |
sendSynch(String cmd)
|
String |
sendSynch(String cmd,
int timeout,
boolean force)
|
void |
serialEvent(javax.comm.SerialPortEvent spe)
This method is called from the serial port controller when there is a serial port event |
void |
setFlowControlMode(int f)
|
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
protected String device
protected javax.comm.SerialPort serial
protected OutputStream serial_out
protected BufferedReader serial_in
protected int timeout_wait
protected javax.comm.SerialPortEventListener listener
protected int answerTimeout
protected boolean waitingForResponse
protected boolean cancelEcho
protected Semaphore semaphore
Constructor Detail |
public Serial()
Method Detail |
public void open(String in_device) throws javax.comm.NoSuchPortException, javax.comm.PortInUseException, IOException
in_device
- the name of the serial device to speak
to. Uses standard port settings. (e.g. "/dev/term/ttyrg" DONT
FORGET ABOUT TERM)public void open(String sInDevice, int iSpeed, int iDatabits, int iStopbits, int iParity) throws javax.comm.NoSuchPortException, javax.comm.PortInUseException, IOException
sInDevice
- a String
valueiSpeed
- an int
valueiDatabits
- an int
valueiStopbits
- an int
valueiParity
- an int
valuepublic void open(String sInDevice, int iSpeed, int iDatabits, int iStopbits, int iParity, int iFlowControl) throws javax.comm.NoSuchPortException, javax.comm.PortInUseException, IOException
sInDevice
- a String
valueiSpeed
- an int
valueiDatabits
- an int
valueiStopbits
- an int
valueiParity
- an int
valueiFlowControl
- an int
valuepublic void openNoParams(String in_device) throws javax.comm.NoSuchPortException, javax.comm.PortInUseException, IOException
public void setFlowControlMode(int f)
public void send(byte[] cmd) throws IOException
cmd[]
- bytes you want to send down the linepublic void send(String cmd) throws IOException
public String sendSynch(byte[] cmd, int timeout, boolean force) throws IOException
cmd
- the commandtimeout
- the timeout (in milliseconds -- how long to wait
if there is no response)force
- if force is true, this method will always wait for
full length of timeout and return everything that was said
during that time; otherwise, this method may return earlier,
the moment it gets its first response from the serial portpublic String sendSynch(String cmd, int timeout, boolean force) throws IOException
public String sendSynch(String cmd) throws IOException
public void close() throws IOException
public boolean ready()
public int read()
public String readString()
public byte[] readBytes()
public boolean addEventListener(javax.comm.SerialPortEventListener lsnr)
public void serialEvent(javax.comm.SerialPortEvent spe)
spe
- a SerialPortEvent
valueprotected boolean processSerialEvent(javax.comm.SerialPortEvent spe)
public static Serial getNewInstance()
public static void main(String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |