www.rkjava.de

de.rkjava.serial.j3964r
Class J3964R

java.lang.Object
  extended byjava.lang.Thread
      extended byde.rkjava.serial.j3964r.J3964R
All Implemented Interfaces:
EventListener, Runnable, javax.comm.SerialPortEventListener

public class J3964R
extends Thread
implements javax.comm.SerialPortEventListener

With a instance of J3964R you can send data in form of a byte array and register your J3964RListener to be informed about incoming data.

You can send data with the call of sendData(Byte[]). The data will be stored automatically in a queue, so no transmission will be lost.

Example for a transmission:

       J3964R my3964R = null;
       try {
         my3964R = new J3964R("COM1",9600);  //Thread starts automatically, no start() necessary
       } catch (javax.comm.PortInUseException e) {...};
       my3964R.trace = true;         // switch the trace on
       Byte[] bytes = new Byte[10];  // prepare data for send
       bytes[0] = new Byte((byte)0x00);      bytes[1] = new Byte((byte)0x00);
       bytes[2] = new Byte((byte)0x45);      bytes[3] = new Byte((byte)0x44);
       bytes[4] = new Byte((byte)0x64);      bytes[5] = new Byte((byte)0x00);
       bytes[6] = new Byte((byte)0x00);      bytes[7] = new Byte((byte)0x05);
       bytes[8] = new Byte((byte)0xFF);      bytes[9] = new Byte((byte)0x2F);
       my3964R.sendData(bytes);      // send data
       {...};
       my3964R.close();              // close the interface and interrupts this Thread
 
The handling of incoming data is managed automatically, therefore every instance of J3964R is a Thread. Every J3964RListener will be informed about about new incoming data and if a transmission was successful or unsuccessfull. Just register a J3964RListener by my3964R with addJ3964RListener(J3964RListener).

Author:
Gerd Limbeck, www.rkjava.de

Field Summary
static byte DLE
          0x10
static byte ETX
          0x03
static byte NAK
          0x15
static long QVZ
          acknowledgement delay time
Defaultvalue: 2000ms.
static long RVZ
          response dalay time
Defaultvalue: 3000ms.
static byte STX
          0x02
static boolean STXafterNAK
          The 3964R specification is not clear: Therefore two possibilities for "STXafterNAK"
Defaultvalue: true.
static boolean trace
          Defaultvalue: false.
static long ZVZ
          character delay time
Defaultvalue: 180ms.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
J3964R(String portName, int baudrate)
          Creates and starts an object of this class
It can exchange data via specified serial interface with 3964R protocol.
J3964R(String portName, int baudrate, int databit, int stopbit, int parity)
          Creates and starts an object of this class
It can exchange data via specified serial interface with 3964R protocol.
J3964R(String portName, int baudrate, J3964RListener listener)
          Creates and starts an object of this class
It can exchange data via specified serial interface with 3964R protocol.
 
Method Summary
 void addJ3964RListener(J3964RListener listener)
          Adds a J3964RListener
static String byte2Hex(byte theByte)
          gives you a byte as a HEX-View
 void close()
          closing the connection.
static Enumeration getPortNames()
          The systems provided interfaces
 int getSpeed()
          Gets the baudrate
 void removeJ3964RListener(J3964RListener listener)
          Removes a J3964RListener.
 void run()
          Don't use run() or start(), the Thread starts automatically within the constructor!
 void sendData(Byte[] byteObjects)
          Sends the data with 3964R-protocol to the serial interface.
 void sendData(Byte[] byteObjects, J3964RNextInDataListener listener)
          Sends the data with 3964R-protocol to the serial interface
The J3964RNextInDataListener will be informed about the next incoming data one time.
 void serialEvent(javax.comm.SerialPortEvent serialPortEvent)
          Don't use this method
It will be use by javax.comm.SerialPortEventListener
 void setSpeed(int baudrate)
          Sets the baudrate
 void setSpeed(int baudrate, int databit, int stopbit, int parity)
          Sets the baudrate
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STX

public static final byte STX
0x02

See Also:
Constant Field Values

DLE

public static final byte DLE
0x10

See Also:
Constant Field Values

ETX

public static final byte ETX
0x03

See Also:
Constant Field Values

NAK

public static final byte NAK
0x15

See Also:
Constant Field Values

QVZ

public static long QVZ
acknowledgement delay time
Defaultvalue: 2000ms.


ZVZ

public static long ZVZ
character delay time
Defaultvalue: 180ms.


RVZ

public static long RVZ
response dalay time
Defaultvalue: 3000ms.


STXafterNAK

public static boolean STXafterNAK
The 3964R specification is not clear: Therefore two possibilities for "STXafterNAK"
Defaultvalue: true.


trace

public static boolean trace
Defaultvalue: false.

Constructor Detail

J3964R

public J3964R(String portName,
              int baudrate,
              int databit,
              int stopbit,
              int parity)
       throws javax.comm.PortInUseException
Creates and starts an object of this class
It can exchange data via specified serial interface with 3964R protocol.

Parameters:
portName - Name of the serial interface.
baudrate - Speed of the serial interface
databit - value from Sun's Communication API 2.0
stopbit - value from Sun's Communication API 2.0
parity - value from Sun's Communication API 2.0
Throws:
javax.comm.PortInUseException - Sun's Communication API 2.0
See Also:
getPortNames()

J3964R

public J3964R(String portName,
              int baudrate)
       throws javax.comm.PortInUseException
Creates and starts an object of this class
It can exchange data via specified serial interface with 3964R protocol.

Parameters:
portName - Name of the serial interface.
baudrate - Speed of the serial interface
Throws:
javax.comm.PortInUseException - Sun's Communication API 2.0
See Also:
getPortNames()

J3964R

public J3964R(String portName,
              int baudrate,
              J3964RListener listener)
       throws javax.comm.PortInUseException
Creates and starts an object of this class
It can exchange data via specified serial interface with 3964R protocol.

Parameters:
portName - Name of the serial interface.
baudrate - Speed of the serial interface
listener - a J3964RListener
Throws:
javax.comm.PortInUseException - Sun's Communication API 2.0
See Also:
getPortNames()
Method Detail

close

public void close()
closing the connection.
If you don't need the object anymore, close the conection to the serial interface with this close()


getSpeed

public int getSpeed()
Gets the baudrate

Returns:
the baudrate
See Also:
setSpeed(int)

setSpeed

public void setSpeed(int baudrate)
              throws javax.comm.UnsupportedCommOperationException
Sets the baudrate

Parameters:
baudrate - e.g. 9600
Throws:
javax.comm.UnsupportedCommOperationException - Sun's Communication API 2.0

setSpeed

public void setSpeed(int baudrate,
                     int databit,
                     int stopbit,
                     int parity)
              throws javax.comm.UnsupportedCommOperationException
Sets the baudrate

Parameters:
baudrate - e.g. z.B. 9600
databit - value from Sun's Communication API 2.0
stopbit - value from Sun's Communication API 2.0
parity - value from Sun's Communication API 2.0
Throws:
javax.comm.UnsupportedCommOperationException - Sun's Communication API 2.0

run

public void run()
Don't use run() or start(), the Thread starts automatically within the constructor!

Specified by:
run in interface Runnable
See Also:
above mentioned example

serialEvent

public void serialEvent(javax.comm.SerialPortEvent serialPortEvent)
Don't use this method
It will be use by javax.comm.SerialPortEventListener

Specified by:
serialEvent in interface javax.comm.SerialPortEventListener
Parameters:
serialPortEvent - a SerialPortEvent

addJ3964RListener

public void addJ3964RListener(J3964RListener listener)
Adds a J3964RListener

Parameters:
listener - the J3964RListener

removeJ3964RListener

public void removeJ3964RListener(J3964RListener listener)
Removes a J3964RListener.

Parameters:
listener - the J3964RListener

sendData

public void sendData(Byte[] byteObjects)
Sends the data with 3964R-protocol to the serial interface.

Parameters:
byteObjects - the bytes for the transmission

sendData

public void sendData(Byte[] byteObjects,
                     J3964RNextInDataListener listener)
Sends the data with 3964R-protocol to the serial interface
The J3964RNextInDataListener will be informed about the next incoming data one time. So it is possible to react of the next incoming telegram after sending this data.

Parameters:
byteObjects - the bytes for the transmission
listener - the J3964RNextInDataListener

getPortNames

public static Enumeration getPortNames()
The systems provided interfaces

Returns:
The Enumeration contains the names of the interfaces as Strings.

byte2Hex

public static String byte2Hex(byte theByte)
gives you a byte as a HEX-View

Parameters:
theByte - the Byte
Returns:
the byte as a HEX-View

www.rkjava.de