dsnserver
Class RXTXComm

java.lang.Object
  extended by dsnserver.RXTXComm
All Implemented Interfaces:
Communication

public class RXTXComm
extends java.lang.Object
implements Communication

It is used for the communication with the BTnode over the serial port.

Author:
kaltt

Field Summary
private  int baudrate
           
protected static java.lang.String defaultLogFile
           
private  java.io.InputStream is
           
private  java.io.OutputStream os
           
 java.io.PrintStream out
           
private  gnu.io.SerialPort port
           
 gnu.io.CommPortIdentifier portId
           
private  java.lang.String portName
           
private  java.util.concurrent.Semaphore sem
           
private static java.util.concurrent.Semaphore sem_file
           
 
Constructor Summary
RXTXComm()
           
 
Method Summary
 void close()
          To close a connection.
 void deleteLog()
           
protected  void finalize()
           
 void lock()
           
 void open(java.lang.String Name)
          To open a connection to a special Socket.
 java.lang.String readLine()
           
 java.lang.String readLine(long timeout)
          To read a line on the com-port The function is reading until a "\n" is identify a line end or the time timeout is over
protected  void showPorts()
          to show Ports
Ports found:
- Name: COM1
- String: gnu.io.CommPortIdentifier@56a499
- PortType: 1
- Hash: 5678233
- owner: null
- Name: COM2
- ...
 void unlock()
           
 void writeLine(java.lang.String command)
          To write a line on the com-port It has to be safed with a semaphre.
static void writeLog(java.lang.String s)
           
static void writeLog(java.lang.String f, java.lang.String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

portId

public gnu.io.CommPortIdentifier portId

port

private gnu.io.SerialPort port

portName

private java.lang.String portName

baudrate

private int baudrate

is

private java.io.InputStream is

os

private java.io.OutputStream os

out

public java.io.PrintStream out

defaultLogFile

protected static java.lang.String defaultLogFile

sem

private java.util.concurrent.Semaphore sem

sem_file

private static java.util.concurrent.Semaphore sem_file
Constructor Detail

RXTXComm

public RXTXComm()
Method Detail

finalize

protected void finalize()
Overrides:
finalize in class java.lang.Object

open

public void open(java.lang.String Name)
To open a connection to a special Socket. Create a InputStream (is) and a OutputStream (os) For example with the COM3 Seriel-Connection portName = "COM3"

Specified by:
open in interface Communication
Parameters:
String - Name

close

public void close()
To close a connection.

Specified by:
close in interface Communication

showPorts

protected void showPorts()
to show Ports
Ports found:
- Name: COM1
- String: gnu.io.CommPortIdentifier@56a499
- PortType: 1
- Hash: 5678233
- owner: null
- Name: COM2
- ...


readLine

public java.lang.String readLine(long timeout)
To read a line on the com-port The function is reading until a "\n" is identify a line end or the time timeout is over

Parameters:
long - timeout (in milliseconds) the function is reading timeout milliseconds on the port before it gives back the result excepting a line was ending with a /n.
Returns:
String line the line which was read on the port

readLine

public java.lang.String readLine()
Specified by:
readLine in interface Communication

writeLine

public void writeLine(java.lang.String command)
To write a line on the com-port It has to be safed with a semaphre. For this you can use before the writeLine command the command lock() and after unlock().

Specified by:
writeLine in interface Communication
Parameters:
String - command the command wich is written to the port to the BTnode.

writeLog

public static void writeLog(java.lang.String s)
                     throws java.io.IOException
Throws:
java.io.IOException

writeLog

public static void writeLog(java.lang.String f,
                            java.lang.String s)
                     throws java.io.IOException
Throws:
java.io.IOException

deleteLog

public void deleteLog()
Specified by:
deleteLog in interface Communication

lock

public void lock()
Specified by:
lock in interface Communication

unlock

public void unlock()
Specified by:
unlock in interface Communication