Class SerialEchoEvent

SerialEchoEvent

public class SerialEchoEvent

Simple SerialEcho example, using javaxcomm.
This program receives serial data on any JStamp/JStik/SaJe com port RXD line, echos it back out the same com port TXD line, and prints the hex value and ASCII char in Charade.
This is a good basic serial I/O test program.


What you need:
You need a JStamp/JStik/SaJe system, serial cable, and a PC with any common terminal program (to communicate with your target system). You also need the Systronix Util package, used for the toHex display here: #echo
Serial cables:
Remember that a PC is wired as DTE and so are the JStamp development station and SaJe. JStik can be either DTE or DCE depending on the serial adapters. Between the PC and another DTE connector you will need a null modem.
Details:
This class implements SerialPortEventListener in order to receive the DataAvailable event.
Using this example
  1. Change baud rate or com port values in initializeSerialPort()
  2. Be sure you have the right configuration in JemBuilder and you have the correct Project->Drivers installed (com1, com2, com3 as needed).
  3. On TINI with SBX2, CS1 is where the 550 UART is addressed, so use something like: public static final int SBX2CS1 = 0x380080; // SBX2 UART in TINI address space This will be TINI's "serial2"
  4. Remember that the 16C552 has its serialA at the *higher* address than serialB, this can be confusing.


Field Summary
static com.dalsemi.system.DataPort dp
          This DataPort is used to print out and set the stretch cycles on serial ports and is also used to probe UART register values.
protected  java.io.InputStream inStream
          reference to the serial input stream
protected  java.io.OutputStream outStream
          reference to the serial output stream
static int PortAddress
          PortAddress is the actual address of the port to be used for the serial port in this project.
static byte rcvVal
          Last byte read from a serial port
static int SBX2
          This constant is the hardware address of sbx2 serial port on TINI
static int SimmSerialA
          This constant is the hardware address of SimmSerial port A on TINI
static int SimmSerialB
          This constant is the hardware address of SimmSerial port B on TINI
static int whichport
          whichport is the port number on TINI.
 
Constructor Summary
SerialEchoEvent()
           
 
Method Summary
 void blockThread()
          method to block a thread This lets the main routine do nothin.
 void initializeSerialPort()
          Method to initialize the serial port and set up the input and output streams - this is where you change the baud rate and com port.
static void main(java.lang.String[] args)
          Instantiate our class then wait this thread.
 void serialEvent(javax.comm.SerialPortEvent ev)
          Javax.comm will call this method whenever a Data Available event occurs On serial ports without hardware flow control this is the only event supported.
static void setExtUartTiming2()
          This is a native method declaration.
 

Field Detail

inStream

protected java.io.InputStream inStream
reference to the serial input stream

outStream

protected java.io.OutputStream outStream
reference to the serial output stream

SimmSerialA

public static final int SimmSerialA
This constant is the hardware address of SimmSerial port A on TINI

SimmSerialB

public static final int SimmSerialB
This constant is the hardware address of SimmSerial port B on TINI

SBX2

public static final int SBX2
This constant is the hardware address of sbx2 serial port on TINI

PortAddress

public static int PortAddress
PortAddress is the actual address of the port to be used for the serial port in this project. Its default value is SimmSerialA and it is later set to SimmSerialB so both serial ports on SimmSerial can be listened to at once.

dp

public static com.dalsemi.system.DataPort dp
This DataPort is used to print out and set the stretch cycles on serial ports and is also used to probe UART register values.

whichport

public static int whichport
whichport is the port number on TINI. For internal uarts, this number is either 0 or 1. For external uarts, it is 2 or 3.

rcvVal

public static byte rcvVal
Last byte read from a serial port
Constructor Detail

SerialEchoEvent

public SerialEchoEvent()
Method Detail

setExtUartTiming2

public static void setExtUartTiming2()
This is a native method declaration. This native method is used to add more stretch cycles for I/O for use with SBX2 serial ports.

serialEvent

public void serialEvent(javax.comm.SerialPortEvent ev)
Javax.comm will call this method whenever a Data Available event occurs On serial ports without hardware flow control this is the only event supported. This means the onboard UARTs of JStamp/JStik/SaJe

initializeSerialPort

public void initializeSerialPort()
Method to initialize the serial port and set up the input and output streams - this is where you change the baud rate and com port. If it is unable to aquire the serial port, the program will exit. It demonstrates serial input and output streams using javax.comm. It also registers this class as a listener for the data available events with Javax.comm.
Parameters:
none, - but edit the source code here to change com port and baud rate.
On JStamp, SaJe and JStik, the onboard serial ports are "com1" and "com2". With SaJe, "com3" is available on the SBX2 expansion board.
On TINI the uarts are serial0, serial1, serial2 and serial3.
Returns:
nothing if successful. Uses System.exit to bail out brutally if unable to properly configure. There's really no place to which we can exit so this will in turn result in an aJile runtime exception.

main

public static void main(java.lang.String[] args)
Instantiate our class then wait this thread. All the action then occurs in the serial event handler.

blockThread

public void blockThread()
method to block a thread This lets the main routine do nothin. Serial events will then be received and handled