Notice: This page contains information for the legacy Phidget21 Library. Phidget21 is out of support. Bugfixes may be considered on a case by case basis. Phidget21 does not support VINT Phidgets, or new USB Phidgets released after 2020. We maintain a selection of legacy devices for sale that are supported in Phidget21. We recommend that new projects be developed against the Phidget22 Library.
|
Language - Adobe Director: Difference between revisions
No edit summary |
No edit summary |
||
Line 33: | Line 33: | ||
The Phidget object will be added to your cast, and you can then drag and drop it into the stage to create a sprite for it. | The Phidget object will be added to your cast, and you can then drag and drop it into the stage to create a sprite for it. | ||
Add a field control to your movie (Insert | Control | Field) for the purpose of capturing some simple output, as well as a button (Insert | Control | Button) labelled “Open” to get things started. | Add a field control to your movie (Insert | Control | Field) for the purpose of capturing some simple output, as well as a button (Insert | Control | Button) labelled “Open” to get things started. | ||
[[Image:Getting_Started_Director.gif|border]] | |||
===Coding For Your Phidget=== | ===Coding For Your Phidget=== | ||
Line 44: | Line 46: | ||
===Connecting to the Phidget=== | ===Connecting to the Phidget=== | ||
The program can try to connect to the Phidget through a call to open. Open will continuously | The program can try to connect to the Phidget through a call to open. Open will continuously try to connect to a Phidget, based on the parameters given, even trying to reconnect if it gets disconnected. | ||
try to connect to a Phidget, based on the parameters given, even trying to reconnect if it | This means that simply calling open does not guarantee you can use the Phidget immediately. | ||
gets disconnected. This means that simply calling open does not guarantee you can use the | We can account for a connection by using event driven programming and tracking the AttachEvents and DetachEvents, or by calling WaitForAttachment. | ||
Phidget immediately. We can account for a connection by using event driven programming | WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded. | ||
and tracking the AttachEvents and DetachEvents, or by calling WaitForAttachment. | Here, the Phidget is opened on clicking the Open button inside the mouseUp event. | ||
WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an | <div style="background-color: #f3f3f3; border-color: #1c9edb; border-width:1px; border-style: dashed;"> | ||
optional timeout is exceeded. Here, the Phidget is opened on clicking the Open button inside | <font size="3"> | ||
the mouseUp event. | <source lang=actionscript> | ||
on mouseUp me | on mouseUp me | ||
sprite(1).CallString("Open()") | sprite(1).CallString("Open()") | ||
sprite(1).CallString("WaitForAttachment(3000)") | sprite(1).CallString("WaitForAttachment(3000)") | ||
end | end | ||
The different parameters and open calls can be used to open the first Phidget of a type it can | </source> | ||
find, open based on a serial number, or even open across the network. The API manual lists | </font> | ||
all of the available modes that open provides. One important thing to remember is that when | </div> | ||
working with Phidgets, a local connection will reserve the device until closed. This prevents | |||
any other instances from retrieving data from the Phidget, including other programs. The one | The different parameters and open calls can be used to open the first Phidget of a type it can find, open based on a serial number, or even open across the network. | ||
connection per device limit does not apply when exclusively using the Phidget Webservice. | The API manual lists all of the available modes that open provides. | ||
You can use CallString(“Close”) at any time outside of the Phidget’s own event handlers to | One important thing to remember is that when working with Phidgets, a local connection will reserve the device until closed. | ||
close the connection. | This prevents any other instances from retrieving data from the Phidget, including other programs. | ||
Event Driven Programming | The one connection per device limit does not apply when exclusively using the Phidget Webservice. | ||
We recommend the use of event driven programming when working with Phidgets. This allows | You can use CallString(“Close”) at any time outside of the Phidget’s own event handlers to close the connection. | ||
the program to execute other tasks until the Phidget fires a new event. In Adobe director, you | |||
can hook an event handler inside a script for the Phidget object with the following code: | ===Event Driven Programming=== | ||
on OnSensorChange(Index, SensorValue) me | |||
We recommend the use of event driven programming when working with Phidgets. | |||
end | This allows the program to execute other tasks until the Phidget fires a new event. | ||
With this method, the code inside OnSensorChange will get executed every time the | In Adobe director, you can hook an event handler inside a script for the Phidget object with the following code: | ||
InterfaceKit reports a change on one of its analog inputs. | |||
Some events such as OnAttach and OnDetach belong to a base Phidget object and are | <div style="background-color: #f3f3f3; border-color: #1c9edb; border-width:1px; border-style: dashed;"> | ||
common to all types of Phidgets. Please refer to the API manual for a full list of events and | <font size="3"> | ||
their usage. | <source lang=actionscript> | ||
Working directly with the Phidget | |||
Some values can be directly read and set on the Phidget, and inside polling loops used as an | on OnSensorChange(Index, SensorValue) me | ||
alternative to event driven programming. Simply use the CallString such as SensorValue(Index) | member("OutputField").text = string(Index) & ": " & string(SensorValue) | ||
or OutputState(Index, OutputState) for InterfaceKits. | end | ||
sprite(1).CallString("OutputState(0,1)") | |||
Working with multiple Phidgets | </source> | ||
Multiple Phidgets of the same type can easily be run inside the same program. In our case, it | </font> | ||
requires another PhidgetInterfaceKit ActiveX object to be created and placed. The new object | </div> | ||
can then be set up, opened and used in the same process as the previous one. | |||
If the application needs to distinguish between the devices, open can be called with the serial | With this method, the code inside OnSensorChange will get executed every time the InterfaceKit reports a change on one of its analog inputs. | ||
number of a specific Phidget. | Some events such as OnAttach and OnDetach belong to a base Phidget object and are common to all types of Phidgets. | ||
Other Phidgets | Please refer to the API manual for a full list of events and their usage. | ||
The design given in this document can also be followed for almost all Phidgets. For example, | |||
if you were using a PhidgetRFID instead of an Interfacekit, you would place a PhidgetRFID | ===Working directly with the Phidget=== | ||
ActiveX object instead of a PhidgetInterfaceKit. The methods and events available would | |||
change but they can be accessed in a similar manner. | Some values can be directly read and set on the Phidget, and inside polling loops used as an alternative to event driven programming. | ||
Simply use the CallString such as SensorValue(Index) or OutputState(Index, OutputState) for InterfaceKits. | |||
<div style="background-color: #f3f3f3; border-color: #1c9edb; border-width:1px; border-style: dashed;"> | |||
<font size="3"> | |||
<source lang=actionscript> | |||
sprite(1).CallString("OutputState(0,1)") | |||
</source> | |||
</font> | |||
</div> | |||
===Working with multiple Phidgets=== | |||
Multiple Phidgets of the same type can easily be run inside the same program. | |||
In our case, it requires another PhidgetInterfaceKit ActiveX object to be created and placed. | |||
The new object can then be set up, opened and used in the same process as the previous one. | |||
If the application needs to distinguish between the devices, open can be called with the serial number of a specific Phidget. | |||
===Other Phidgets=== | |||
The design given in this document can also be followed for almost all Phidgets. | |||
For example, if you were using a PhidgetRFID instead of an Interfacekit, you would place a PhidgetRFID ActiveX object instead of a PhidgetInterfaceKit. | |||
The methods and events available would change but they can be accessed in a similar manner. | |||
==Building your Project== | ==Building your Project== |
Revision as of 16:02, 18 October 2011
Preamble about the language and its general strengths and weaknesses.
Assessment for use with Phidgets
Our honest opinion on how well this language is suited to controlling Phidgets. If it is a poor choice, suggest and link similar (better) languages.
Support
We provide minimal support to Adobe Director.
Restrictions
In this section, list any restrictions or limitations that this particular language may impose. For example, incompatibility with certain operating systems.
Development Environments and Compilers
Describe each major compiler and notable differences or important information. (eg. framework versions) If there are known issues/workarounds mention them and link to the corresponding issue at the bottom of the page.
Drivers, Libraries and Resources
Before you can run your program, you need to set up the proper environment and get the necessary files off the Phidgets website. Visit the drivers section at www.phidgets.com and get the latest:
You will need the Phidget Framework to use and to program with Phidgets. We also recommend that you download the following reference materials:
- API Manual
- Adobe Director sample code
- You can find a high level discussion about programming with Phidgets in general on the General API page.
- The Device Functionality page explains the general operational information for your device.
You may want to have these pages open while working through these instructions.
Getting Started
This tutorial was written for Adobe Director 11.5 in Lingo and assumes its use. Other versions of director should work as well, and each would be set up in a similar manner. First launch Director and generate a new movie file with a descriptive name such as PhidgetTest. Next, insert an ActiveX control (Insert | Control | ActiveX...) and add the “PhidgetInterfaceKit Class”. The Phidget object will be added to your cast, and you can then drag and drop it into the stage to create a sprite for it. Add a field control to your movie (Insert | Control | Field) for the purpose of capturing some simple output, as well as a button (Insert | Control | Button) labelled “Open” to get things started.
File:Getting Started Director.gif
Coding For Your Phidget
In this tutorial, the Phidget ActiveX object is assumed to be sprite 1 and the text field was given the member name “OutputField” to help distinguish it from the other objects. By double clicking an ActiveX object, Director will fully list its functionality. In Lingo, you can apply the functionality for an object’s sprite through CallStrings. The object name for any type of Phidget is also listed in the API manual. Every type of Phidget also shares some functionality from the base Phidget class.
Connecting to the Phidget
The program can try to connect to the Phidget through a call to open. Open will continuously try to connect to a Phidget, based on the parameters given, even trying to reconnect if it gets disconnected. This means that simply calling open does not guarantee you can use the Phidget immediately. We can account for a connection by using event driven programming and tracking the AttachEvents and DetachEvents, or by calling WaitForAttachment. WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded. Here, the Phidget is opened on clicking the Open button inside the mouseUp event.
on mouseUp me
sprite(1).CallString("Open()")
sprite(1).CallString("WaitForAttachment(3000)")
end
The different parameters and open calls can be used to open the first Phidget of a type it can find, open based on a serial number, or even open across the network. The API manual lists all of the available modes that open provides. One important thing to remember is that when working with Phidgets, a local connection will reserve the device until closed. This prevents any other instances from retrieving data from the Phidget, including other programs. The one connection per device limit does not apply when exclusively using the Phidget Webservice. You can use CallString(“Close”) at any time outside of the Phidget’s own event handlers to close the connection.
Event Driven Programming
We recommend the use of event driven programming when working with Phidgets. This allows the program to execute other tasks until the Phidget fires a new event. In Adobe director, you can hook an event handler inside a script for the Phidget object with the following code:
on OnSensorChange(Index, SensorValue) me
member("OutputField").text = string(Index) & ": " & string(SensorValue)
end
With this method, the code inside OnSensorChange will get executed every time the InterfaceKit reports a change on one of its analog inputs. Some events such as OnAttach and OnDetach belong to a base Phidget object and are common to all types of Phidgets. Please refer to the API manual for a full list of events and their usage.
Working directly with the Phidget
Some values can be directly read and set on the Phidget, and inside polling loops used as an alternative to event driven programming. Simply use the CallString such as SensorValue(Index) or OutputState(Index, OutputState) for InterfaceKits.
sprite(1).CallString("OutputState(0,1)")
Working with multiple Phidgets
Multiple Phidgets of the same type can easily be run inside the same program. In our case, it requires another PhidgetInterfaceKit ActiveX object to be created and placed. The new object can then be set up, opened and used in the same process as the previous one. If the application needs to distinguish between the devices, open can be called with the serial number of a specific Phidget.
Other Phidgets
The design given in this document can also be followed for almost all Phidgets. For example, if you were using a PhidgetRFID instead of an Interfacekit, you would place a PhidgetRFID ActiveX object instead of a PhidgetInterfaceKit. The methods and events available would change but they can be accessed in a similar manner.
Building your Project
Describe the different ways a project could be built using this language.
Common Problems and Solutions/Workarounds
Here you can put various frequent problems and our recommended solutions.