de.wagner_ibw.iow
Class IowPort

java.lang.Object
  |
  +--de.wagner_ibw.iow.IowPort

public class IowPort
extends java.lang.Object

A BinaryPort represents an iow port consists of 8 bits. The IO Warrior 24 contains two of them, the IO Warrior 40 four.

Author:
Thomas Wagner

Field Summary
private  boolean changeFlag
          This Flag shows that new data sets in the data register and a write operation is needed.
private  int data
          Data register of this port.
private  int dir
          Direction register of this port (ioMask).
private  int index
          Contains the port number relating to an real IOW Device that this port belongs to. (0-1 for IO Warrior 24, 0-3 for IO Warrior 40)
private  java.util.Vector listeners
          List of IowPortChangeListener.
private  int spec
          Special function mode bits register of this port (specMask).
 
Constructor Summary
IowPort(int index, int ioMask)
          Simple constructor (ioMask as int).
IowPort(int index, int ioMask, int initialData)
          Simple constructor (ioMask as int) with initial data.
IowPort(int index, java.lang.String ioMask)
          Simple constructor (ioMask as String).
IowPort(int index, java.lang.String ioMask, java.lang.String initialData)
          Simple constructor (ioMask as String) with initial data as String.
 
Method Summary
 void addPortChangeListener(IowPortChangeListener pcl)
          Adds an IowPortChangeListener to the internal list.
private  void checkBit(int bit)
          Validate the given bit number.
 void clearBit(int num)
          Sets the given bit to 0 (clear).
 void clearChangeFlag()
           
private  int convDataString(java.lang.String bin)
          Convenient method for converting data information from String (i.e.
private  int convDirString(java.lang.String bin)
          Convenient method for converting direction information from String (i.e.
 int getData()
          Returns the integer representation of this port.
 int getDataToWrite()
          Returns the content of this port prepared for write operation.
 int getIndex()
           
 int getSpec()
           
 boolean isBitClear(int num)
          Returns true, if the given bit is clear (0).
 boolean isBitSet(int num)
          Returns true, if the given bit is set (1).
 boolean isChangeFlagSet()
           
 void removePortChangeListener(IowPortChangeListener pcl)
          Removes an IowPortChangeListener from the internal list.
 void setBit(int num)
          Sets the given bit to 1 (set).
 void setData(int value)
          Sets the entire port's dtat to the given integer value.
 void setData(java.lang.String value)
          Sets the entire port's data to the given String value.
 void setDataFromRead(int readData)
           
 void setDirection(int ioMask)
          Sets the direction for the port's pins (ioMask as int).
 void setDirection(java.lang.String ioMask)
          Sets the direction for the port's pins (ioMask as String).
 void setSpec(int specMask)
           
 java.lang.String toString()
          Returns the String represenation of this port.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

data

private int data
Data register of this port. Contains the status of each bit (0-Low, 1-High).


dir

private int dir
Direction register of this port (ioMask). Marks bits as input or output.


spec

private int spec
Special function mode bits register of this port (specMask). Marks bits as dedicated for special mode functions.


index

private int index
Contains the port number relating to an real IOW Device that this port belongs to. (0-1 for IO Warrior 24, 0-3 for IO Warrior 40)


changeFlag

private boolean changeFlag
This Flag shows that new data sets in the data register and a write operation is needed. The flag is reseted from the write operation to the chip.


listeners

private java.util.Vector listeners
List of IowPortChangeListener.

Constructor Detail

IowPort

public IowPort(int index,
               int ioMask)
Simple constructor (ioMask as int).

Parameters:
index -
ioMask -

IowPort

public IowPort(int index,
               int ioMask,
               int initialData)
Simple constructor (ioMask as int) with initial data.

Parameters:
index -
ioMask -
initialData -

IowPort

public IowPort(int index,
               java.lang.String ioMask)
        throws java.lang.IllegalArgumentException
Simple constructor (ioMask as String).

Parameters:
index -
ioMask -
Throws:
java.lang.IllegalArgumentException

IowPort

public IowPort(int index,
               java.lang.String ioMask,
               java.lang.String initialData)
        throws java.lang.IllegalArgumentException
Simple constructor (ioMask as String) with initial data as String.

Parameters:
index -
ioMask -
initialData -
Throws:
java.lang.IllegalArgumentException
Method Detail

setDirection

public void setDirection(java.lang.String ioMask)
                  throws java.lang.IllegalArgumentException
Sets the direction for the port's pins (ioMask as String).

Parameters:
ioMask - Describes the pin direction (MSB first):
  • I - Input.
  • O - Output.
Throws:
java.lang.IllegalArgumentException - If ioMask's length != 8 or if ioMask contains invalid chars (valid are 'iIoO')

setDirection

public void setDirection(int ioMask)
Sets the direction for the port's pins (ioMask as int).

Parameters:
ioMask -

setData

public void setData(int value)
Sets the entire port's dtat to the given integer value.
Be aware of the fact that the new data are not automatically written to the IO Warrior device! Use writeIOPorts() additionally to do this.

Parameters:
value -

setData

public void setData(java.lang.String value)
             throws java.lang.IllegalArgumentException
Sets the entire port's data to the given String value.
Be aware of the fact that the new data are not automatically written to the IO Warrior device! Use writeIOPorts() additionally to do this.

Parameters:
value -
Throws:
java.lang.IllegalArgumentException

setBit

public void setBit(int num)
            throws java.lang.IllegalArgumentException
Sets the given bit to 1 (set).
If this bit an input or if it is already 1 then nothing happend. Otherwise the bit is set and dataChanged flag is set true.
Be aware of the fact that the new data are not automatically written to the IO Warrior device! Use writeIOPorts() additionally to do this.

Parameters:
num - Number of the bit which is set (1).
Throws:
java.lang.IllegalArgumentException - Is thrown if num contains an invalid bit number (valid numbers are 0...7).

clearBit

public void clearBit(int num)
              throws java.lang.IllegalArgumentException
Sets the given bit to 0 (clear).
If this bit an input or if it is already 0 then nothing happend. Otherwise the bit is clear and dataChanged flag is set true.
Be aware of the fact that the new data are not automatically written to the IO Warrior device! Use writeIOPorts() additionally to do this.

Parameters:
num - Number of the bit which is clear (0).
Throws:
java.lang.IllegalArgumentException - Is thrown if num contains an invalid bit number (valid numbers are 0...7).

isBitSet

public boolean isBitSet(int num)
                 throws java.lang.IllegalArgumentException
Returns true, if the given bit is set (1).

Parameters:
num - Number of the desired bit.
Returns:
True, if the bit is set.
Throws:
java.lang.IllegalArgumentException - Is thrown if num contains an invalid bit number (valid numbers are 0...7).

isBitClear

public boolean isBitClear(int num)
                   throws java.lang.IllegalArgumentException
Returns true, if the given bit is clear (0).

Parameters:
num - Number of the desired bit.
Returns:
True, if the bit is not set.
Throws:
java.lang.IllegalArgumentException - Is thrown if num contains an invalid bit number (valid numbers are 0...7).

getDataToWrite

public int getDataToWrite()
Returns the content of this port prepared for write operation.

Returns:
Integer representation of data. All imputs are set to high.

setDataFromRead

public void setDataFromRead(int readData)
Parameters:
readData -

setSpec

public void setSpec(int specMask)

getSpec

public int getSpec()

isChangeFlagSet

public boolean isChangeFlagSet()

clearChangeFlag

public void clearChangeFlag()

getData

public int getData()
Returns the integer representation of this port.

Returns:
Integer representation.
Since:
0.9.3

getIndex

public int getIndex()

convDataString

private int convDataString(java.lang.String bin)
                    throws java.lang.IllegalArgumentException
Convenient method for converting data information from String (i.e. 'XX010011') to int. 'X' or 'x' means 'don't care' and is the same as 0 (for what is this feature? ;-).

Parameters:
bin -
Returns:
Throws:
java.lang.IllegalArgumentException

convDirString

private int convDirString(java.lang.String bin)
                   throws java.lang.IllegalArgumentException
Convenient method for converting direction information from String (i.e. "IIIIOOOO") to int. 'I' or 'i' means input, 'O' or 'o' means output.

Parameters:
bin -
Returns:
Throws:
java.lang.IllegalArgumentException

addPortChangeListener

public void addPortChangeListener(IowPortChangeListener pcl)
Adds an IowPortChangeListener to the internal list.

Parameters:
pcl - IowPortChangeListener that has added to the list.

removePortChangeListener

public void removePortChangeListener(IowPortChangeListener pcl)
Removes an IowPortChangeListener from the internal list.

Parameters:
pcl - IowPortChangeListener that has removed from the list.

checkBit

private void checkBit(int bit)
               throws java.lang.IllegalArgumentException
Validate the given bit number.

Parameters:
bit -
Throws:
java.lang.IllegalArgumentException - Is thrown if num contains an invalid bit number (valid numbers are 0...7).
Since:
0.9.3

toString

public java.lang.String toString()
Returns the String represenation of this port. 'IoMask' describes the pin direction (MSB first): 'Data' describes the current pin status (MSB first):

Overrides:
toString in class java.lang.Object
Returns:
String representation.