hypermedia.picoip
Class PicoIP

java.lang.Object
  extended by hypermedia.picoip.PicoIP

public class PicoIP
extends Object

A simple object to easily communicate with PicoIP card (http://www.pictec.org/).

Version:
0.1
Author:
Cousot Stéphane - stef@ubaa.net, Douglas Edric Stanley - http://www.abstractmachine.net/

Field Summary
static int DEFAULT_PIN_COUNT
          The number of pins on the PicoIP card
static int TIMEOUT
          The default connection timeout in milliseconds
 
Constructor Summary
PicoIP(Object parent, String address)
          Initializes PicoIP object and binds it to an available port.
PicoIP(Object parent, String address, int pin_count)
          Initializes PicoIP object and binds it to an available port.
PicoIP(Object parent, String address, int pin_count, int port)
          Initializes PicoIP object with the given listening port.
 
Method Summary
 boolean ask(int pin)
          Ask for the given pin's value.
 void close()
          Close the current connection.
 void log(boolean on)
          Enable or disable UDP connexion log
 int port()
          Return the actual listening port or -1 if the connexion is not set.
 void receive(byte[] data)
          PicoIP receive handler.
 void reset()
          Turn off all pins
 boolean set(int pin, boolean state)
          Turn on/off the requested pin.
 boolean set(int pin, int value)
          Change the given pin's value.
 void timeout(int millis)
          Set the timeout value for the response time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PIN_COUNT

public static final int DEFAULT_PIN_COUNT
The number of pins on the PicoIP card

See Also:
Constant Field Values

TIMEOUT

public static final int TIMEOUT
The default connection timeout in milliseconds

See Also:
Constant Field Values
Constructor Detail

PicoIP

public PicoIP(Object parent,
              String address)
Initializes PicoIP object and binds it to an available port.

Parameters:
parent - the object owner
address - the PicoIP card address

PicoIP

public PicoIP(Object parent,
              String address,
              int pin_count)
Initializes PicoIP object and binds it to an available port.

Parameters:
parent - the object owner
address - the PicoIP card address
pin_count - the number of PIcoIP inputs/outputs

PicoIP

public PicoIP(Object parent,
              String address,
              int pin_count,
              int port)
Initializes PicoIP object with the given listening port.

note: PicoIP use two different ports for the communication. One for sending messages, the other for listening. The only rule to remember is that PicoIP receive message on his sending port + 100.

Parameters:
parent - the object owner
address - the card address
pin_count - the number of PIcoIP inputs/outputs
port - the listening port to bind on
Method Detail

port

public int port()
Return the actual listening port or -1 if the connexion is not set.

Returns:
int

log

public void log(boolean on)
Enable or disable UDP connexion log

Parameters:
on - print out UDP activity while true

set

public boolean set(int pin,
                   boolean state)
Turn on/off the requested pin. Return true on success, false otherwise.

Parameters:
pin - the pin index
state - the required pin status
Returns:
boolean

set

public boolean set(int pin,
                   int value)
Change the given pin's value. Return true on success, false otherwise.

Parameters:
pin - the pin index
value - the new pin value
Returns:
boolean

ask

public boolean ask(int pin)
Ask for the given pin's value. To get the result (or perform actions on this event), you must implement in your code this method :
        void receive(int pin, int value) {
                // do something here...
        }
 

Return true on success, false otherwise.

notes : this method will be automatically called when the socket receive incoming data.

Parameters:
pin - the pin index to be check
Returns:
boolean

receive

public void receive(byte[] data)
PicoIP receive handler. This method is called automatically, you do not need to call it.


timeout

public void timeout(int millis)
Set the timeout value for the response time. This value must be greater or equal to 0, otherwise the timeout is set to his default value. If the passed number equal to 0, the listening method is set in an infinity loop until a response is received.

Parameters:
millis - the new timeout value in milliseconds
See Also:
TIMEOUT

reset

public void reset()
Turn off all pins


close

public void close()
Close the current connection.