Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## jcontrol.comm
Class UART

    java.lang.Object
      jcontrol.comm.UART

All Implemented Interfaces:
  BasicInputStream, BasicOutputStream

Direct Known Subclasses:
  RS232

    public class UART

extends Object
implements BasicInputStream, BasicOutputStream

Access to UART-Ports of Device

Field Summary
`static int` | `PARAMS_ECHO` Enables echo for received characters.
`static int` | `PARAMS_FLOWCONTROL_RTSCTS` Enables hardware handshaking using `RTS` and `CTS` lines.
`static int` | `PARAMS_FLOWCONTROL_XONXOFF` Enables software handshaking using `XON` and `XOFF` symbols.
`static int` | `PARAMS_MULTIDROP_ADDRESS` Enables address multidrop mode.
`static int` | `PARAMS_MULTIDROP_DATA` Enables data multidrop mode.
`static int` | `PARAMS_PARITY_EVEN` Enables even parity "8E1" (default: no parity "8N1").
`static int` | `PARAMS_PARITY_MASK` There can only exists one of the 4 parity-types PARAMS_PARITY_EVEN, PARAMS_PARITY_ODD, PARAMS_MULTIDROP_ADDRESS and PARAMS_MULTIDROP_DATA.
`static int` | `PARAMS_PARITY_ODD` Enables odd parity "8O1" (default: no parity "8N1").
`static int` | `PORT_RS232_0` port declaration: rs232_0 existing on all JControl-Devices
`static int` | `PORT_RS232_1` port declaration: rs232_1 existing on JControl/BFT-Device
`static int` | `PORT_RS232_2` port declaration: rs232_2 for future purposes
`static int` | `PORT_RS232_3` port declaration: rs232_3 for future purposes
`static int` | `PORT_RS422_0` port declaration: rs422_0 existing on JControl/BFT-Device
`static int` | `PORT_RS422_1` port declaration: rs422_1 for future purposes
`static int` | `PORT_RS422_2` port declaration: rs422_2 for future purposes
`static int` | `PORT_RS422_3` port declaration: rs422_3 for future purposes

Constructor Summary
`UART(int port)` Constructor

Method Summary
`int` | `available()` Returns the number of available characters in the input buffer.
`void` | `close()` Closes the stream, further writes and reads are not possible, the RS232 hardware will be turned off.
`int` | `errorCode()` Returns the current Error-Code.
`void` | `flush()` flush unsent bytes (if exists)
`int` | `getBaudrate()` Gets the current Baudrate of Device
`int` | `getParams()` Gets some serail port feature parameters.
`void` | `mark(int readlimit)` NOTE: not supported!
`boolean` | `markSupported()` NOTE: not supported!
`int` | `read()` Reads the next available character from the input buffer.
`int` | `read(byte[] b)` Reads some number of bytes from the input stream and stores them into the buffer array `b`.
`int` | `read(byte[] buffer, int startindex, int length)` Reads a byte array from the input buffer.
`void` | `reset()` NOTE: not supported!
`void` | `setBaudrate(int baudrate)` Sets the serial port baudrate.
`void` | `setCharacterGuardTime(int bits)` Sets the character guard time, i.e. the time to wait between sending two characters over the serial port.
`void` | `setParams(int params)` Sets some serial port feature parameters.
`int` | `skip(int n)` skips n bytes of reading characters
`void` | `write(byte[] b)` Writes `b.length` bytes from the specified byte array to this output stream.
`void` | `write(byte[] buffer, int startindex, int length)` Writes a block of bytes to the serial port -- as it is.
`void` | `write(int b)` Writes one byte to the serial port.

Methods inherited from class java.lang.Object
`clone, equals, getClass, notifyAll, toString, wait`

Field Detail

### PARAMS_PARITY_MASK

    public static final int PARAMS_PARITY_MASK

  There can only exists one of the 4 parity-types PARAMS_PARITY_EVEN, PARAMS_PARITY_ODD, PARAMS_MULTIDROP_ADDRESS and PARAMS_MULTIDROP_DATA. Mask the params by PARAMS_PARITY_MASK to get the int-value of parity type.

  See Also:
    Constant Field Values

### PARAMS_PARITY_EVEN

    public static final int PARAMS_PARITY_EVEN

  Enables even parity "8E1" (default: no parity "8N1"). Do not use in conjunction with `PARITY_ODD,PARAMS_MULTIDROP_ADDRESS,PARAMS_MULTIDROP_DATA`.

  See Also:
    `setParams(int)`, `#PARITY_ODD`, `PARAMS_MULTIDROP_ADDRESS`, `PARAMS_MULTIDROP_DATA`, Constant Field Values

### PARAMS_PARITY_ODD

    public static final int PARAMS_PARITY_ODD

  Enables odd parity "8O1" (default: no parity "8N1"). Do not use in conjunction with `PARITY_EVEN,PARAMS_MULTIDROP_ADDRESS,PARAMS_MULTIDROP_DATA`.

  See Also:
    `setParams(int)`, `#PARITY_EVEN`, `PARAMS_MULTIDROP_ADDRESS`, `PARAMS_MULTIDROP_DATA`, Constant Field Values

### PARAMS_MULTIDROP_ADDRESS

    public static final int PARAMS_MULTIDROP_ADDRESS

  Enables address multidrop mode. Do not use in conjunction with `PARAMS_PARITY_EVEN,PARAMS_PARITY_ODD,PARAMS_MULTIDROP_DATA`. In multidrop mode during receiving the character type (data/address) is ignored and can't identified.

  See Also:
    `setParams(int)`, `#PARITY_EVEN`, `#PARITY_ODD`, `PARAMS_MULTIDROP_DATA`, Constant Field Values

### PARAMS_MULTIDROP_DATA

    public static final int PARAMS_MULTIDROP_DATA

  Enables data multidrop mode. Do not use in conjunction with `PARAMS_PARITY_EVEN,PARAMS_PARITY_ODD,PARAMS_MULTIDROP_ADDRESS`. In multidrop mode during receiving the character type (data/address) is ignored and can't identified.

  See Also:
    `setParams(int)`, `#PARITY_EVEN`, `#PARITY_ODD`, `PARAMS_MULTIDROP_ADDRESS`, Constant Field Values

### PARAMS_ECHO

    public static final int PARAMS_ECHO

  Enables echo for received characters.

  See Also:
    `setParams(int)`, Constant Field Values

### PARAMS_FLOWCONTROL_XONXOFF

    public static final int PARAMS_FLOWCONTROL_XONXOFF

  Enables software handshaking using `XON` and `XOFF` symbols. Use only for ASCII based communication. Do not use in conjunction with `FLOWCONTROL_RTSCTS`.

  See Also:
    `setParams(int)`, Constant Field Values

### PARAMS_FLOWCONTROL_RTSCTS

    public static final int PARAMS_FLOWCONTROL_RTSCTS

  Enables hardware handshaking using `RTS` and `CTS` lines. May be ignored on some devices. Do not use in conjunction with `FLOWCONTROL_XONXOFF`.

  See Also:
    `setParams(int)`, Constant Field Values

### PORT_RS232_0

    public static final int PORT_RS232_0

  port declaration: rs232_0
  existing on all JControl-Devices

  See Also:
    Constant Field Values

### PORT_RS232_1

    public static final int PORT_RS232_1

  port declaration: rs232_1
  existing on JControl/BFT-Device

  See Also:
    Constant Field Values

### PORT_RS232_2

    public static final int PORT_RS232_2

  port declaration: rs232_2
  for future purposes

  See Also:
    Constant Field Values

### PORT_RS232_3

    public static final int PORT_RS232_3

  port declaration: rs232_3
  for future purposes

  See Also:
    Constant Field Values

### PORT_RS422_0

    public static final int PORT_RS422_0

  port declaration: rs422_0
  existing on JControl/BFT-Device

  See Also:
    Constant Field Values

### PORT_RS422_1

    public static final int PORT_RS422_1

  port declaration: rs422_1
  for future purposes

  See Also:
    Constant Field Values

### PORT_RS422_2

    public static final int PORT_RS422_2

  port declaration: rs422_2
  for future purposes

  See Also:
    Constant Field Values

### PORT_RS422_3

    public static final int PORT_RS422_3

  port declaration: rs422_3
  for future purposes

  See Also:
    Constant Field Values

Constructor Detail

### UART

    public UART(int port)
         throws IOException

  Constructor

  Throws:
    `IOException`

Method Detail

### available

    public int available()
                  throws IOException

  Returns the number of available characters in the input buffer.

  Specified by:
    `available` in interface `BasicInputStream`
  Returns:
    the number of available chars
  Throws:
    `IOException` - if an error occurs

### read

    public int read()
             throws IOException

  Reads the next available character from the input buffer. This method blocks until a character is available.

  Specified by:
    `read` in interface `BasicInputStream`
  Returns:
    the read out character
  Throws:
    `IOException` - if an error occurs
  See Also:
    `available()`

### read

    public int read(byte[] buffer,
                    int startindex,
                    int length)
             throws IOException

  Reads a byte array from the input buffer.

  Specified by:
    `read` in interface `BasicInputStream`
  Parameters:
    `buffer` - the byte array to fill
    `index` - the index to start filling the array
    `length` - number of bytes to read; the array is filled from `index` to `index`+`length`-1
  Returns:
    the number of bytes read
  Throws:
    `IOException` - if an error occurs
  See Also:
    `InputStream.read()`

### read

    public int read(byte[] b)
             throws IOException

  Description copied from interface: `BasicInputStream`
  Reads some number of bytes from the input stream and stores them into the buffer array `b`. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.

  If `b` is `null`, a `NullPointerException` is thrown. If the length of `b` is zero, then no bytes are read and `0` is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value `-1` is returned; otherwise, at least one byte is read and stored into `b`.

  The first byte read is stored into element `b[0]`, the next one into `b[1]`, and so on. The number of bytes read is, at most, equal to the length of `b`. Let k be the number of bytes actually read; these bytes will be stored in elements `b[0]` through `b[`k`-1]`, leaving elements `b[`k`]` through `b[b.length-1]` unaffected.

  If the first byte cannot be read for any reason other than end of file, then an `IOException` is thrown. In particular, an `IOException` is thrown if the input stream has been closed.

  The `read(b)` method for class `InputStream` has the same effect as:

       read(b, 0, b.length)

  Specified by:
    `read` in interface `BasicInputStream`
  Parameters:
    `b` - the buffer into which the data is read.
  Returns:
    the total number of bytes read into the buffer, or `-1` is there is no more data because the end of the stream has been reached.
  Throws:
    `IOException` - if an I/O error occurs.
  See Also:
    `read(byte[] buffer, int startindex, int length)`

### write

    public void write(int b)
               throws IOException

  Writes one byte to the serial port. The unicode character is trucated to one byte.

  Specified by:
    `write` in interface `BasicOutputStream`
  Parameters:
    `data` - the byte to send (coded in a short allowing a range 0 ... 255)
  Throws:
    `IOException` - if an I/O error occurs. In particular, an `IOException` may be thrown if the output stream has been closed.
  See Also:
    `write(byte[],int,int)`

### write

    public void write(byte[] buffer,
                      int startindex,
                      int length)
               throws IOException

  Writes a block of bytes to the serial port -- as it is.

  Specified by:
    `write` in interface `BasicOutputStream`
  Parameters:
    `buffer` - the byte array to send
    `index` - the index to start reading the array
    `length` - number of bytes to write; the array is read from `index` to `index`+`length`-1
  Throws:
    `IOException` - if an I/O error occurs. In particular, an `IOException` is thrown if the output stream is closed.

### write

    public void write(byte[] b)
               throws IOException

  Description copied from interface: `BasicOutputStream`
  Writes `b.length` bytes from the specified byte array to this output stream. The general contract for `write(b)` is that it should have exactly the same effect as the call `write(b, 0, b.length)`.

  Specified by:
    `write` in interface `BasicOutputStream`
  Parameters:
    `b` - the data.
  Throws:
    `IOException` - if an I/O error occurs.
  See Also:
    `write(byte[] buffer, int startindex, int length)`

### close

    public void close()

  Closes the stream, further writes and reads are not possible, the RS232 hardware will be turned off.

  Specified by:
    `close` in interface `BasicInputStream`
  Specified by:
    `close` in interface `BasicOutputStream`

### setBaudrate

    public void setBaudrate(int baudrate)

  Sets the serial port baudrate. This is controller dependent.

  Parameters:
    `baudrate` - the baudrate to use, possible values are:

    Baudrates for JControl/Gimlin(16Bit)
    Baudrate | Parameter
    600 | 600
    1200 | 1200
    2400 | 2400
    4800 | 4800
    9600 | 9600
    19.200 | 19200
    31.250 | 31250
    38.400 | 38
    62.500 | 62
    125.000 | 125
    250.000 | 250

    Baudrates for JControl/Gimlin (32Bit)
    Baudrate | Parameter
    300 | 300
    600 | 600
    1200 | 1200
    2400 | 2400
    4800 | 4800
    9600 | 9600
    19.200 | 19200
    31.250 | 31250
    62.500 | 62500
    125.000 | 125000
    250.000 | 250000

    Defaults to the value specified by the system property "``rs232.baudrate``".

### getBaudrate

    public int getBaudrate()

  Gets the current Baudrate of Device

  Returns:
    baudrate

### setParams

    public void setParams(int params)

  Sets some serial port feature parameters. Defaults to the value specified by the system property "``rs232.params``".

  Parameters:
    `params` - bitmask with parameters
  See Also:
    `#PARITY_EVEN`, `#PARITY_ODD`, `#ECHO`, `#FLOWCONTROL_XONXOFF`, `#FLOWCONTROL_RTSCTS`

### getParams

    public int getParams()

  Gets some serail port feature parameters.

  Returns:

### errorCode

    public int errorCode()

  Returns the current Error-Code. If an error occurs (`IOException`) the cause may be found here. The Error-Code is cleared after readout (if not, the error remains active and every RS232 access will throw another `IOException`). If an overrun error is indicated the FIFO should be cleared using `read(...)`.

  Returns:
    the error code (the values ar or-ed together):
    1 -- Parity error
    2 -- Framing error
    8 -- UART overrun error
    16 -- FIFO buffer overrun
    Additionally there are some information flags (not cleared):
    4 -- sndXOFF, remembers last sent XOFF state
    32 -- recAbortLF, set if an `readLine()` is waiting for a linefeed character
    64 -- recXOFF, remembers last received XOFF state
    128 -- Inactive, set if the port is closed.

### setCharacterGuardTime

    public void setCharacterGuardTime(int bits)

  Sets the character guard time, i.e. the time to wait between sending two characters over the serial port. Note that this value does not change the timeout, so on altering the character guard time, the application has to take care of adjusting the timeout appropriately (i.e. if guard time is set to 8, the timeout must be approximately doubled, as communication speed is cut down by 50%.

  Parameters:
    `bits` - minimum bits to wait between two characters

### skip

    public int skip(int n)
             throws IOException

  skips n bytes of reading characters

  Specified by:
    `skip` in interface `BasicInputStream`
  Parameters:
    `n` - the number of bytes to skip
  Returns:
    the count of bytes that was skip'ed
  Throws:
    `IOException` - if an I/O error occurs.

### flush

    public void flush()
               throws IOException

  flush unsent bytes (if exists)

  Specified by:
    `flush` in interface `BasicOutputStream`
  Throws:
    `IOException` - if an I/O error occurs.

### mark

    public void mark(int readlimit)

  NOTE: not supported!

  Specified by:
    `mark` in interface `BasicInputStream`
  Parameters:
    `readlimit` - the maximum limit of bytes that can be read before the mark position becomes invalid.

### markSupported

    public boolean markSupported()

  NOTE: not supported!

  Specified by:
    `markSupported` in interface `BasicInputStream`
  Returns:
    `true` if this stream instance supports the mark and reset methods; `false` otherwise.

### reset

    public void reset()
               throws IOException

  NOTE: not supported!

  Specified by:
    `reset` in interface `BasicInputStream`
  Throws:
    `IOException` - if this stream has not been makred or if the mark has been invalidated.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD