com.sun.comm
Class LinuxParallel

java.lang.Object
  extended byjavax.comm.CommPort
      extended byjavax.comm.ParallelPort
          extended bycom.sun.comm.LinuxParallel

class LinuxParallel
extends ParallelPort


Nested Class Summary
(package private)  class LinuxParallel.LPInputStream
           
(package private)  class LinuxParallel.LPOutputStream
           
 
Field Summary
private  int framing_byte
           
private  int ibuffer_size
           
private  LinuxParallel.LPInputStream inputStream
           
private  ParallelPortEventListener listener
           
static int LPT_MODE_ANY
           
static int LPT_MODE_ECP
           
static int LPT_MODE_EPP
           
static int LPT_MODE_PS2
           
static int LPT_MODE_SPP
           
private  int notificationMask
           
private static int NOTIFY_BUF
           
private static int NOTIFY_ERR
           
private  int obuffer_size
           
private  LinuxParallel.LPOutputStream outputStream
           
private  int port_fd
           
private  int port_mode
           
private  int rcv_threshold
           
private  int rcv_timeout
           
private static int STATUS_PaperOut
           
private static int STATUS_PrtBusy
           
private static int STATUS_PrtError
           
private static int STATUS_PrtSelected
           
private static int STATUS_PrtTimedOut
           
 
Fields inherited from class javax.comm.ParallelPort
LPT_MODE_NIBBLE
 
Fields inherited from class javax.comm.CommPort
name
 
Constructor Summary
LinuxParallel(java.lang.String theName)
           
 
Method Summary
 void addEventListener(ParallelPortEventListener lsnr)
          Registers a ParallelPortEventListener object for ParallelPortEvents.
 void close()
          Closes the communications port.
 void disableReceiveFraming()
          Disables receive framing.
 void disableReceiveThreshold()
          Disables receive threshold.
 void disableReceiveTimeout()
          Disables receive timeout.
 void enableReceiveFraming(int framingByte)
          Enables receive framing, if this feature is supported by the driver.
 void enableReceiveThreshold(int thresh)
          Enables receive threshold, if this feature is supported by the driver.
 void enableReceiveTimeout(int rcvTimeout)
          Enables receive timeout, if this feature is supported by the driver.
 int getInputBufferSize()
          Gets the input buffer size.
 java.io.InputStream getInputStream()
          Returns an input stream.
 int getMode()
          Gets the currently configured mode.
 int getOutputBufferFree()
          Gets the number of bytes available in the output buffer.
 int getOutputBufferSize()
          Gets the output buffer size.
 java.io.OutputStream getOutputStream()
          Returns an output stream.
 int getReceiveFramingByte()
          Gets the current byte used for receive framing.
 int getReceiveThreshold()
          Gets the integer value of the receive threshold.
 int getReceiveTimeout()
          Gets the integer value of the receive timeout.
 boolean isPaperOut()
          Checks if the port is indicating an "Out of Paper" state.
 boolean isPrinterBusy()
          Checks if the port is indicating a "Printer Busy" state.
 boolean isPrinterError()
          Checks if the printer has encountered an error.
 boolean isPrinterSelected()
          Checks if the printer is in selected state.
 boolean isPrinterTimedOut()
          Checks if the printer has timed out.
 boolean isReceiveFramingEnabled()
          Checks if receive framing is enabled.
 boolean isReceiveThresholdEnabled()
          Checks if receive threshold is enabled.
 boolean isReceiveTimeoutEnabled()
          Checks if receive timeout is enabled.
private  int nativeAvailable(int port_fd)
           
private  void nativeClosePort(int port_fd)
           
private  boolean nativeGetStatusFlags(int port_fd, int flag)
           
private  int nativeOpenPort(java.lang.String port_name)
           
private  int nativeRead(int port_fd, byte[] buf, int offset, int len)
           
private  byte nativeReadByte(int port_fd)
           
private  void nativeSetTimeout(int port_fd, int timeout)
           
 int nativeWrite(int port_fd, byte[] buf, int offset, int len)
           
 void notifyOnBuffer(boolean enable)
          Expresses interest in being notified when the output buffer is empty.
 void notifyOnError(boolean enable)
          Expresses interest in being notified of port errors.
private  void raiseEvent(int notify_bit, boolean oldvalue, boolean newvalue)
           
 void removeEventListener()
          Deregisters event listener registered using addEventListener.
 void restart()
          Restarts output after an error.
 void setInputBufferSize(int size)
          Sets the input buffer size.
 int setMode(int mode)
          Sets the printer port mode.
 void setOutputBufferSize(int size)
          Sets the output buffer size.
 void suspend()
          Suspends output.
 
Methods inherited from class javax.comm.CommPort
getName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

port_mode

private int port_mode

port_fd

private int port_fd

rcv_timeout

private int rcv_timeout

rcv_threshold

private int rcv_threshold

framing_byte

private int framing_byte

ibuffer_size

private int ibuffer_size

obuffer_size

private int obuffer_size

LPT_MODE_ANY

public static final int LPT_MODE_ANY
See Also:
Constant Field Values

LPT_MODE_SPP

public static final int LPT_MODE_SPP
See Also:
Constant Field Values

LPT_MODE_PS2

public static final int LPT_MODE_PS2
See Also:
Constant Field Values

LPT_MODE_EPP

public static final int LPT_MODE_EPP
See Also:
Constant Field Values

LPT_MODE_ECP

public static final int LPT_MODE_ECP
See Also:
Constant Field Values

STATUS_PaperOut

private static final int STATUS_PaperOut
See Also:
Constant Field Values

STATUS_PrtBusy

private static final int STATUS_PrtBusy
See Also:
Constant Field Values

STATUS_PrtSelected

private static final int STATUS_PrtSelected
See Also:
Constant Field Values

STATUS_PrtTimedOut

private static final int STATUS_PrtTimedOut
See Also:
Constant Field Values

STATUS_PrtError

private static final int STATUS_PrtError
See Also:
Constant Field Values

listener

private ParallelPortEventListener listener

inputStream

private LinuxParallel.LPInputStream inputStream

outputStream

private LinuxParallel.LPOutputStream outputStream

notificationMask

private int notificationMask

NOTIFY_ERR

private static final int NOTIFY_ERR
See Also:
Constant Field Values

NOTIFY_BUF

private static final int NOTIFY_BUF
See Also:
Constant Field Values
Constructor Detail

LinuxParallel

public LinuxParallel(java.lang.String theName)
              throws java.io.IOException
Method Detail

nativeOpenPort

private int nativeOpenPort(java.lang.String port_name)
                    throws java.io.IOException
Throws:
java.io.IOException

getOutputBufferFree

public int getOutputBufferFree()
Description copied from class: ParallelPort
Gets the number of bytes available in the output buffer.

Specified by:
getOutputBufferFree in class ParallelPort
Returns:
integer value corresponding to the number of bytes available in the output buffer

setMode

public int setMode(int mode)
            throws UnsupportedCommOperationException
Description copied from class: ParallelPort
Sets the printer port mode.

Specified by:
setMode in class ParallelPort
Parameters:
mode - one of LPT_MODE_ANY, LPT_MODE_SPP, LPT_MODE_PS2, LPT_MODE_EPP, or LPT_MODE_ECP

Throws:
UnsupportedCommOperationException - is thrown if the mode is not supported by the underline driver.

getMode

public int getMode()
Description copied from class: ParallelPort
Gets the currently configured mode.

Specified by:
getMode in class ParallelPort
Returns:
mode returned is one of LPT_MODE_SPP, LPT_MODE_PS2, LPT_MODE_EPP, or LPT_MODE_ECP

suspend

public void suspend()
Description copied from class: ParallelPort
Suspends output.

Specified by:
suspend in class ParallelPort

restart

public void restart()
Description copied from class: ParallelPort
Restarts output after an error.

Specified by:
restart in class ParallelPort

nativeGetStatusFlags

private boolean nativeGetStatusFlags(int port_fd,
                                     int flag)

isPaperOut

public boolean isPaperOut()
Description copied from class: ParallelPort
Checks if the port is indicating an "Out of Paper" state.

Specified by:
isPaperOut in class ParallelPort
Returns:
true if printer has run out of paper, false if printer does not report "Out of paper".

isPrinterBusy

public boolean isPrinterBusy()
Description copied from class: ParallelPort
Checks if the port is indicating a "Printer Busy" state.

Specified by:
isPrinterBusy in class ParallelPort
Returns:
true if printer is busy, false if printer is idle

isPrinterSelected

public boolean isPrinterSelected()
Description copied from class: ParallelPort
Checks if the printer is in selected state.

Note: This method is platform dependent.

Specified by:
isPrinterSelected in class ParallelPort
Returns:
true if printer is selected, false if printer is in deselected mode

isPrinterTimedOut

public boolean isPrinterTimedOut()
Description copied from class: ParallelPort
Checks if the printer has timed out.

Note: This method is platform dependent.

Specified by:
isPrinterTimedOut in class ParallelPort
Returns:
true if printer has timed out, false if printer does not report "Out of paper".

isPrinterError

public boolean isPrinterError()
Description copied from class: ParallelPort
Checks if the printer has encountered an error.

Note: This method is platform dependent.

Specified by:
isPrinterError in class ParallelPort
Returns:
true if printer has encountered an error, false if printer does not report "Out of paper".

addEventListener

public void addEventListener(ParallelPortEventListener lsnr)
                      throws java.util.TooManyListenersException
Description copied from class: ParallelPort
Registers a ParallelPortEventListener object for ParallelPortEvents. Interest in specific events may be expressed by using the notifyOnError and notifyOnBuffer methods.

Only one listener per ParallelPort is supported. Calling addEventListener multiple times will simply replace the current ParallelPortEventListener object.

After the port is closed, no more event will be generated. Another call to open() of the port's CommPortIdentifier object will return a new CommPort object, and the lsnr has to be added again to the new CommPort object to receive event from this port.

Specified by:
addEventListener in class ParallelPort
Parameters:
lsnr - A ParallelPortEventListener object whose parallelEvent method will be called to indicate an event.

Throws:
java.util.TooManyListenersException - If an initial attempt to attach a listener succeeds, subsequent attempts will throw TooManyListenersException without effecting the first listener.

removeEventListener

public void removeEventListener()
Description copied from class: ParallelPort
Deregisters event listener registered using addEventListener. This is done automatically when a port is closed.

Specified by:
removeEventListener in class ParallelPort

raiseEvent

private void raiseEvent(int notify_bit,
                        boolean oldvalue,
                        boolean newvalue)

notifyOnError

public void notifyOnError(boolean enable)
Description copied from class: ParallelPort
Expresses interest in being notified of port errors.

Specified by:
notifyOnError in class ParallelPort
Parameters:
enable - enable or disable error notification based on whether notify is true or false

notifyOnBuffer

public void notifyOnBuffer(boolean enable)
Description copied from class: ParallelPort
Expresses interest in being notified when the output buffer is empty.

Specified by:
notifyOnBuffer in class ParallelPort
Parameters:
enable - true enables notification; false disables notification.

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Description copied from class: CommPort
Returns an input stream. This is the only way to receive data from the communications port. If the port is unidirectional and doesn't support receiving data, then getInputStream returns null.

The read behaviour of the input stream returned by getInputStream depends on combination of the threshold and timeout values. The possible behaviours are described in the table below:

Threshold Timeout Read Buffer Size Read Behaviour
State Value State Value
disabled - disabled - n bytes block until any data is available
enabled m bytes disabled - n bytes block until min(m,n) bytes are available
disabled - enabled x ms n bytes block for x ms or until any data is available
enabled m bytes enabled x ms n bytes block for x ms or until min(m,n) bytes are available

Note, however, that framing errors may cause the Timeout and Threshold values to complete prematurely without raising an exception.

Enabling the Timeout OR Threshold with a value a zero is a special case. This causes the underlying driver to poll for incoming data instead being event driven. Otherwise, the behaviour is identical to having both the Timeout and Threshold disabled.

Specified by:
getInputStream in class CommPort
Returns:
InputStream object that can be used to read from the port
Throws:
java.io.IOException - if an I/O error occurred

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Description copied from class: CommPort
Returns an output stream. This is the only way to send data to the communications port. If the port is unidirectional and doesn't support sending data, then getOutputStream returns null.

Specified by:
getOutputStream in class CommPort
Returns:
OutputStream object that can be used to write to the port
Throws:
java.io.IOException - if an I/O error occurred

close

public void close()
Description copied from class: CommPort
Closes the communications port. The application must call close when it is done with the port. Notification of this ownership change will be propagated to all classes registered using addPortOwnershipListener.

Overrides:
close in class CommPort

nativeClosePort

private void nativeClosePort(int port_fd)
                      throws java.io.IOException
Throws:
java.io.IOException

nativeAvailable

private int nativeAvailable(int port_fd)
                     throws java.io.IOException
Throws:
java.io.IOException

nativeReadByte

private byte nativeReadByte(int port_fd)
                     throws java.io.IOException
Throws:
java.io.IOException

nativeRead

private int nativeRead(int port_fd,
                       byte[] buf,
                       int offset,
                       int len)
                throws java.io.IOException
Throws:
java.io.IOException

nativeWrite

public int nativeWrite(int port_fd,
                       byte[] buf,
                       int offset,
                       int len)
                throws java.io.IOException
Throws:
java.io.IOException

enableReceiveThreshold

public void enableReceiveThreshold(int thresh)
                            throws UnsupportedCommOperationException
Description copied from class: CommPort
Enables receive threshold, if this feature is supported by the driver. When the receive threshold condition becomes true, a read from the input stream for this port will return immediately.

enableReceiveThreshold is an advisory method which the driver may not implement. By default, receive threshold is not enabled.

An application can determine whether the driver supports this feature by first calling the enableReceiveThreshold method and then calling the isReceiveThresholdEnabled method. If isReceiveThresholdEnabled still returns false, then receive threshold is not supported by the driver. If the driver does not implement this feature, it will return from blocking reads at an appropriate time.

See getInputStream for description of exact behaviour.

Specified by:
enableReceiveThreshold in class CommPort
Parameters:
thresh - when this many bytes are in the input buffer, return immediately from read.

Throws:
UnsupportedCommOperationException - is thrown if receive threshold is not supported by the underlying driver.

disableReceiveThreshold

public void disableReceiveThreshold()
Description copied from class: CommPort
Disables receive threshold.

Specified by:
disableReceiveThreshold in class CommPort

isReceiveThresholdEnabled

public boolean isReceiveThresholdEnabled()
Description copied from class: CommPort
Checks if receive threshold is enabled.

Specified by:
isReceiveThresholdEnabled in class CommPort
Returns:
boolean true if the driver supports receive threshold.

getReceiveThreshold

public int getReceiveThreshold()
Description copied from class: CommPort
Gets the integer value of the receive threshold. If the receive threshold is disabled or not supported by the driver, then the value returned is meaningless.

Specified by:
getReceiveThreshold in class CommPort
Returns:
number of bytes for receive threshold

enableReceiveTimeout

public void enableReceiveTimeout(int rcvTimeout)
Description copied from class: CommPort
Enables receive timeout, if this feature is supported by the driver. When the receive timeout condition becomes true, a read from the input stream for this port will return immediately.

enableReceiveTimeout is an advisory method which the driver may not implement. By default, receive timeout is not enabled.

An application can determine whether the driver supports this feature by first calling the enableReceiveTimeout method and then calling the isReceiveTimeout method. If isReceiveTimeout still returns false, then receive timeout is not supported by the driver.

See getInputStream for description of exact behaviour.

Specified by:
enableReceiveTimeout in class CommPort
Parameters:
rcvTimeout - when this many milliseconds have elapsed, return immediately from read, regardless of bytes in input buffer.


disableReceiveTimeout

public void disableReceiveTimeout()
Description copied from class: CommPort
Disables receive timeout.

Specified by:
disableReceiveTimeout in class CommPort

isReceiveTimeoutEnabled

public boolean isReceiveTimeoutEnabled()
Description copied from class: CommPort
Checks if receive timeout is enabled.

Specified by:
isReceiveTimeoutEnabled in class CommPort
Returns:
boolean true if the driver supports receive timeout.

getReceiveTimeout

public int getReceiveTimeout()
Description copied from class: CommPort
Gets the integer value of the receive timeout. If the receive timeout is disabled or not supported by the driver, then the value returned is meaningless.

Specified by:
getReceiveTimeout in class CommPort
Returns:
number of milliseconds in receive timeout

nativeSetTimeout

private void nativeSetTimeout(int port_fd,
                              int timeout)

disableReceiveFraming

public void disableReceiveFraming()
Description copied from class: CommPort
Disables receive framing.

Specified by:
disableReceiveFraming in class CommPort

enableReceiveFraming

public void enableReceiveFraming(int framingByte)
                          throws UnsupportedCommOperationException
Description copied from class: CommPort
Enables receive framing, if this feature is supported by the driver. When the receive framing condition becomes true, a read from the input stream for this port will return immediately.

enableReceiveFraming is an advisory method which the driver may not implement. By default, receive framing is not enabled.

An application can determine whether the driver supports this feature by first calling the enableReceiveFraming method and then calling the isReceiveFramingEnabled method. If isReceiveFramingEnabled still returns false, then receive framing is not supported by the driver.

Note: As implemented in this method, framing is not related to bit-level framing at the hardware level, and is not associated with data errors.

Specified by:
enableReceiveFraming in class CommPort
Parameters:
framingByte - this byte in the input stream suggests the end of the received frame. Blocked reads will return immediately. Only the low 8 bits of framingByte are used while the upper 24 bits are masked off. A value outside the range of 0-255 will be converted to the value of its lowest 8 bits.

Throws:
UnsupportedCommOperationException - is thrown if receive timeout is not supported by the underlying driver.

isReceiveFramingEnabled

public boolean isReceiveFramingEnabled()
Description copied from class: CommPort
Checks if receive framing is enabled.

Specified by:
isReceiveFramingEnabled in class CommPort
Returns:
boolean true if the driver supports receive framing.

getReceiveFramingByte

public int getReceiveFramingByte()
Description copied from class: CommPort
Gets the current byte used for receive framing. If the receive framing is disabled or not supported by the driver, then the value returned is meaningless. The return value of getReceiveFramingByte is an integer, the low 8 bits of which represent the current byte used for receive framing.

Note: As implemented in this method, framing is not related to bit-level framing at the hardware level, and is not associated with data errors.

Specified by:
getReceiveFramingByte in class CommPort
Returns:
integer current byte used for receive framing

setInputBufferSize

public void setInputBufferSize(int size)
Description copied from class: CommPort
Sets the input buffer size. Note that this is advisory and memory availability may determine the ultimate buffer size used by the driver.

Specified by:
setInputBufferSize in class CommPort
Parameters:
size - size of the input buffer

getInputBufferSize

public int getInputBufferSize()
Description copied from class: CommPort
Gets the input buffer size. Note that this method is advisory and the underlying OS may choose not to report correct values for the buffer size.

Specified by:
getInputBufferSize in class CommPort
Returns:
input buffer size currently in use

setOutputBufferSize

public void setOutputBufferSize(int size)
Description copied from class: CommPort
Sets the output buffer size. Note that this is advisory and memory availability may determine the ultimate buffer size used by the driver.

Specified by:
setOutputBufferSize in class CommPort
Parameters:
size - size of the output buffer

getOutputBufferSize

public int getOutputBufferSize()
Description copied from class: CommPort
Gets the output buffer size. Note that this method is advisory and the underlying OS may choose not to report correct values for the buffer size.

Specified by:
getOutputBufferSize in class CommPort
Returns:
output buffer size currently in use