com.systronix.TINI_Serial
Class MultithreadBlockingRead

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--com.systronix.TINI_Serial.MultithreadBlockingRead
All Implemented Interfaces:
java.lang.Runnable

public class MultithreadBlockingRead
extends java.lang.Thread

Title: SimmSerial Test Program #1 Description: Test the DUART on SIMMSerial using a blocking read Copyright: Copyright (c) 2001 Company: Systronix


Field Summary
static int BaudRate
          This is the baud rate of the serial port.
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 k
          a counting variable used to reduce space on the stack k is used to select a transmit buffer to be transmitted.
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
private static int PortNum
          PortNum keeps track of which port number is to be initialized for external serial ports.
 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 helps main detect overflows.
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.
 
Fields inherited from class java.lang.Thread
contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ
 
Constructor Summary
MultithreadBlockingRead(javax.comm.SerialPort MyPort, boolean up)
          The constructor sets up the transmit and recieve buffers for the object.
 
Method Summary
 void Clear()
          flushes the input and output ports for the serial port so no false data is read or written.
protected  void finalize()
          This code is here because using version 1.02d of the tini tools, external serial ports did not close properly.
static javax.comm.SerialPort InitializeExternalSerialPort(java.lang.String portName)
          This function sets up external serial ports before they are actually initialized using javax.comm.
static javax.comm.SerialPort InitializeInternalSerialPort(int PortNum)
          InitializeInternalSerialPort initializes the internal TINI serial port, or an external port that has already been set up in the TINI OS.
static void main(java.lang.String[] args)
          This version of main starts to child threads running, one for each serial port.
 void run()
          This version of the serial tester program uses a blocking read to wait for input data before more output data is transmitted.
 void TestHandShaking()
          TestHandShaking tests to make sure RTS and CTS both go up and down, as well as DTR and DSR.
 
Methods inherited from class java.lang.Thread
, activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, exit, getContextClassLoader, getName, getPriority, getThreadGroup, init, interrupt, interrupt0, interrupted, isAlive, isDaemon, isInterrupted, isInterrupted, join, join, join, nextThreadNum, registerNatives, resume, resume0, setContextClassLoader, setDaemon, setName, setPriority, setPriority0, sleep, sleep, start, stop, stop, stop0, suspend, suspend0, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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.

BaudRate

public static final int BaudRate
This is the baud rate of the serial port. Possible values are standard serial port values.

StartTime

public static long StartTime
StartTime helps main detect overflows. Every time a serial packet is read, StartTime reads in the current time from System#currentTimeMillis if the code goes too long without reading a packet of data, the system prints out the number of packets read along with the current input and output buffers for both serial ports being tested.

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

k

public int k
a counting variable used to reduce space on the stack k is used to select a transmit buffer to be transmitted.

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.

PortNum

private static int PortNum
PortNum keeps track of which port number is to be initialized for external serial ports. It must start on number 2 and then move to number three, whether serialA is initialized first or serialB is.
Constructor Detail

MultithreadBlockingRead

public MultithreadBlockingRead(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()
flushes the input and output ports for the serial port so no false data is read or written.

run

public void run()
This version of the serial tester program uses a blocking read to wait for input data before more output data is transmitted. The basic structure is a three threaded program, a thread for each serial port and a thread to monitor the serial transmissions. Each serial thread writes data to its output stream and than waits for data to be recieved on the input stream. Both tests test the serial handshaking lines to make sure they are set and reset when the calls through the api are made.
Overrides:
run in class java.lang.Thread

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 starts to child threads running, one for each serial port. 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.

InitializeExternalSerialPort

public static javax.comm.SerialPort InitializeExternalSerialPort(java.lang.String portName)
This function sets up external serial ports before they are actually initialized using javax.comm. The hardware address of the external ports must be set up in the Tini OS before they can be used.
Parameters:
portName - is the name of the external serial port being initialized. These names match the labels on SimmSerial, serialA and SerialB are the possible parameters.

InitializeInternalSerialPort

public static javax.comm.SerialPort InitializeInternalSerialPort(int PortNum)
InitializeInternalSerialPort initializes the internal TINI serial port, or an external port that has already been set up in the TINI OS. Users should call InitializeExternalSerialPort(java.lang.String) to initialize a simmserial external serial port.
Parameters:
PortNum
  • 0 - is TINI internal UART 0. To use this port, call "downserver -s" from the TINI shell command prompt to stop the shell from using port 0.
  • 1 is TINI internal UART 1. This port cannot be used with one wire. Check the state of JP4 before attempting to use UART 1.
  • 2 is a SimmSerial port. Use InitializeExternalSerialPort(java.lang.String) to initialize SimmSerial
  • 3 is a SimmSerial port. Use InitializeExternalSerialPort(java.lang.String) to initialize SimmSerial