jSyncManager

org.jSyncManager.JSerial
Class SerialPeer

java.lang.Object
  extended byorg.jSyncManager.JSerial.SerialPeer

public class SerialPeer
extends java.lang.Object

A class to define native code headers for accessing a serial port in Java. This class will provide the native code headers for accessing serial ports under Java. Note that normally a programmer should not directly utilize this class - all functionality is available through the org.jSyncManager.JSerialInterface class.

Version:
$Revision: 1.2 $
Author:
Brad BARCLAY <bbarclay@jsyncmanager.org>
Last modified by: $Author: yaztromo $ on $Date: 2003/11/20 17:50:58 $.

Field Summary
static java.lang.String NOPORT
           
static java.lang.String PORTUNAVAILABLE
           
 
Constructor Summary
SerialPeer(byte port)
          The peer constructor.
 
Method Summary
 boolean checkPort(byte port)
          A method to check if the requested port exists on this machine.
 int getChar()
          Gets the next available character from the incoming serial stream.
 int getDataBits()
          A method to retreive the current databit setting.
 boolean getDSRDTRState()
          Queries the state of the DSR/DTR handshaking.
 int getParity()
          A method to retreive the current parity setting.
static java.lang.String getPlatformName()
          A static method to return the name of the platform for which a working native code library has been installed.
 byte getPort()
          A method to return the ID value of the current port.
 boolean getRTSCTSState()
          Queries the state of the RTS/CTS handshaking.
 int getSpeed()
          A method to get the currently set serial speed.
 int getStopBits()
          A method to retreive the current stopbit setting.
static java.lang.String getVersion()
          A static method to return the version number of the installed native code implementation.
 boolean getXONXOFFState()
          Queries the state of the XON/XOFF handshaking.
 void grabPort()
          Native method to gain exclusive access to a serial port.
 boolean portStatus()
          A method to determine wether or not the current port is in the "grabbed" state.
 void putChar(int b)
          Puts a character into the outgoing serial stream.
 void releasePort()
          A method to release control of the serial port to the underlying OS.
 void setDataBits(int databits)
          Sets the number of Data Bits per transmission byte.
 void setDSRDTR(boolean state)
          A method to set the state of the DSR/DTR handshaking.
 void setParity(int parity)
          Sets the Parity bit type used for each transmission unit.
 void setRTSCTS(boolean state)
          A method to set the state of the RTS/CTS handshaking.
 void setSpeed(int speed)
          Native method to set the speed for the serial port.
 void setStopBits(int stopbits)
          Sets the number of Stop Bits per transmission unit.
 void setXONXOFF(boolean state)
          A method to set the state of the XON/XOFF handshaking.
 void startBreak()
          Starts transmitting a break signal.
 void stopBreak()
          Stop transmission of a break signal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOPORT

public static final java.lang.String NOPORT

PORTUNAVAILABLE

public static final java.lang.String PORTUNAVAILABLE
Constructor Detail

SerialPeer

public SerialPeer(byte port)
           throws SerialInitializationException
The peer constructor.

Parameters:
port - the port ID number for this serial peer.
Throws:
SerialInitializationException - thrown if the port requested does not exist.
Method Detail

grabPort

public void grabPort()
              throws SerialGrabException
Native method to gain exclusive access to a serial port.

Throws:
SerialGrabException - thrown if the port cannot be grabbed by this process.

setSpeed

public void setSpeed(int speed)
              throws SerialSpeedException
Native method to set the speed for the serial port.

Parameters:
speed - a valid speed setting.
Throws:
SerialSpeedException - thrown if the given speed is invalid, or not supported.

setDataBits

public void setDataBits(int databits)
                 throws SerialDataBitException
Sets the number of Data Bits per transmission byte.

Parameters:
databits - the desired number of data bits per transmission byte.
Throws:
SerialDataBitException - thrown if the specified value is invalid or unsupported.

setParity

public void setParity(int parity)
               throws SerialParityException
Sets the Parity bit type used for each transmission unit.

Parameters:
parity - a value representing the parity type.
Throws:
SerialParityException - thrown if the given parity is invalid or unsupported.

setStopBits

public void setStopBits(int stopbits)
                 throws SerialStopBitException
Sets the number of Stop Bits per transmission unit.

Parameters:
stopbits - the number of stop bits per transmission unit.
Throws:
SerialStopBitException - thrown if the value specified is invalid or unsupported.

getChar

public int getChar()
            throws java.io.IOException
Gets the next available character from the incoming serial stream.

Returns:
an integer representing a character value from 0 - 255, or -1 if no character is available.
Throws:
java.io.IOException - thrown if an IOException occurs while attempting to read the serial port.

putChar

public void putChar(int b)
             throws java.io.IOException
Puts a character into the outgoing serial stream.

Parameters:
b - a character value between 0 - 255.
Throws:
java.io.IOException - thrown if an IOException occurs while attempting to read the serial port.

getPlatformName

public static java.lang.String getPlatformName()
A static method to return the name of the platform for which a working native code library has been installed.

Returns:
a String representing the name of the platform.

getVersion

public static java.lang.String getVersion()
A static method to return the version number of the installed native code implementation.

Returns:
a strong representing major_version.minor_version.

getPort

public byte getPort()
A method to return the ID value of the current port.

Returns:
a byte representing the port ID.

getSpeed

public int getSpeed()
A method to get the currently set serial speed.

Returns:
the current serial speed for the current port.

getDataBits

public int getDataBits()
A method to retreive the current databit setting.

Returns:
the current data bit size per byte for the current port.

getParity

public int getParity()
A method to retreive the current parity setting.

Returns:
the current parity type for the current port.

getStopBits

public int getStopBits()
A method to retreive the current stopbit setting.

Returns:
the current stop bit size per byte for the current port.

releasePort

public void releasePort()
                 throws SerialReleaseException
A method to release control of the serial port to the underlying OS.

Throws:
SerialReleaseException - thrown if the port cannot be released.

portStatus

public boolean portStatus()
A method to determine wether or not the current port is in the "grabbed" state.

Returns:
the "grab" status - true if the port is released, false otherwise.

checkPort

public boolean checkPort(byte port)
A method to check if the requested port exists on this machine.

Returns:
wether or not this port is supported - true if the port exists, false otherwise.

setRTSCTS

public void setRTSCTS(boolean state)
               throws SerialHandshakingException
A method to set the state of the RTS/CTS handshaking. Sets the state of RTS/CTS hardware handshaking.

Parameters:
state - if true, enables RTS/CTS hardware handshaking.
Throws:
SerialHandshakingException - thrown if the serial driver is unable to change modes.

setDSRDTR

public void setDSRDTR(boolean state)
               throws SerialHandshakingException
A method to set the state of the DSR/DTR handshaking. Sets the state of DSR/DTR hardware handshaking.

Parameters:
state - if true, enables hardware handshaking.
Throws:
SerialHandshakingException - thrown if the serial driver is unable to change modes.

setXONXOFF

public void setXONXOFF(boolean state)
                throws SerialHandshakingException
A method to set the state of the XON/XOFF handshaking. Sets the state of XON/XOFF software handshaking. Note that this function will set both the transmit and receive to use XON/XOFF control.

Parameters:
state - if true, enables software handshaking.
Throws:
SerialHandshakingException - thrown if the serial driver is unable to change modes.

startBreak

public void startBreak()
Starts transmitting a break signal.


stopBreak

public void stopBreak()
Stop transmission of a break signal.


getRTSCTSState

public boolean getRTSCTSState()
Queries the state of the RTS/CTS handshaking.

Returns:
true if RTS/CTS is enabled.

getDSRDTRState

public boolean getDSRDTRState()
Queries the state of the DSR/DTR handshaking.

Returns:
true if DSR/DTR is enabled.

getXONXOFFState

public boolean getXONXOFFState()
Queries the state of the XON/XOFF handshaking.

Returns:
true if XON/XOFF is enabled.

jSyncManager

Copyright (c) 1998 - 2003 Brad BARCLAY and others. All Rights Reserved.