com.dalsemi.comm
Class LCDPort

java.lang.Object
  |
  +--com.dalsemi.comm.LCDPort

public class LCDPort
extends java.lang.Object

A class to write to a LCD display. This class was written and tested using the KS0066U and KS0070B segment drivers/controller. The class can be used as part of a streams based protocol. There are also methods for communicating directly to the LCD display. Using the sendControl and sendData commands you can control the LCD directly without the need for streams.


Field Summary
static int COMMAND
           
static int GENERIC
           
static int LCD_DRIVER
          PortNumber
static int LCDDEFAULTREADTIMEOUT
           
static int PARAM_COMMANDTABLE
           
static int STDERR
           
static int STDOUT
           
 
Constructor Summary
LCDPort(int portNum, int stream)
          Constructs a new LCDPort.
 
Method Summary
 int available()
          returns the number of bytes available on the port.
 void close()
          Closes the port and frees up system resources.
 void disableReceiveTimeout()
          disables the receive timeout.
 void enableReceiveTimeout()
          enables the receive timeout - currently not implemented.
 int getInputBufferSize()
          gets the size of the input buffer.
 java.io.InputStream getInputStream()
          gets a LCD port Input stream
 int getOutputBufferSize()
          gets the size of the output buffer.
 java.io.OutputStream getOutputStream()
          gets a LCD port Output stream
 boolean isReceiveTimeoutEnabled()
          returns true if the receive timeout is enabled.
 void open()
          opens the LCD port for communication.
 int read()
          read from the LCD port.
 int read(byte[] arr, int offset, int len)
          read from the LCD port.
static void sendControl(int value)
          Sends a control byte to the LCD display.
static void sendData(int value)
          Sends a data byte to the display.
static void setAddress(int address)
          Set the address for the next write.
 void setInputBufferSize(int size)
          sets the size of the input buffer.
static void setLCDParams(int paramNum, byte[] params, int length)
          Sends a parameter to the LCD display.
static void setNumberOfLines(int num)
          Sets the number of lines for the LCD driver.
 void setOutputBufferSize(int size)
          sets the size of the output buffer.
 void setReceiveTimeout(int timeout)
          sets the receive timeout to the given value.
static void setShiftDirection(boolean dir)
          Sets the direction of shifts.
static void setShiftInterval(int num_ms)
          Set the interval of the automatic shift.
static void setShiftMode(boolean on)
          Turns automatic shifting on and off.
 void write(byte[] arr)
          Writes the array to the LCD port.
 void write(byte[] arr, int offset, int len)
          writes the given array to the LCD port.
 void write(int ch)
          Writes a byte to the LCD port.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LCD_DRIVER

public static final int LCD_DRIVER
PortNumber

COMMAND

public static final int COMMAND

STDOUT

public static final int STDOUT

STDERR

public static final int STDERR

GENERIC

public static final int GENERIC

LCDDEFAULTREADTIMEOUT

public static final int LCDDEFAULTREADTIMEOUT

PARAM_COMMANDTABLE

public static final int PARAM_COMMANDTABLE
Constructor Detail

LCDPort

public LCDPort(int portNum,
               int stream)
        throws java.io.IOException
Constructs a new LCDPort.
Parameters:
portNum - - the port number of the driver. Should be LCD_DRIVER
stream - - the stream to open. Only stdout is supported.
Method Detail

setLCDParams

public static void setLCDParams(int paramNum,
                                byte[] params,
                                int length)
Sends a parameter to the LCD display. The only parameter currently supported is number of lines. This should be used to let the underlying driver know how many lines it should support. Valid line numbers supported are 1,2,4 Example: set number of lines to 1 byte[] b1 = {0x01}; LCDPort.setLCDParams(1, b1, b1.length);
Parameters:
paramNum - - parameter number (only 1 is supported)
params - - the parameter values
length - - the length of the parameter array.

open

public void open()
opens the LCD port for communication. This method is called from getInputStream and getOutputStream.

close

public void close()
           throws java.io.IOException
Closes the port and frees up system resources.

write

public void write(byte[] arr)
           throws java.io.IOException
Writes the array to the LCD port. The bytes will be written sequentially.
Parameters:
arr - - the array to be written to the LCD port.
Throws:
- - IOException

write

public void write(byte[] arr,
                  int offset,
                  int len)
           throws java.io.IOException
writes the given array to the LCD port.
Parameters:
arr - - the array to be written.
offset - - the offset in the array to begin sending.
len - - the number of bytes to send.

write

public void write(int ch)
           throws java.io.IOException
Writes a byte to the LCD port.
Parameters:
ch - - the data to be written.
Throws:
java.io.IOException -  

read

public int read(byte[] arr,
                int offset,
                int len)
         throws java.io.IOException
read from the LCD port.
Parameters:
arr - - the array for the data read to be placed in.
offset - - the offset to begin saving data.
len - - the number of bytes to read.
Throws:
java.io.IOException -  

read

public int read()
         throws java.io.IOException
read from the LCD port.
Returns:
the byte read.
Throws:
java.io.IOException -  

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
gets a LCD port Input stream
Returns:
InputStream
Throws:
throws - IOException

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
gets a LCD port Output stream
Returns:
OutputStream
Throws:
throws - IOException

enableReceiveTimeout

public void enableReceiveTimeout()
                          throws UnsupportedCommOperationException
enables the receive timeout - currently not implemented.
Throws:
UnsupportedCommOperationException -  

disableReceiveTimeout

public void disableReceiveTimeout()
                           throws UnsupportedCommOperationException
disables the receive timeout. - currently not implemented. Receive timeout is alway on.
Throws:
UnsupportedCommOperationException -  

setReceiveTimeout

public void setReceiveTimeout(int timeout)
                       throws UnsupportedCommOperationException
sets the receive timeout to the given value.
Parameters:
timeout - - the value to delay before timeing out.
Throws:
UnsupportedCommOperationException -  

isReceiveTimeoutEnabled

public boolean isReceiveTimeoutEnabled()
returns true if the receive timeout is enabled. currently always returns false.
Returns:
boolean true if receive timeout is enabled

getInputBufferSize

public int getInputBufferSize()
gets the size of the input buffer.

getOutputBufferSize

public int getOutputBufferSize()
gets the size of the output buffer.
Returns:
int - the size of the output buffer.

setInputBufferSize

public void setInputBufferSize(int size)
                        throws UnsupportedCommOperationException
sets the size of the input buffer.
Parameters:
size - - the size of the input buffer.
Throws:
UnsupportedCommOperationException - - thrown if the buffer cannot be resized.

setOutputBufferSize

public void setOutputBufferSize(int size)
                         throws UnsupportedCommOperationException
sets the size of the output buffer.
Parameters:
size - - the size of the output buffer.
Throws:
UnsupportedCommOperationException - - thrown if the output buffer cannot be resized.

available

public int available()
returns the number of bytes available on the port.
Returns:
- the number of bytes available.

setNumberOfLines

public static void setNumberOfLines(int num)
Sets the number of lines for the LCD driver.
Parameters:
num - - number of lines.

sendControl

public static void sendControl(int value)
Sends a control byte to the LCD display. Refer to the data sheets of the KS0066U and KS0070B for information on control characters. This can be used to set the address, shift, clear, etc.
Parameters:
value - - the control value to be sent.

sendData

public static void sendData(int value)
Sends a data byte to the display. This can be used to directly read and write data to the LCD display.
Parameters:
value - - the byte to be displayed.

setShiftMode

public static void setShiftMode(boolean on)
Turns automatic shifting on and off.
Parameters:
on - - true turns shifting on.

setShiftDirection

public static void setShiftDirection(boolean dir)
Sets the direction of shifts.
Parameters:
dir - - true = left

setShiftInterval

public static void setShiftInterval(int num_ms)
Set the interval of the automatic shift.
Parameters:
num_ms - - number of milliseconds between shifts.

setAddress

public static void setAddress(int address)
Set the address for the next write.
Parameters:
address - - the address.