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 IO-Warrior port consists of 8 bits. The IO-Warrior 24 contains two of them, the IO-Warrior 40 four and the IO-Warrior 56 seven of them (port 6 only bit 0 and 7).

Author:
Thomas Wagner

Constructor Summary
IowPort(int index, int ioMask)
          Simple constructor (io mask as int).
IowPort(int index, int ioMask, int initialData)
          Simple constructor (io mask as int) with initial data.
IowPort(int index, java.lang.String ioMask)
          Simple constructor (io mask as String).
IowPort(int index, java.lang.String ioMask, java.lang.String initialData)
          Simple constructor (io mask as String) with initial data as String.
 
Method Summary
 void addPortChangeListener(IowPortChangeListener pcl)
          Adds an IowPortChangeListener to the internal list.
 void clearBit(int num)
          Sets the given bit to 0 (clear).
 int getData()
          Returns the integer representation of this port.
 int getDataToWrite()
          Returns the content of this port prepared for write operation.
 int getIndex()
          Returns the port index of this port.
 int getSpecial()
          Getter for special bit mask.
 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).
 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)
          Sets the port's data register after read report received.
 void setDirection(int ioMask)
          Sets the direction for the port's pins (io mask as int).
 void setDirection(java.lang.String ioMask)
          Sets the direction for the port's pins (io mask as String).
 void setSpecial(int specialMask)
          Setter for special bit mask.
 java.lang.String toString()
          Returns the String represenation of this port.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IowPort

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

Parameters:
index - index for this port.
ioMask - io mask for this port.

IowPort

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

Parameters:
index - index for this port.
ioMask - io mask for this port.
initialData - initial data fro this port.

IowPort

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

Parameters:
index - index for this port.
ioMask - io mask for this port.
Throws:
java.lang.IllegalArgumentException - if string ioMask is invalid.

IowPort

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

Parameters:
index - index for this port.
ioMask - io mask for this port.
initialData - initial data fro this port.
Throws:
java.lang.IllegalArgumentException - if string ioMask is invalid.
Method Detail

setDirection

public void setDirection(java.lang.String ioMask)
                  throws java.lang.IllegalArgumentException
Sets the direction for the port's pins (io mask 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 (io mask 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. All inputs are set to high.

Returns:
Integer representation of data.

setDataFromRead

public void setDataFromRead(int readData)
Sets the port's data register after read report received.

Parameters:
readData - appropriate byte from read report.

setSpecial

public void setSpecial(int specialMask)
Setter for special bit mask.

Parameters:
specialMask - special bit mask to set.

getSpecial

public int getSpecial()
Getter for special bit mask.

Returns:
special bit mask.

getData

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

Returns:
Integer representation.
Since:
0.9.3

getIndex

public int getIndex()
Returns the port index of this port.


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.

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.