com.meiglobal.ebds.api
Class EBDS_SerialPort

java.lang.Object
  extended by com.meiglobal.ebds.api.WrappedSerialPort
      extended by com.meiglobal.ebds.api.EBDS_SerialPort
All Implemented Interfaces:
gnu.io.SerialPortEventListener, java.util.EventListener

public class EBDS_SerialPort
extends WrappedSerialPort

Specialized class to handle EBDS communications down a serial port. Uses the custom WrappedSerialPort class to communicate with the device.


Field Summary
static byte ETX
           
static byte STX
           
 
Fields inherited from class com.meiglobal.ebds.api.WrappedSerialPort
_buffer, _iRead, _iWrite, _strPortName
 
Constructor Summary
EBDS_SerialPort(Acceptor acceptor)
          Constructor.
 
Method Summary
protected  byte calcCRC(byte[] b)
          Calculates the CRC of a byte array.
 boolean getReplyAcked(byte[] reply)
          Informs if a received reply has been acknowledged.
 byte[] receive()
          Receives information from the device.
 void resetPort()
          Attempts to reset the port by closing and re-opening.
 void sendData(byte[] data)
          Sends data to the device.
 
Methods inherited from class com.meiglobal.ebds.api.WrappedSerialPort
close, flushInputStream, isOpen, listPorts, openPort, send, serialEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STX

public static final byte STX
See Also:
Constant Field Values

ETX

public static final byte ETX
See Also:
Constant Field Values
Constructor Detail

EBDS_SerialPort

public EBDS_SerialPort(Acceptor acceptor)
Constructor.

Parameters:
acceptor - The Acceptor object that will use this serial port.
Method Detail

resetPort

public void resetPort()
Attempts to reset the port by closing and re-opening. This function call will consume (but log) any exceptions.


sendData

public void sendData(byte[] data)
              throws AcceptorException,
                     java.io.IOException
Sends data to the device.

Parameters:
data - The data to be sent.
Throws:
AcceptorException - If message payload is null
java.io.IOException - If there is a problem with the serial port

receive

public byte[] receive()
               throws AcceptorException,
                      SerialReadTimeout
Receives information from the device.

Returns:
A byte array containing the received data.
Throws:
AcceptorException - If an error occurs.
SerialReadTimeout - If a reply is not received in a timely manner.

getReplyAcked

public boolean getReplyAcked(byte[] reply)
Informs if a received reply has been acknowledged.

Parameters:
reply - The byte array reply to check.
Returns:
True if it is ACKed. False if NAKed.

calcCRC

protected byte calcCRC(byte[] b)
Calculates the CRC of a byte array.

Parameters:
b - The byte array.
Returns:
The result of the calculation.