Phidgets
Class Phidget

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--Phidgets.Phidget
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
PhidgetAccelerometer, PhidgetEncoder, PhidgetInterfaceKit, PhidgetLED, PhidgetManager, PhidgetMotorControl, PhidgetPHSensor, PhidgetRFID, PhidgetServo, PhidgetTemperatureSensor, PhidgetTextLCD, PhidgetTextLED, PhidgetWeightSensor

public class Phidget
extends java.lang.Thread

Version:
1.0.5

This is the base class from which all Phidget Devices derive. Don't cerate phidget devices directly using this class. Use the specific class for the device that you wish to access.

General usage of the java Phidget library is as follows:

Support for Phidgets in java is provided by way of the Phidget Server, a TCP/IP based socket server that is run on the pc with the attached phidget. Because of this, java doesn't need to talk to the hardware direcly, and so a JNI is not needed. Also, both local and remote Phidgets can be opened and controlled.

To open a Phidget:

First, create an instance of the device you wish to open:
ie: PhidgetInterfaceKit ifkit = new PhidgetInterfaceKit();

Second, choose a open type:

There are two ways to open Phidgets: OpenRemote and OpenRemoteIP
OpenRemote uses UDP broadcast to find a server by its registered serial number but only works on internal networks
OpenRemoteIP takes in a regular IP address or hostname for opening Phidgets across networks, or over the internet - wherever broadcast can't be used.

Both methods require the port that the server is running on and the password that it's running with, as well as the serial number of the Phidget you wish to open.

ie: ifkit.OpenRemoteIP("localhost",5001,-1,"pass");

To read from or control a Phidget:

Each Phidget class has it's own methods for controlling the device and reading data from it. Data is polled automatically from the Phidget devices and so it always up to date and accesible using the Get methods. Also, event handlers can be registered that will recieve notification on data changes.

To set up Events:

Each phidget has two methods for events: add_IPhidgetEventsListener(_IPhidgetEvents l) and remove_IPhidgetEventsListener() for adding and removing event handlers.

The easiest way to set up event support is to create a class that implements the events interface for that device and write your events handlers there, then pass that class to the add event listener method.

Each device has it's own set of events, but every Phidget supports three basic event types: OnDetach, OnAttach and OnError which can be used for basic monitoring.

Author:
Patrick McNeil

Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Phidget()
           
 
Method Summary
 void Close()
          Closes the device.
 boolean equals(java.lang.Object comp)
           
 java.lang.String GetDeviceType()
          Gets the device type.
 int GetDeviceVersion()
          Gets the Device Version.
 boolean GetIsAttached()
          Gets the connection status.
 int GetSerialNumber()
          Gets the Serial Number.
 java.lang.String GetServerAddress()
          Gets the IP address of the Phidget WebService
 int GetServerID()
          Gets the Server ID of the Phidget WebService
 int GetServerPort()
          Gets the Port of the Phidget WebService
 void run()
          Polls for phidget data on an open socket.
 void setDeviceType(java.lang.String string)
          Sets the device name.
 void setDeviceVersion(int i)
          Sets teh device version.
 void setSerialNumber(int i)
          Sets the serial number.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Phidget

public Phidget()
Method Detail

GetSerialNumber

public int GetSerialNumber()
Gets the Serial Number.
Returns:
Serial Number

GetDeviceVersion

public int GetDeviceVersion()
Gets the Device Version.
Returns:
version

GetIsAttached

public boolean GetIsAttached()
Gets the connection status.
Returns:
connection status

GetDeviceType

public java.lang.String GetDeviceType()
Gets the device type.
Returns:
device type

Close

public void Close()
Closes the device. This will shut down all socket connections and call the detach handler for this device.

run

public void run()
Polls for phidget data on an open socket. This function is called as part of the OpenRemote and OpenRemoteIP commands and should not be called directly.
Overrides:
run in class java.lang.Thread

setDeviceType

public void setDeviceType(java.lang.String string)
Sets the device name.
Parameters:
string - Device Name

setDeviceVersion

public void setDeviceVersion(int i)
Sets teh device version.
Parameters:
i - Version

setSerialNumber

public void setSerialNumber(int i)
Sets the serial number.
Parameters:
i - Serial Number

equals

public boolean equals(java.lang.Object comp)
Overrides:
equals in class java.lang.Object

GetServerAddress

public java.lang.String GetServerAddress()
Gets the IP address of the Phidget WebService
Returns:
IP Address

GetServerPort

public int GetServerPort()
Gets the Port of the Phidget WebService
Returns:
Port

GetServerID

public int GetServerID()
Gets the Server ID of the Phidget WebService
Returns:
Server ID