com.systronix.TINI_Serial
Class HandshakingEvents

com.systronix.TINI_Serial.HandshakingEvents

public class HandshakingEvents

Title: Handshaking Events Description: Test the DUART on SIMMSerial using events, This code actually uses a combination of events and a blocking read. This illustrates the point that TINI may not recieve as many events as bytes, try to packetize your information and read all available serial information in the serial event thread. Copyright: Copyright (c) 2001 Company: Systronix


Field Summary
static int BytesToTest
          BytesToTest is the packet size used in the current test.
private  boolean CountUp
          CountUp determines whether the output stream counts up from 0 or down from 255.
 boolean Done
          Done tells the reporting thread when the serial test is done so it can print out data.
private  int i
          a counting variable used to reduce space on the stack
private  java.io.InputStream in
          The input stream used to read data into RecieveData
private  int j
          a counting variable used to reduce space on the stack
 int num
          num does not neccesarily have to be a class variable anymore.
static int NumberOfPackets
          NumberOfPackets is the number of packets sent before a test passes.
private  java.io.OutputStream out
          The output stream used to write data from the buffers in TransmitData
 byte[] RecieveData
          This is where data is stored to be compared to what is transmitted.
private  javax.comm.SerialPort sp
          this instance variable is the serial port being used by this class.
static long StartTime
          StartTime is the time a packet was last read.
static int TimesThroughLoop
          TimesThroughLoop is a count of the number of packets actually sent through both serial ports.
 byte[][] TransmitData
          This is a byte array array so multiple patterns can be written out the serial port.
 
Constructor Summary
HandshakingEvents(javax.comm.SerialPort MyPort, boolean up)
          The constructor sets up the transmit and recieve buffers for the object.
 
Method Summary
 void Clear()
          Clears the requested uart so no residual erroneous data is sent or recieved.
protected  void finalize()
          This code is here because using version 1.02d of the tini tools, external serial ports did not close properly.
static void main(java.lang.String[] args)
          This version of main sets up event listeners on each serial port so that the user will be notified if a serial error occurs.
 void serialEvent(javax.comm.SerialPortEvent Ev)
          This is the event handler function.
 void TestHandShaking()
          TestHandShaking tests to make sure RTS and CTS both go up and down, as well as DTR and DSR.
 

Field Detail

sp

private javax.comm.SerialPort sp
this instance variable is the serial port being used by this class. The input and output streams to through this class.

CountUp

private boolean CountUp
CountUp determines whether the output stream counts up from 0 or down from 255. The basic test to see if there is a serial error is to add the input and output buffers together. They should equal 0xFF or 255.

StartTime

public static long StartTime
StartTime is the time a packet was last read. It is monitored by the main program to determine if serial data is actually being sent, or if the program has hung.

in

private java.io.InputStream in
The input stream used to read data into RecieveData

out

private java.io.OutputStream out
The output stream used to write data from the buffers in TransmitData

TransmitData

public byte[][] TransmitData
This is a byte array array so multiple patterns can be written out the serial port. This reduces the chances that a test will falsely pass because of old data in the recieve buffer.

RecieveData

public byte[] RecieveData
This is where data is stored to be compared to what is transmitted.

i

private int i
a counting variable used to reduce space on the stack

j

private int j
a counting variable used to reduce space on the stack

num

public int num
num does not neccesarily have to be a class variable anymore. It was meant to persist the number of bytes already read between events.

Done

public boolean Done
Done tells the reporting thread when the serial test is done so it can print out data.

TimesThroughLoop

public static int TimesThroughLoop
TimesThroughLoop is a count of the number of packets actually sent through both serial ports.

BytesToTest

public static final int BytesToTest
BytesToTest is the packet size used in the current test.

NumberOfPackets

public static final int NumberOfPackets
NumberOfPackets is the number of packets sent before a test passes.
Constructor Detail

HandshakingEvents

public HandshakingEvents(javax.comm.SerialPort MyPort,
                         boolean up)
The constructor sets up the transmit and recieve buffers for the object.
Parameters:
MyPort - is the serial port for this tester object to use.
up - determines whether the output stream will count up or down.
Method Detail

finalize

protected void finalize()
This code is here because using version 1.02d of the tini tools, external serial ports did not close properly. They do in 1.02e. If you have problems with port in use exceptions, do the following things:

Clear

public void Clear()
Clears the requested uart so no residual erroneous data is sent or recieved.

serialEvent

public void serialEvent(javax.comm.SerialPortEvent Ev)
This is the event handler function. HandshakingEvents is different from MultithreadBlockingRead because it uses events to wait for serial data instead of using a blocking read. Both tests test the serial handshaking lines to make sure they are set and reset when the calls through the api are made.

TestHandShaking

public void TestHandShaking()
TestHandShaking tests to make sure RTS and CTS both go up and down, as well as DTR and DSR. Note that DTR and RTS are outputs on both DTE and DCE serial ports and DSR and CTS are inputs on both DTE and DCE serial ports.

main

public static void main(java.lang.String[] args)
This version of main sets up event listeners on each serial port so that the user will be notified if a serial error occurs. It then monitors the status variables of each port and prints out a debugging message if the code has stopped, or if there was an error.