actionscript 3.0 api manual - old dominion...
TRANSCRIPT
Actionscript 3.0 API Manual
Phidget21
Describes the Application Program Interface (API) for each Phidget device. The API can be used by a number of languages; this manual discusses use via Flash and the code examples reflect this.
Library Version: 2.1.1
Phidgets Actionscript 3.0 API ReferenceVersion 21.2
© Phidgets Inc. 2007
Contents
How to use Phidgets 5Basic Architecture 5Basic Example 5Phidget Class 6Phidget Methods 7Phidget Events 8PhidgetAccelerometer 9Phidget Accelerometer Methods 9Phidget Accelerometer Events 10PhidgetEncoder 11Phidget Encoder Methods 11Phidget Encoder Events 12PhidgetInterfaceKit 13Phidget InterfaceKit Methods 13Phidget InterfaceKit Events 15PhidgetLED 16Phidget LED Methods 16PhidgetMotorControl 17Phidget Motor Control Methods 17Phidget Motor Control Events 19PhidgetPHSensor 20Phidget PH Sensor Events 20PhidgetRFID 21Phidget RFID Methods 21Phidget RFID Events 22PhidgetServo 23Phidget Servo Methods 23Phidget Servo Events 24PhidgetTemperatureSensor 25Phidget Temperature Sensor Methods 25Phidget Temperature Sensor Events 26PhidgetTextLCD 27Phidget Text LCD Methods 27The Phidget Dictionary 28Phidget Dictionary Methods 28Phidget Dictionary Events 29The Phidget Manager 31Phidget Manager Methods 31Phidget Manager Events 32Appendix I: Regular Expressions 33Extended Regular Expressions: 34Appendix II: Error Codes and Descriptions 35Appendix III: Special Values 37Appendix IV: Event Handlers 38Appendix V: Change Triggers 39Appendix VII: Generating Custom Characters 40
How to use Phidgets
Phidgets are an easy to use set of building blocks for low cost sensing and control from your PC. Using the Universal Serial Bus (USB) as the basis for all Phidgets, the complexity is managed behind this easy to use and robust Application Program Interface (API) library.
The library was written originally for Windows, but has been ported to MacOS and Linux. Although the library is written in C, the functions can be called from a number of languages including C, C++, Objective-C, Matlab, Flash, etc. The source code is freely available for reference/debugging purposes.
Basic Architecture
Phidgets are controlled at the API Level using a specific object for the type of Phidget you are using.
Operations are performed by calling methods on this object. Objects are registered, and associated with a Phidget device using one of the Phidget.open functions. After the OnAttach event fires, commands can be issued.
If the application needs data from the device, event handlers can be used, or property get functions can be used to get specific values. Lastly, the Phidget.close method is called to disconnect the object from the Phidget.
Basic Example
When programming for all Phidgets the basic procedure is always the same. First an object must be declared as a Phidget. Then on Open command must be sent, after which the object will be attached. Only after the attach occurs can any inputs be read or outputs changed.
This example contacts the Local Webservice on Port 5001 and attempts to open a Phidget IntefaceKit.To use this code, paste it into the Actions pane for the first frame of a movie. You should see activity on the Output pane when the Movie is Tested.
import com.phidgets.*;import com.phidgets.events.*;var blnInit;var myPhidget:Phidget;function onAttach(evt:PhidgetEvent):void{ trace(evt);}if (blnInit != true) { trace('Performing Initialisation'); myPhidget= new PhidgetInterfaceKit(); myPhidget.addEventListener(PhidgetEvent.ATTACH, onAttach); myPhidget.open("localhost", 5001); blnInit = true;}
More detailed examples for all the calls in this document can be found in the Downloads section of the Phidgets website.
Client Machine
User Application
Phidget Library
Phidget Device
Device Firmware
Device Hardware
IO Devices
Sensors
Indicators
ActuatorsUSB
TCP/IP
Server / Phidget Host
Phidget Library
UserApplication
PhidgetWebService
Phidget Class
The base class for interaction with Phidget devices is the Phidget Class. All Phidgets will have these properties, methods and events in common
Class: PhidgetPackage: com.phidgetsExtends: EventDispatcher
Base class for all Phidget device interaction
PropertiesLabel:string [get/set] Gets and Sets a user specified Identifying string for the phidget.
ServerID:String [get] DNS name of the server hosting the Phidget device
Port:int [get] Port of the Webservice on the Server
Address:String [get] IP Address of the Server that hosts this Phidget device
isConnected:Boolean [get] Whether or not the device is physically connected
isAttached:Boolean [get] Returns an integer indicating the status of the device.
serialNumber:int [get] Returns the unique serial number of this Phidget. This number is set during manufacturing, and is unique across all Phidgets.
Version:int [get] Sets a pointer to a null terminated string describing the Device Version of the Phidget
Name:String [get] Sets a pointer to a null terminated string describing the name of the Phidget.. For example, “Phidget InterfaceKit 8/8/8”, “Phidget InterfaceKit 0/0/4”, etc.
Type:String [get] Sets a pointer to a null terminated string describing the type of the Phidget. All PhidgetInterfaceKits will return "PhidgetInterfaceKit", PhidgetRFID returns "PhidgetRFID" and so on.
Phidget Methods
Phidget.openCreates a connection between a CPhidgetHandle and a physical Phidget. The CPhidgetHandle should be a valid handle previously allocated by CPhidget(device)_create. Before calling CPhidget_open, we recommend registering the event handlers your application will use.
Open is pervasive. What this means is that you can call open on a device before it is plugged in, and keep the device opened across device dis- and re-connections.
Open is Asynchronous. What this means is that open will return immediately – before the device being opened is actually available. What this means is that you need to either poll CPhidget_getDeviceStatus for an attached status, or handle the attach event, in order to wait for the device to become available before trying to use it.
open (address:String, port:Number, password:String, serialNumber:Number):voidInputaddress:string IP Address of the server hosting the Phidget
port:Number Port- number of the webservice running on the server
password:String Password to the serverCan be empty if password is not used on server
serialNumber:Number Serial Number of the phidget you wish to openSetting to -1 will open the first available Phidget device matching the object type you are calling open upon. This can be empty if only device exists.
Phidget.closeCloses the file handles for this device. You can call this while reads and writes are still outstanding; they will fail quickly
close():void
Phidget.toString()Returns a string containing the Phidget Device Name, Device Version and Serial Number. This should allow one to uniquely identify a particular Phidget device.
toString():StringOutputreturn value:String
Phidget Events com.phidgets.events.PhidgetEvent com.phidgets.events.PhidgetErrorEvent
onConnectedAn event raised by a Phidget object when it has established communication with a Phidget device after an Open request.
PhidgetEvent (PhidgetEvent.CONNECT, myphidget:Phidget)ParametersPhidgetEvent.CONNECT The type of event raised by the Phidget. In this case a Connect event
myphidget:Phidget The Phidget object that raised the event
onDisconnectedAn event raised by a Phidget object when it has lost communication with a Phidget device.
PhidgetEvent (PhidgetEvent.DISCONNECT, myphidget:Phidget)ParametersPhidgetEvent:DISCONNECT The type of event raised by the Phidget. In this case a Disconnect event
myphidget:Phidget The Phidget object that raised the event
onErrorAn event raised by a Phidget object when it encounters an error, either in the parameters of a request made to the object or an error being raised by the Phidget device itself.
PhidgetErrorEvent (PhidgetErrorEvent.ERROR, myphidget:Phidget, error:PhidgetError)ParametersPhidgetErrorEvent:ERROR The type of event raised by the Phidget In this case an Error event
myphidget:Phidget The Phidget object that raised the event
error:PhidgetError The error code being raised. Corresponds to one of the PhidgetErrorsSee the Appendices for a list of these error codes.
onAttachAn event raised by a Phidget object when the Phdiget device is physically connected to the host machine.
PhidgetEvent (PhidgetEvent.ATTACH, myphidget:Phidget)
ParametersPhidgetEvent.ATTACH The type of event raised by the Phidget.
In this case a Attach event
myphidget:Phidget The Phidget object that raised the event
onDetachAn event raised by the Phidget object when the Phidget device is physically disconnect from the host machine.
PhidgetEvent (PhidgetEvent.DETACH, myphidget:Phidget)ParametersPhidgetEvent.DETACH The type of event raised by the Phidget. In this case a Detach event
myphidget:Phidget The Phidget object that raised the event
PhidgetAccelerometer
The PhidgetAccelerometer is a component that provides a high-level programmer interface to control a PhidgetAccelerometer device connected through a USB port. The product is available as a dual axis or a 3-axis module. With this component, the programmer can:
Measure up to 5 Gravity (5*9.8 m/s2) change per axis, depending on unit purchased.•Measures both dynamic acceleration (e.g., vibration) and static acceleration (e.g., gravity or tilt) on 2 or 3 •axis.
Class: PhidgetAccelerometerPackage: com.phidgetsExtends: Phidget
Specialised class for PhidgetAccelerometer Device interaction
PropertiesNumberOfAxes:int [get] Get the number of axes available from the PhidgetAccelerometer.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
Phidget Accelerometer Methods
PhidgetAccelerometer.getAccelerationGets the last acceleration value received from the PhidgetAccelerometer for a particular axis.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
getAcceleration(index:int):NumberInputindex:int Index of Axis to query
Outputreturn value:Number Current value of the Acceleration
PhidgetAccelerometer.getAccelerationChangeTriggerGets the amount of change that should exist between the last reported value and the current value before an OnAccelerationChange event is fired.
For additional information please view the Appendix on Change Triggers.
getAccelerationChangeTrigger(index:int):NumberInputindex:int Index of the Axis to query for Change Trigger
Outputreturn value:Number Current value of the Change Trigger
PhidgetAccelerometer.setAccelerationChangeTriggerSpecifies the amount of change that should exist between the last reported value and the current value before an OnAccelerationChange event is fired. If the AccelerationChangeTrigger is set to 0, an event will be triggered for every measurement of acceleration taken.
For additional information please view the Appendix on Change Triggers
setAccelerationChangeTrigger(index:int, val:Number):voidInputindex:int Index of the Axis to set the Change Trigger on
val:Number Value to set the Change Trigger to
Phidget Accelerometer Events com.phidgets.events.PhidgetDataEvent
onAccelerationChangeAn event raised by the Phidget when the Acceleratin exceeds the Acceleration Change Trigger threshold
PhidgetDataEvent( PhidgetDataEvent.ACCELERATION_CHANGE, myPhidget:Phidget, acceleration:Number, index:int)ParametersPhidgetDataEvent.ACCELERATION_CHANGE The type of event being raised by the Phidget.
In this case an Acceleration Change.
myPhidget:Phidget The Phidget object raising the event
acceleration:Number The current value of the Acceleration
index:int The index of the Axis raising the event
PhidgetEncoder
The PhidgetEncoder is a component that provides a high-level programmer interface to control a PhidgetEncoder device connected through a USB port.
With this component, the programmer can: Detect changes in position of incremental and absolute encoders.•Easily track the changes with respect to time.•
Class: PhidgetEncoderPackage: com.phidgetsExtends: Phidget
Specialised class for PhidgetEncoder device interaction
PropertiesNumberOfInputs:int [get] Returns the number of inputs on this particular Phidget device.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
NumberOfEncoders:int [get] Gets the number of encoders available on the Phidget.Please view the Phidget’s Product Manual to determine if functionality varies from this document.
Phidget Encoder Methods
PhidgetEncoder.getInputStateReturns the state of the designated input.
In the case of a switch or button which is normally open, True would correspond to when the switch is pressed.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
Note this is not available on the PhidgetEncoder HighSpeed device.
getInputState(index:int):BooleanInputindex:int Index of input to query
Outputreturn value:Boolean Current input state
PhidgetEncoder.getEncoderPositionGets the last position value received from the encoder for the particular encoder selected.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
getEncoderPosition(index:int):NumberInputindex:int Index of encoder to query
Outputreturn value:int Current position of encoder
PhidgetEncoder.setEncoderPositionSpecifies a new value for the current position of the encoder.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
setEncoderPosition(index:int, val:Number):voidInputindex:int Index of encoder to set
val:Number New position of encoder
Phidget Encoder Events com.phidgets.events.PhidgetDataEvent
onInputChangeAn event raised when a digital input changes state.
PhidgetDataEvent (PhidgetDataEvent.INPUT_CHANGE, myPhidget;Phidget, input:Boolean, index:int)ParametersPhidgetDataEvent.INPUT_CHANGE The type of event being raised by the Phidget.
In this case an Input Change event
myPhidget:Phidget The Phidget object raising the event
input:Boolean The current value of the Input
index:int The index of the Input raising the event
onPositionChangeAn event raised when the Position of the Encoder is changed.
PhidgetDataEvent ( PhidgetDataEvent.POSITION_CHANGE, myPhidget:Phidget, position:int, index:int)ParametersPhidgetDataEvent.POSITION_CHANGE The type of event being raised by the Phidget.
In this case a Position Change event.
myPhidget:Phidget The Phidget object raising the event
position:int The current value of the Position
index:int The index of the Encoder raising the event
PhidgetInterfaceKit
The PhidgetInterfaceKit is a component that provides a high-level programmer interface to control a PhidgetInterfaceKit device connected through a USB port.
With this component, the programmer can: Turn particular outputs on and off.•Get notified of changes of state of the inputs as events.•Configure events to fire when the analog inputs change.•
The PhidgetInterfaceKit devices provide a combination of: Digital outputs.•Digital inputs.•Analog inputs.•
Note that any implementation details that vary from this document will be noted in the Product Manual for the specific device.
Class: PhidgetInterfaceKitPackage: com.phidgetsExtends: Phidget
A specialised class that handles interaction with an InterfcaeKit device.
PropertiesNumberOfInputs:int [get] Gets the number of Inputs on the device
NumberOfOutputs:int [get] Gets the number of Outputs on the device
NumberOfSensors:int [get] Gets the number of analog inputs available on the given PhidgetInterface KitPlease view the Phidget’s Product Manual to determine if functionality varies from this document.
Ratiometric:Boolean [get/set] Some of the PhidgetInterfaceKits with Analog Inputs have to ability to measure voltage by comparing to a fixed 5 Volt reference, or comparing to the voltage supplied to the sensor. If your sensor operates as a voltage divider, or the output is described as ratiometric, SensorValue will be most accurate if Ratiometric is set to true. If your sensor is described as non-ratiometric, set Ratiometric to false.Sensors manufactured by Phidgets Inc. will typically have a small R printed on them if they are Ratiometric, or N if they are non-ratiometric.Note that this value is never actually returned from the Device only maintained by the Phidgets Library.Applications that use this value should set it explicitly.Please view the Phidget’s Product Manual to determine if functionality varies from this document.
Phidget InterfaceKit Methods
PhidgetInterfaceKit.getInputStateRetrieves the state of a didgital input
getInputState(index:int):BooleanInputindex:int Index of Input to query
Outputreturn value:Boolean Current value of input
PhidgetInterfaceKit.getOutputStateRetrieves the state of a digital output
getOutputState(index:int):BooleanInputindex:int Index of output to query
Outputreturn value:Boolean Current value of output
PhidgetInterfaceKit.setOutputStateSets the state of a digital output
setOutputState(index:int, val:Boolean):voidInputindex:int Index of output to set
val:Boolean Value to set output to
PhidgetInterfaceKit.getSensorValueGets the last reported sensor value for the given index as a value from 0-1000
Note that this value defaults to 65535 for an unitialised state. Applications that do not wish to encounter this value should use ChangeTrigger handlers as opposed to polling the device for new data.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
getSensorValue(index:int):intInputindex:int Index of sensor to query
Outputreturn value:int Current value of sensor
PhidgetInterfaceKit.getSensorChangeTriggerGets the amount of change that should exist between the last reported value and the current value before an OnSensorChange event is fired.
To receive all events, set the SensorChangeTrigger to zero.
For additional details on Change Triggers please view the Appendices.
getSensorChangeTrigger(index:int):intInputindex:int Index of Sensor to find change trigger from
Outputreturn value:int Current value of Change Trigger
PhidgetInterfaceKit.setSensorChangeTriggerSpecifies the amount of change that should exist between the last reported value and the current value before an OnSensorChange event is fired
Additional information can be found in the Change Triggers section of the Appendices.
setSensorChangeTrigger(index:int, val:int):voidInputindex:int Index of Sensor to apply change trigger to
val:int Value to set the change trigger to
Phidget InterfaceKit Events com.phidgets.events.PhidgetDataEvent
onInputChangeAn event raised by the PhidgetInterfaceKit object when the digital input changes.
PhidgetDataEvent (PhidgetDataEvent.INPUT_CHANGE, myphidget:Phidget, input:Boolean, index:int)ParametersPhidgetDataEvent.INPUT_CHANGE The type of Data event raised by the Phidget.
In this case, an Input Change event.
myphidget:Phidget The Phidget object that raised the event
input:Boolean The state of the Input that raised the event
index:int=-1 The index of the input that raised the event.
onOutputChangeAn event raised by the PhidgetInterfaceKit when a digital output changes.
PhidgetDataEvent (PhidgetDataEvent.OUTPUT_CHANGE, myphidget:Phidget, output:Boolean, index:int)ParametersPhidgetDataEvent.OUTPUT_CHANGE The type of Data event raised by the Phidget.
In this case, an Output Change event.
myphidget:Phidget The Phidget object that raised the event
output:Boolean The state of the Input that raised the event
index:int=-1 The index of the input that raised the event.
onSensorChangeAn event raised by the PhidgetInterfaceKit object when a Sensor passes it's Change Trigger threshold
PhidgetDataEvent (PhidgetDataEvent.SENSOR_CHANGE, myphidget:Phidget, sensor:int, index:int)ParametersPhidgetDataEvent.SENSOR_CHANGE The type of Data event raised by the Phidget.
In this case, a Sensor Change event.
myphidget:Phidget The Phidget object that raised the event
sensor:int The state of the Sensor that raised the event
index:int=-1 The index of the input that raised the event.
PhidgetLED
The PhidgetLED is a component that provides a high-level programmer interface to control a PhidgetLED device connected through a USB port.
With this component, the programmer can: Control each led individually, On/Off and Brightness.•
Class: PhidgetLEDPackage: com.phidgetsExtends: Phidget
Base class for all Phidget device interaction
PropertiesNumberOfLEDs:int [get] Returns the number of LED positions available in this Phidget.
This property does not return the number of LEDs actually attached.Please view the Phidget’s Product Manual to determine if functionality varies from this document
Phidget LED Methods
PhidgetInterfaceKit.getDiscreteLEDGets the brightness of an individual LED.
Range of brightness is 0-100.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
getDiscreteLED(index:int):intInputindex:int Index of the LED to query
Outputreturn value:int Current value of the LED
PhidgetInterfaceKit.setDiscreteLEDSets the brightness of an individual LED.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
setDiscreteLED(index:int, val:int):voidInputindex:int Index of the LED to set
val:int Value to set the LED toValid from 0-100
PhidgetMotorControl
The PhidgetMotorControl is a component that provides a high-level programmer interface to control a PhidgetMotorControl device connected through a USB port.
With this component, the programmer can: Contro• l direction, and start and stop DC motors.Control the velocity and acceleration of each DC motor.•Read the limit switch.•
Class: PhidgetMotorControl Package: com.phidgetsExtends: Phidget
Specialised class for PhdigetMotorControl device interactuibs
PropertiesNumberOfInputs:int [get] Returns the number of inputs on this particular Phidget device.
Please see the hardware description for the details of device variations.
NumberOfMotors: int [get] Returns the maximum number of motors on this particular Phidget device. This depends on the actual hardware. Please view the Phidget’s Product Manual to determine if functionality varies from this document.Note: that there is no way of programmatically determining how many motors are actually plugged into the hardware.
Phidget Motor Control Methods
PhidgetMotorControl.getInputStateReturns the state of the designated input.
In the case of a switch or button which is normally open, True would correspond to when the switch is pressed.
Note that this device will report PUNKNOWN until data has been received. Applications wishing not to see this value should use Change Handlers as opposed to polling the device for new data.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
getInputState(index:int):BooleanInputindex:int Index of the input to query
Outputreturn value:Boolean Current value of the input
PhidgetMotorControl.getCurrentReturns the current value for current consumption of a motor
getCurrent(index:int):NumberInputindex:int Index of the Motor to query
Outputreturn value:Number Current value of current to the motor
PhidgetMotorControl.getAccelerationGets the current acceleration
Note that this value defaults to 10 upon initialisation.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
getAcceleration(index:int):NumberInputindex:int Index of the motor to query
Outputreturn value:Number Current value of the Acceleration
PhidgetMotorControl.setAccelerationSets the Motor’s Maximum accesleration.
Valid values are 0-100
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
setAcceleration(index:int, val:Number):voidInputindex:int Index of the motor to set
val:Number New maximum acceleration value
PhidgetMotorControl.getMotorSpeedGets the current motor speed.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
getMotorSpeed(index:int):NumberInputindex:int Index of the motor to query
Outputreturn value:Number Current motor speed
PhidgetMotorControl.setMotorSpeedSets the Motor Speed.
Valid values are (–100 – 100)
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
setMotorSpeed(index:int, val:Number):void Inputindex:int Index of the motor to set
val:Number New value for the motor's speed
Phidget Motor Control Events com.phidgets.events.PhidgetDataEvent
onInputChangeAn event raised when a digital Input changes state
PhidgetDataEvent( PhidgetDataEvent.INPUT_CHANGE, myPhidget:Phidget, input:Boolean, index:int)ParametersPhidgetDataEvent.INPUT_CHANGE The type of event being raised by the Phidget.
In this case an Input Change event
myPhdiget:Phidget The Phidget object raising the event
input:Boolean The current value of the input
index:int The index of the input raising the event
onVelocityChangeAn event raised when a Motor velocity changes
PhidgetDataEvent( PhidgetDataEvent.VELOCITY_CHANGE, myPhidget:Phidget, velocity:Number, index:int)ParametersPhidgetDataEvent.VELOCITY_CHANGE The type of event being raised by the Phidget.
In this case a Velocity Change event
myPhdiget:Phidget The Phidget object raising the event
velocity:Number The current Velocity value
index:int The index of the Motor raising the event
onCurrentChangeAn event raised when a Motor's current consumption changes
Note that this may not be available on all device models. Please see your device documentation for information on variation from this document.
PhidgetDataEvent ( PhidgetDataEvent.CURRENT_CHANGE, myPhdiget:Phidget, current:Number, index:int) Parameters
InputPhdigetDataEvent.CURRENT_CHANGE The type of event being raised by the Phidget.
In this case a Current Change event.
myPhdiget:Phidget The Phidget object raising the event
current:Number The current value of the Motor's Current consumption
index:int The index of the Motor raising the event
PhidgetPHSensor
The PhidgetPHSensor is a component that provides a high-level programmer interface to control a PhidgetPHSensor device connected through a USB port.
With this component, the programmer can: Read the pH of a liquid with a pH sensor.•
Class: PhidgetPHSensorPackage: com.phidgetsExtends: Phidget
Specialised class for PhidgetPHSensor device interaction
PropertiesPH:Number [get] Returns the current pH.
Valid range is 0-14Note that this value defaults to -20. Applications not wishing to encounter this value should use Change Handlers instead of polling the device for data.Please view the Phidget’s Product Manual to determine if functionality varies from this document.
Potential:Number [get] Returns the current potential in volts. Range is 0.414 to -0.414 volts for a range of 0 to 14 pH0v corresponds to a pH of 7.0Please view the Phidget’s Product Manual to determine if functionality varies from this document.
PHChangeTrigger:Number [get/set] Gets the amount of change that should exist between the last reported value and the current value before an OnPHChange event is fired.For additional information see the Appendix on Change Triggers
Temperature:Number [set] Sets the ambient temperature of the PH sensor for increased accuracy.This value defaults to 20 degrees celcius which is applicable for most applications
Phidget PH Sensor Events com.phidgets.events.PhidgetDataEvent
onPH_ChangeAn event raised by the Phidget when the PH changes more than the PH Change Trigger threshold
PhidgetDataEvent(PhidgetDataEvent.PH_CHANGE, myPhidget:Phidget, ph:Number)ParametersPhidgetDataEvent.PH_CHANGE The type of event being raised by a Phidget.In this case a PH Change event
myPhidget:Phidget The Phidget object raising the event
ph:Number The current value of the PH sensor
PhidgetRFID
The PhidgetRFID is a component that provides a high-level programmer interface to control a PhidgetRFID device connected through a USB port.
With this component, the programmer can: Read Radio Frequency Identification tags that use the EM4102 125Khz protocol•
Radio Frequency Identification or RFID, is a non-contact identification technology which uses a reader to read data stored on low cost tags.
The particular instance of the technology we use stores a 40-bit number on the tag. Every tag that is purchased from Phidgets Inc. is guaranteed unique.
When a RFID tag is read, the component returns the unique number contained in the RFID tag.
Class: PhidgetRFIDPackage: com.phidgetsExtends: Phidget
Specialised class for PhidgetRFID device interaction
PropertiesNumberOfOutputs:int [get] Returns the number of outputs on this particular Phidget device.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
LastTag:String[get] The RFID tag value of the Last Tag to come within range of the tag reader
Antenna:Boolean [get/set] Sets the state of the antenna to True or False.Please view the Phidget’s Product Manual to determine if functionality varies from this document.
LED:Boolean [get/set] Sets the state of the LED to True or False.Please view the Phidget’s Product Manual to determine if functionality varies from this document.
TagPresent:Boolean [get] Whether or not an RFID tag is currently present
Phidget RFID Methods
PhidgetRFID.getOutputStateReturns the state of the designated digital output as True or False.
Depending on the type of output available, the specified output goes to a high value or completes a connection.
Note that this value defaults to PUNKNOWN. Applications not wishing to see this value should use Change Handlers instead of polling the device for data.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
getOutputState(index:int):BooleanInputindex:int Index of the output to query
Outputreturn value:Boolean Current value of the output
PhidgetRFID.setOutputStateSets the state of the designated output to True or False.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
setOutputState(index:int, val:Boolean):voidInputindex:int Index of the output to set
val:Boolean New value of the output
Phidget RFID Events com.phidgets.events.PhidgetDataEvent
onTagAn event raised when a compatible RFID tage comes within range of the PhdigetRFID device
PhidgetDataEvent (PhidgetDataEvent.TAG, myPhidget:Phidget, Tag:String)ParametersPhidgetDataEvent.TAG The type of event being raised by the Phidget
In this case a Tag detection event
myPhidget:Phidget The Phidget object raising the event
Tag:String The Internal Tag value of the last RFID tag to come within range of the PhidgetRFID device
onTagLossAn event raised when a compatible RFID tag leaves the detection range of the PhidgetRFID device
PhidgetDataEvent( PhidgetDataEvent.TAG_LOST, myPhidget:Phidget, Tag:String)ParametersPhidgetDataEvent.TAG_LOST The type of event being raised by the Phidget. In this case a Tag Loss event
myPhidget:Phidget The Phidget object raising the event
Tag:String The Internal Tag value of the RFID leaving range of the PhidgetRFID device
onOutputChangeAn event raised when an output is changed.
PhidgetDataEvent( PhidgetDataEvent.OUTPUT_CHANGE, myPhdiget:Phidget, output:Boolean, index:int)ParametersPhidgetDataEvent.OUTPUT_CHANGE The type of event being raised by the Phidget.
In this case an Output Change event
myPhdiget:Phidget The Phidget object raising the event
output:Boolean The current state of the output
index:int The index of the output raising the event
PhidgetServo
The PhidgetServo is a component that provides a high-level programmer interface to control a PhidgetServo device connected through a USB port.
With this component, the programmer can: Set the desired position for a servo motor, ranging from 0 to 180 degrees.•
Class: PhidgetServo Package: com.phidgetsExtends: Phidget
Specialised class for PhidgetServo device interaction
PropertiesNumberOfMotors: int [get] Returns the maximum number of motors on this particular Phidget device.
This depends on the actual hardware. Please see the hardware description for the details of device variations.Note that there is no way of programmatically determining how many motors are actually plugged into the hardware.
Phidget Servo Methods
PhidgetServo.getMotorPositionGets the desired servo motor position for a particular servo motor.
Note that this defaults to -23. Applications not wishing to see this value should use Change Handlers instead of polling the device for data.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
getMotorPosition(index:int):NumberInputindex:int Index of the motor to query for position
Outputreturn value:Number Value of the Motor's current position
PhidgetServo.setMotorPositionSets the desired servo motor position for a particular servo motor.
This value may range from -23 to 231, corresponding to time width of the control pulse, the angle that the Servo motor moves to depends on the characteristic of individual motors.
Please read the PhidgetServo documentation to understand what behaviour you can expect from your motors.
setMotorPosition(index:int, val:Number):voidInputindex:int Index of the Motor to set
val:Number New value for position
PhidgetServo.setMotorOffTurns a Motor On & Off
setMotorOff(index:int):voidInputindex:int Index of a Motor to toggle
Phidget Servo Events com.phidgets.events.PhidgetDataEvent
onPositionChangeAn event raised when a Servo's Position changes
PhidgetDataEvent( PhidgetDataEvent.POSITION_CHANGE, myPhidget:Phidget, position:Number, index:int)ParametersPhidgetDataEvent.POSITION_CHANGE The type of event being raised the Phidget.
In this case Position Change event
myPhdiget:Phidget The Phidget object raising the event
position:Number The current position of the Servo
index:int The index of the Servo raising the event
PhidgetTemperatureSensor
The PhidgetTemperatureSensor is a component that provides a high-level programmer interface to control a PhidgetTemperatureSensor device connected through a USB port.
With this component, the programmer can: Read the temperature of Thermocouple device.•Read cold junction temperature.•Get notification of temperature change.•
Class: PhidgetTemperatureSensor Package: com.phidgetsExtends: Phidget
Specialised class for PhdigetTemperatureSensor interaction
PropertiesNumberOfTemperatureInputs:int [get] Returns the number of temperature inputs.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
Phidget Temperature Sensor Methods
PhidgetTemperatureSensor.getPotentialReturns the current potential of the Thermocouple in volts.
Range is -0.0065 to 0.0550 milliVolts for a range of -260 °C to 1372 °C
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
getPotential(index:int):NumberInputindex:int Index of the sensor to query
Outputreturn value:Number Current value of the Sensor's potential
PhidgetTemperatureSensor.getTemperatureReturns the current temperature in Celsius or Fahrenheit (depending on UseImperial property).
Index = 0 returns the temperature of the cold junction.
Index = 1 returns the temperatrue of the thermocouple.
Note that this value defaults to -500. Applications that do not wish to see this value should use Change Handlers instead of polling the device for data.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
getTemperature(index:int):NumberInputindex:int Index of the sensor to query
Outputreturn value:Number Current temperature of the sensor
PhidgetTemperatureSensor.getTemperatureChangeTriggerGets the amount of change that should exist between the last reported value and the current value before an OnTemperatureChange event is fired.
For additional information see the Appendix on Change Triggers.
getTemperatureChangeTrigger(index:int):NumberInputindex:int Index of the sensor to query for change trigger
Outputreturn value:Number Current value of the change trigger
PhidgetTemperatureSensor.setTemperatureChangeTriggerSpecifies the amount of change that should exist between the last reported value and the current value before an OnTemperatureChange event is fired.
For addtional information see the Appendix on Change Triggers.
setTemperatureChangeTrigger(index:int, val:Number):voidInputindex:int Index of the sensor to set a change trigger on
val:Number New value for the change trigger
Phidget Temperature Sensor Events com.phidgets.events.PhidgetDataEvent
onTemperatureChangeAn event raised when the Temperature exceeds the Temperature Change Trigger threshold
PhidgetDataEvent ( PhidgetDataEvent.TEMPERATURE_CHANGE, myPhidget:Phidget, temperature:Number, index:int)ParametersPhidgetDataEvent.TEMPERATURE_CHANGE The type of event being raised by the Phidget.
In this case a Temperature Change event
myPhidget:Phidget The Phidget object raising the event
temperature:Number The current value of the Temperature
inddex:int The index of the Temperature sensor raising the event
PhidgetTextLCD
The PhidgetTextLCD is a component that provides a high-level programmer interface to control a PhidgetTextLCD device connected through a USB port.
With this component, the programmer can: Display text on a PhidgetTextLCD module.•
Class: PhidgetTextLCD Package: com.phidgetsExtends: Phidget
Specialised calss for PhidgetTextLCS device interation
PropertiesNumberOfRows:int [get] Returns number of rows of text that may be presented on the display.
NumberOfColumns:int [get] Returns number of columns of text that may be used on the display.
Backlight:Boolean [get/set] Determines if the backlight for this LCD is on or off.Note that this defaults to True
Cursor:Boolean [get/set] Determines if the cursor is on or off.Note that this defaults to False
CursorBlink:Boolean [get/set] Determines if the cursor's blinking is on or off.Note that this defaults to False
Contrast:int [get/set] Gets the contrast value from 0-255.Note that this defaults to 0
Phidget Text LCD Methods
PhidgetTextLCD.setDisplayStringSets the text to display on a particular row of the display. The text will be clipped at the right edge of the display.
Please view the Phidget’s Product Manual to determine if functionality varies from this document.
setDisplayString(index:int, val:String):voidInputindex:int+ Row to set string to
val:String ASCII string to display
PhidgetTextLCD.setCustomCharacterSets a custom character.
With existing hardware, there is space for 8 custom characters : Index can range from 8 to 15.
Each character is described by a set of integers.
For more information, have a look at the TextLCD example in the examples.zip for Phidget21.
setCustomCharacter(index:int, val1:int, val2:int):void Inputindex:int Custom Character Index
val1:int Part 1 of Character Description Field
val2:int Part 2 of Character Description Field
The Phidget Dictionary
The Phidget Dictionary is a service provided by the Phidget Webservice. The Webservice maintains a centralized dictionary of key-value pairs that can be accessed and changed from any number of clients through the PhidgetDictionary object.
Note that the Webservice uses this dictionary to control access to Phidgets through the openRemoteIP interface, and as such, you should never add or modify a key that starts with /PSK/ or /PCK/, unless you want to explicitly modify Phidget specific data – and this is highly discouraged, as it’s very easy to break things. Listening to these keys is fine if so desired.
The intended use for the dictionary is as a central repository for communication and persistent storage of data between several client applications. As an example - a higher level interface exposed by one application – which controls the Phidgets, for others to access – rather then every client talking directly to the Phidgets themselves.
The dictionary makes use of extended regular expressions for key matching. See the end of this document for the rules of regular expressions.
Class: PhidgetDictionaryPackage: com.phidgetsExtends: EventDispatcher
Specialised class for interaction with the Phidget Dictionary webservice
PropertiesServerID:String [get] DNS Name of the Server
Port:int [get] Port of the Webservice running on the server
Address:String [get] IP Address of the Server
isConnected:Boolean [get] Whether the Phidget is physically connected or not
Phidget Dictionary Methods
PhidgetDictionary.openOpens a connection to the Dictionary service on the specified webserver
open (address:String, port:Number, password:String):voidInputaddress:string IP Address of the Server
port:Number Port of the Webservice running on the server
password:String Password to the WebserviceThe Password may be empty if a password is not used on the webservice
PhidgetDictionary.closeCloses the file handles for this device. You should always call this when finished with a Dictionary.
close():void
PhidgetDictionary.addKeyAdds a new key to the Dictionary, or modifies the value of an existing key.
The key can only contain numbers, letters, ‘/’, ‘.’, ‘-‘, ‘_’, and must begin with a letter, ‘_’ or ‘/’.
The value can contain any value.
The persistent value controls whether a key will stay in the dictionary after the client that created it disconnects. If persistent == 0, the key is removed when the connection closes. Otherwise the key remains in the dictionary until it is explicitly removed.
addKey(key:String, value:String, persistent:Boolean):void Inputkey:String Key Tag name
value:String Value of Key
persistent:Boolean Whether or not to keep the key in the Dictionary after session has completedThis defaults to True
PhidgetDictionary.removeKeyRemoves a key, or set of keys, from the Dictionary.
The key name is a regular expressions pattern, and so care must be taken to only have it match the specific keys you want to remove.
removeKey(pattern:String):voidInputpattern:String A regular expression by which to match keys
Phidget Dictionary Events flash.events.Event com.phidgets.events.PhidgetEvent com.phidgets.events.PhidgetErrorEvent
onConnectedAn event raised by a PhidgetDictionary object when it has connected to a remote Dictionary Service, ie. after an Open request.
PhidgetDictionaryEvent (PhidgetDictionaryEvent.CONNECT, myDictionary:PhidgetDictionary, key:String, value:String )ParametersPhidgetDictionaryEvent.CONNECT The type of event being raised by the PhidgetDictionary object.
In this case a Connect event
myDictionary:PhidgetDictionary The PhidgetDictionary object raising the event.
key:String=null A string value containing a Key code.
value:String=null A string value containing a Key value.
onDisconnectedAn event raised by a PhidgetDictionary object when it has been disconnected from the remote Dictionary Service
PhidgetDictionaryEvent (PhidgetDictionaryEvent.DISCONNECT, myDictionary:PhidgetDictionary, key:String, value:String)ParametersPhidgetDictionaryEvent.DISCONNECT The type of event being raised by the PhidgetDictionary object.
In this case a Disconnect event
myDictionary:PhidgetDictionary The PhidgetDictionary object raising the event.
key:String=null A string value containing a Key code.
value:String=null A string value containing a Key value.
onErrorAn event raised by a Phidget object when it encounters an error, either in the parameters of a request made to the object or an error being raised by the Phidget device itself.
PhidgetErrorEvent (PhidgetErrorEvent.ERROR, myphidget:Phidget, error:PhidgetError)ParametersPhidgetErrorEvent:ERROR The type of event raised by the Phidget. In this case an Error event
myphidget:Phidget The Phidget object that raised the event
error:PhidgetError The error code being raised. Corresponds to one of the PhidgetErrorsSee the Appendices for a list of these error codes.
onKeyChangeAn event raised by a PhidgetDictionary object when a Key it is monitoring is changed.
PhidgetDictionaryEvent (PhidgetDictionaryEvent.KEY_CHANGE, myDictionary:PhidgetDictionary, key:String, value:String)ParametersPhidgetDictionaryEvent.KEY_CHANGE The type of event being raised by the PhidgetDictionary object.
In this case a Key Change event
myDictionary:PhidgetDictionary The PhidgetDictionary object raising the event.
key:String=null A string value containing a Key code.
value:String=null A string value containing a Key value.
onKeyRemovalAn event raised by a PhidgetDictionary object when a key it is monitoring is Removed.
PhidgetDictionaryEvent (PhidgetDictionaryEvent.KEY_REMOVAL, myDictionary:PhidgetDictionary, key:String, value:String)ParametersPhidgetDictionaryEvent.KEY_REMOVAL The type of event being raised by the PhidgetDictionary object.
In this case a Key Removal event
myDictionary:PhidgetDictionary The PhidgetDictionary object raising the event.
key:String=null A string value containing a Key code.
value:String=null A string value containing a Key value.
The Phidget ManagerThe Phidget manager is an interface that allows for monitoring of all phidgets connected to a system, without opening them.
Class: PhidgetManagerPackage: com.phidgetsExtends: EventDispatcher
Specialised class for device interaction via the Phidget Manager
PropertiesServerID:String [get] The DNS name of the server
Port:int [get] The Port of the Webservice running on the server
Address:String [get] Address of the server
isConnected:Boolean [get] Whether or not the phidget is physically connected
Phidget Manager Methods
PhidgetManager.openOpens a connection to the local Phidget Manager.
The CPhidgetManagerHandle should be a valid handle previously allocated by CphidgetManager_create.
Before calling CPhidgetManager_open, we recommend registering the event handlers your application will use.
open (address:String, port:Number, password:String):voidParametersaddress:string IP Address of the Server
port:Number Port of the Webservice running on the Server
password:String Password for the WebservicePassword may be empty if a password is not used on the webservice
PhidgetManager.closeCloses a Phidget opened via PhidgetManager
close():void
Phidget Manager Events flash.events.Event com.phidgets.events.PhidgetManagerEvent com.phidgets.events.PhidgetErrorEvent
onConnectedAn event raised by the Phidget Manager when it has connected to a Server
PhidgetManagerEvent(PhidgetManagerEvent.CONNECT, myphidget:Phidget)ParametersPhidgetManagerEvent.DETACH The type of event raised by the Phidget.In this case a Connect event
myphidget:Phidget The Phidget object that raised the event
onDisconnectedAn event raised by the Phidget Manager when it has disconnected from a Server
PhidgetManagerEvent(PhidgetManagerEvent.DISCONNECT, myphidget:Phidget)ParametersPhidgetManagerEvent.DISCONNECT The type of event raised by the Phidget.In this case a Disconnect event
myphidget:Phidget The Phidget object that raised the event
onErrorAn event raised by a Phidget object when it encounters an error, either in the parameters of a request made to the object or an error being raised by the Phidget device itself.
PhidgetErrorEvent (PhidgetErrorEvent.ERROR, myphidget:Phidget, error:PhidgetError)ParametersPhidgetErrorEvent:ERROR The type of event raised by the Phidget. In this case an Error event
myphidget:Phidget The Phidget object that raised the event
error:PhidgetError The error code being raised. Corresponds to one of the PhidgetErrorsSee the Appendices for a list of these error codes.
onAttachAn event raised by the Phidget Manager when a Phidget Device is physically connected to the host machine
PhidgetManagerEvent(PhidgetManagerEvent.ATTACH, myphidget:Phidget)ParametersPhidgetManagerEvent.ATTACH The type of event raised by the Phidget.In this case an Attach event
myphidget:Phidget The Phidget object that raised the event
onDetachAn event raised by the Phidget Manager when a Phidget Device is physically disconnected from the host machine
PhidgetManagerEvent(PhidgetManagerEvent.DETACH, myphidget:Phidget)ParametersPhidgetManagerEvent.DETACH The type of event raised by the Phidget.
In this case an Detach event
myphidget:Phidget The Phidget object that raised the event
Appendix I: Regular Expressions Regular Expressions are used with the Phidget Dictionary Object to perform Key Matching.They are a powerful method for performing searchs that can vary from extremely specific to extremely general matches. Please see the Examples for additional information on using the Dictionary object and Regular Expressions (available on the Downloads page from http://Phidgets.com )
Definitions:
. Matches any single character. Into [ ] this character has its habitual meaning.
[ ] Matches a single character that is contained within the brackets. For example, [abc] matches "a", "b", or "c".
[a-z] matches any lowercase letter. These can be mixed: [abcq-z] matches a, b, c, q, r, s, t, u, v, w, x, y, z, and so does [a-cq-z].
The '-' character should be literal only if it is the last or the first character within the brackets: [abc-] or [-abc].
To match an '[' or ']' character, the easiest way is to make sure the closing bracket is first in the enclosing square brackets: [][ab] matches ']', '[', 'a' or 'b'.
[^ ] Matches a single character that is not contained within the brackets. For example, [^abc] matches any character other than "a", "b", or "c". [^a-z] matches any single character that is not a lowercase letter. As above, these can be mixed.
^ Matches the start of the line (or any line, when applied in multiline mode)
$ Matches the end of the line (or any line, when applied in multiline mode)
( ) Defines a "marked subexpression". What the enclosed expression matched can be recalled later. See the next entry, \n. Note that a "marked subexpression" is also a "block". Note that this is not found in some instances of regex.
\n Where n is a digit from 1 to 9; matches what the nth marked subexpression matched. This construct is theoretically irregular and has not been adopted in the extended regular expression syntax.
* A single character expression followed by "*" matches zero or more copies of the expression. For example, "[xyz]*" matches "", "x", "y", "zx", "zyx", and so on.
\n*, where n is a digit from 1 to 9, matches zero or more iterations of what the nth marked subexpression matched. For example, "(a.)c\1*" matches "abcab" and "abcabab" but not "abcac".An expression enclosed in "\(" and "\)" followed by "*" is deemed to be invalid. In some cases (e.g. /usr/bin/xpg4/grep of SunOS 5.8), it matches zero or more iterations of the string that the enclosed expression matches. In other cases (e.g. /usr/bin/grep of SunOS 5.8), it matches what the enclosed expression matches, followed by a literal "*".
+ A single character expression followed by "+" matches one or more copies of the expression. For example, "[xyz]+" matches "x", "y", "zx", "zyx", and so on.
\n+, where n is a digit from 1 to 9, matches one or more iterations of what the nth marked subexpression matched.
An expression enclosed in "\(" and "\)" followed by "+" is deemed to be invalid.
{x,y} Match the last "block" at least x and not more than y times. For example, "a\{3,5\}" matches "aaa", "aaaa" or "aaaaa". Note that this is not found in some instances of regex.
Extended Regular Expressions:
+ Match the last "block" one or more times - "ba+" matches "ba", "baa", "baaa" and so on
? Match the last "block" zero or one times - "ba?" matches "b" or "ba"
| The choice (or set union) operator: match either the expression before or the expression after the operator - "abc|def" matches "abc" or "def".Also, backslashes are removed: \{...\} becomes {...} and \(...\) becomes (...). Examples: "[hc]+at" matches with "hat", "cat", "hhat", "chat", "hcat", "ccchat" etc. "[hc]?at" matches "hat", "cat" and "at" "([cC]at)|([dD]og)" matches "cat", "Cat", "dog" and "Dog"
Since the characters '(', ')', '[', ']', '.', '*', '?', '+', '^' and '$' are used as special symbols they have to be escaped if they are meant literally. This is done by preceding them with '\' which therefore also has to be escaped this way if meant literally. Examples: "a\.(\(|\))" matches with the string "a.)" or "a.("
Appendix II: Error Codes and DescriptionsError Code Value Error DescriptionPHIDGET_NOTFOUND 1 "A Phidget matching the type and or se-
rial number could not be found."This indicates that a Phidget being searched for (ie. via Open) could not be located.
PHIDGET_NOMEMORY 2 "Memory could not be allocated."This indicates that there is not enough memory for the Phidgets library to create the object requested.
PHIDGET_UNEXPECTED 3 "Unexpected Error. Contact Phidgets Inc. for support."Indicates that a serious error has oc-curred, or a severe bug exists within the library.
PHIDGET_INVALIDARG 4 "Invalid argument passed to function."An argument is not valid to the require-ments of the function. In many cases this refers to an invalid Phidget Handle.
PHIDGET_NOTATTACHED 5 "Phidget not physically attached."Indicates the function requires an attached Phidget to operate.
PHIDGET_INTERRUPTED 6 "Read/Write operation was interrupted"An error occurred while attempting to com-municate with the Phidget over USB.
PHIDGET_INVALID 7 "The Error Code is not defined."Indicates that a serious error has oc-curred, or a severe bug exists within the library.
PHIDGET_NETWORK 8 "Network Error."Attempting to communicate with the Phidget via the Network has failed.
PHIDGET_UNKNOWNVAL 9 "Value is Unknown (State not yet received from device)."A query to a value on the Phidget device has failed as the Phidget has not returned data yet.
PHIDGET_BADPASSWORD 10 "Authorization Failed."The remote access method has failed it’s authorization.
PHIDGET_UNSUPPORTED 11 "Not Supported"This is a bad or unsupported function call.
Error Code Value Error DescriptionPHIDGET_DUPLICATE 12 "Duplicated request"
A previous request to the device has al-ready performed this function, and it is not valid to perform twice.
PHIDGET_TIMEOUT 13 "Given timeout has been exceeded"A synchronous request has failed it’s time limits. Usually this is returned when at-tempting WaitForConnect.
PHIDGET_OUTOFBOUNDS 14 "Index out of Bounds"An index into the function is above or below the recognized bounds of the device. ie. when accessing a single sensor on a multi-sensor device.
PHIDGET_EVENT 15 "A non-null error code was returned from an event handler"An error code was passed to a function handler. Note that correct decoding of the actual error would have to be done within the event handler itself.
PHIDGET_NETWORK_NOTCONNECTED 16 "A connection to the server does not ex-ist."An attempt to connect to a remotely con-nected device or service failed due to net-work connectivity problems.
PHIDGET_WRONGDEVICE 17 "Function is not applicable for this de-vice."The wrong type of device handle was passed as an argument to a function. (ie. calling CPhidgetWeightSensor_getWeight with an Accelerometer handle)
Appendix III: Special Values
The Phidgets Library uses some special values internally to track things that are not de-fined in the Actionscript 3.0 language or applicable only to Phidget devices.
Group Constant Name Value DescriptionAttachment State PHIDGET_ATTACHED 0x1 The Phidget has been at-
tachedPHIDGET_NOTATTACHED 0x0 The Phidget is not at-
tachedPHIDGET_CONNECTIONERROR 0x2 The Phidget experienced
a connection error
Booleans PFALSE 0x00 Evaluate as FALSE
PTRUE0x01 Evaluate as TRUE
PUNK 0x02 Evaluate as UNKNOWN
Appendix IV: Event Handlers
Event Handlers are used to notify your application that a noteworthy event has occured with a Phidget. By creating a function accepting the proper parameters (the Event Handler), and registering that function with the library, the library is able to call your function whenever events occur.
Because your Event Handler can be run at anytime, it's best to register them before calling Phidget.open().
Event Handlers have to conform to a standard that the Phidget library understands. As a minimum, all callbacks have a Phidget Object, and an Event Type as arguments.
The Phidget Object argument provides a link to the Phidget that raised the event. This allows properties of the Phidget to be avaluated within the Callback.
The Event Type identifies the kind of event being fired, this allows the user to make a choice of how to handle the event.
Setting up an Event Handler involves:
Setting up a Phidget object1. Creating a function to handle your event2. Passing the type of event to trigger on3. Passing the name of the function to call when4.
Please see the Examples for additional information on using Event Handlers (available on the Downloads page from http://Phidgets.com )
Event Handler Exampleimport com.phidgets.*;import com.phidgets.events.*;var blnInit;var myPhidget:Phidget;function onAttach(evt:PhidgetEvent):void{ trace(evt);}if (blnInit != true) { trace('Performing Initialisation'); myPhidget= new PhidgetInterfaceKit(); myPhidget.addEventListener(PhidgetEvent.ATTACH, onAttach); myPhidget.open("localhost", 5001); blnInit = true;}
Create Phidget Object
Register Event Handlers
Open Phidget
Device creates attach event
Event Handlerfires
User function performs
processing and returns
Wait for attach event
Appendix V: Change Triggers
Change Triggers are used to filter the number of events that are returned to an Application, by setting a minimum amount of activity before a Change Event is sent to the Client.
The Change Trigger routine uses 3 values.
i) The Last Reported (or default) value is used as the reference point by which to compare future values.
ii) The Last Reported value + & --- the Change Trigger value provide the valid range of values before a Change event is fired
iii) The Current Data value, is com-pared to the valid range of operation to de-termine whether a Change Event is fired
When each new data point is acquired by the Phidget, it must answer several questions:
i) Is the New Value > (Last Reported Value + Change Trigger)? ii) Is the New Value < (Last Reported Value - Change Trigger)?
If either is True:
i) Reported Value is updated to the Current Data value ii) Change Event is fired
Value
Time
Reported Value
Last Value + Change Trigger
Change Event
Last Value –Change Trigger
Actual Value
Appendix VII: Generating Custom CharactersThis is only a simple example showing how to generate custom characters. For detailed information please see your Phdget manual.
For an easy method to generate characters without the formula, visit http://www.phidgets.com/documentation/customchar.html
Each Custom Character is comprised of two numbers; one for the top 4 rows of pixels, one for the bottom 4 rows of pixels.
They are evaluated as powers of 2 from the top right corner going left and continuing at the left side of each row.
Value 1 (Upper Half):
=2^1 + 2^2 + 2^3 + 2^5 + 2^6 + 2^7 + 2^8 + 2^9 + 2^10 + 2^12 + 2^14 + 2^15 + 2^16 + 2^17 + 2^18 + 2^19
= 103818
Value 2 (Lower Half):
=2^0 + 2^2 + 2^4 + 2^5 + 2^9 + 2^10 + 2^11 + 2^12 + 2^13 + 2^14 + 2^16 + 2^17 + 2^18
= 491061