Alert.png

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.


Click on the 2phidget22.jpg button in the menu bar to go to the Phidget22 version of this page.

Alert.png

Language - AutoIt: Difference between revisions

From Phidgets Legacy Support
(Created page with '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 …')
 
 
(37 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Preamble about the language and its general strengths and weaknesses.
[[Category:Language]]
{{OSLang|[[File:icon-Autoit.png|64x64px]]|[http://www.autoitscript.com/site/autoit/ AutoIt] is a general-purpose GUI scripting language for Windows.}}


==Assessment for use with Phidgets==
==Introduction==
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==
If this is your first time working with a Phidget, we suggest starting with the ''Getting Started'' page for your specific device. This can be found in the [[:Category:UserGuide|user guide]]. That page will walk you through installing drivers and libraries for your operating system, and will then bring you back here to use AutoIt specifically.
We provide [[Levels of Support|minimal]] support to AutoIt.


==Restrictions==
AutoIt is capable of using the complete Phidget API, including events. However, AutoIt has no Phidget examples for devices at this time.
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==
AutoIt can be developed with Windows XP/Vista/7.


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.  
You can compare AutoIt with our other [[Software Overview#Language Support|supported languages]].


==Drivers, Libraries and Resources==
==Quick Downloads==
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:
* [http://www.phidgets.com/drivers.php Phidget Framework]
You will need the Phidget Framework to use and to program with Phidgets. We also recommend that you download the following reference materials:
* [http://www.phidgets.com/documentation/COM_API_Manual.pdf API Manual]
The .NET API manual lists calls and events for every type of Phidget and can be used as a reference.
* At this time, we do not have sample code available for AutoIt.
* 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.
{{QuickDownloads|AutoIt|
{{APIQuickDownloads|{{SERVER}}/documentation/COM_API_Manual.pdf}}|
* None Provided |
{{WindowsQuickDownloads}}}}


==Getting Started==
==Getting Started with AutoIt==
Here we provide a basic setup guide and code samples to start a project from scratch.


==Building your Project==
Applications using Phidgets can be developed in AutoIt v3 through the COM API and this tutorial assumes its use.
Describe the different ways a project could be built using this language.
 
The Windows installers above in the [[#Quick Downloads|Quick Downloads]] section will install the Phidget framework and will register the necessary .dlls for you.
 
In lieu of example code, to begin in AutoIt you can create a new script file and open it with your preferred editor. Then, create a simple user interface to work with and then place an input control for the purpose of capturing some simple output:
 
<div class="source"><syntaxhighlight lang=autoit>
  #include <GUIConstantsEx.au3>
 
  GUICreate("Phidget Test")
  $InputControl = GUICtrlCreateInput("", 20, 40, 160)
  GUISetState(@SW_SHOW)
 
  ;Phidget initialization code goes here
 
  Do
    $msg = GUIGetMsg()
  Until $msg = $GUI_EVENT_CLOSE
 
  ;Phidget Event Handlers go here
 
</syntaxhighlight></div>
 
==Coding For Your Phidget==
 
There are additional references for writing AutoIt code:
 
{{UsingAPhidgetInCodeGeneral|both of which are available in AutoIt|[{{SERVER}}/documentation/COM_API_Manual.pdf COM API]}}
 
===Code Snippets===
 
Specific calls in AutoIt will differ in syntax from those on the [[General Phidget Programming]] page, but the concepts stay the same.
 
It may help to have the [[General Phidget Programming]] page and this section open at the same time, because they parallel each other and you can refer to the AutoIt syntax. However, many additional concepts are covered on the General Phidget Programming page on a high level, such as using multiple Phidgets, handling errors, and different styles of programming.
 
====Step One: Initialize and Open====
 
To open the Phidget, you must create the object from the Phidget21COM library at initialization. This can be accomplished through a call to ObjCreate. Then, we try to open the Phidget.  The open() call is simple most of the time, but it can also handle many different types of open (i.e. remote open using the [[Phidget WebService]], opening [[General Phidget Programming#Using Multiple Phidgets|multiple Phidgets]], etc).  For the details of open (and other functions on this page), refer to the [[General Phidget Programming|Opening the Phidget]] section on the General Phidget Programming page.
 
For example, we can declare, create, and open a PhidgetInterfaceKit with:
 
<div class="source"><syntaxhighlight lang=autoit>
 
  $oPhid1 = ObjCreate("Phidget21COM.PhidgetInterfacekit")
  $oPhid1.Open()
 
</syntaxhighlight></div>
 
The object name for any type of Phidget is listed in the [{{SERVER}}/documentation/COM_API_Manual.pdf COM API manual], as well as the variety of open calls available.  Every type of Phidget also shares some functionality with the base Phidget class.
 
====Step Two: Wait for Attachment (plugging in) of the Phidget====
 
An attached Phidget is one that is attached in hardware - i.e. plugged it.  We can account for this connection by waiting or by catching an AttachEvent.  WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded:
 
<div class="source"><syntaxhighlight lang=autoit>
 
  $oPhid1.WaitForAttachment(3000)
  If NOT $oPhid1.IsAttached Then
    MsgBox(0, "Error", "Phidget Device not attached")
  Exit
  EndIf
 
</syntaxhighlight></div>
 
One important thing to remember is that when working with Phidgets, a local connection will reserve the device until closed. This means only one program can access the Phidget locally.  Many computers can access one Phidget over the [[Phidget WebService]].
 
====Step Three: Do Things with the Phidget====
 
We recommend the use of event driven programming when working with Phidgets.
This allows the program to execute other tasks until the Phidget generates a new event.
In AutoIt, you enable event handlers for a Phidget at initialization with the following line: 
 
<div class="source"><syntaxhighlight lang=autoit>
 
  $oPhidEvents = ObjEvent($oPhid1, "phid1_")
 
</syntaxhighlight></div>
 
AutoIt will use the phidl1_ prefix we declared when looking for the handler to execute.
You can define the handler functions for events such as OnSensorChange or Attached elsewhere in your code:
 
<div class="source"><syntaxhighlight lang=autoit>
  Func phid1_OnSensorChange($Index, $SensorValue)
    GUICtrlSetData($InputControl, $SensorValue)
  EndFunc
 
</syntaxhighlight></div>
 
With this method, the code inside phid1_OnSensorChange will get executed every time the PhidgetInterfaceKit reports a change on one of its analog inputs.
Some events such as Attach and Detach belong to the base Phidget object and thus are common to all types of Phidgets.
Please refer to the API manual for a full list of events and their usage.
 
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 instance properties such as SensorValue(Index as Long) or OutputState(Index as Long) for PhidgetInterfaceKits.
 
<div class="source"><syntaxhighlight lang=autoit>
 
  $oPhid1.OutputState(0) = "true"
 
</syntaxhighlight></div>
 
Note that when setting booleans on the Phidget, it must be encapsulated in quotes.
Alternatively, you can usually use the integer value 0 for false and 1 for true.
 
====Step Four: Close and Delete====
 
Multiple Phidgets of the same type can easily be run inside the same program.
In our case, it requires another PhidgetInterfaceKit object to be defined and initialized.
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.
 
{{MoreHowTos}}


==Common Problems and Solutions/Workarounds==
==Common Problems and Solutions/Workarounds==
Here you can put various frequent problems and our recommended solutions.
 
None at this time.

Latest revision as of 18:18, 11 June 2014

Icon-Autoit.png AutoIt is a general-purpose GUI scripting language for Windows.

Introduction

If this is your first time working with a Phidget, we suggest starting with the Getting Started page for your specific device. This can be found in the user guide. That page will walk you through installing drivers and libraries for your operating system, and will then bring you back here to use AutoIt specifically.

AutoIt is capable of using the complete Phidget API, including events. However, AutoIt has no Phidget examples for devices at this time.

AutoIt can be developed with Windows XP/Vista/7.

You can compare AutoIt with our other supported languages.

Quick Downloads

Just need the AutoIt documentation, drivers, libraries, and examples? Here they are:

Documentation

Example Code

  • None Provided

Libraries and Drivers

Getting Started with AutoIt

Applications using Phidgets can be developed in AutoIt v3 through the COM API and this tutorial assumes its use.

The Windows installers above in the Quick Downloads section will install the Phidget framework and will register the necessary .dlls for you.

In lieu of example code, to begin in AutoIt you can create a new script file and open it with your preferred editor. Then, create a simple user interface to work with and then place an input control for the purpose of capturing some simple output:

  #include <GUIConstantsEx.au3>

  GUICreate("Phidget Test")
  $InputControl = GUICtrlCreateInput("", 20, 40, 160)
  GUISetState(@SW_SHOW)

  ;Phidget initialization code goes here

  Do
     $msg = GUIGetMsg()
  Until $msg = $GUI_EVENT_CLOSE

  ;Phidget Event Handlers go here

Coding For Your Phidget

There are additional references for writing AutoIt code:

  • COM API (This is the complete set of functions you have available for all Phidgets)
  • Device Specific APIs - The one for your Phidget can be found in its user guide.

To learn the details behind opening, configuring, using, and closing your Phidget, try the General Phidget Programming page. That page also describes using the Phidget in an event-driven manner and in a traditional manner, both of which are available in AutoIt.

Code Snippets

Specific calls in AutoIt will differ in syntax from those on the General Phidget Programming page, but the concepts stay the same.

It may help to have the General Phidget Programming page and this section open at the same time, because they parallel each other and you can refer to the AutoIt syntax. However, many additional concepts are covered on the General Phidget Programming page on a high level, such as using multiple Phidgets, handling errors, and different styles of programming.

Step One: Initialize and Open

To open the Phidget, you must create the object from the Phidget21COM library at initialization. This can be accomplished through a call to ObjCreate. Then, we try to open the Phidget. The open() call is simple most of the time, but it can also handle many different types of open (i.e. remote open using the Phidget WebService, opening multiple Phidgets, etc). For the details of open (and other functions on this page), refer to the Opening the Phidget section on the General Phidget Programming page.

For example, we can declare, create, and open a PhidgetInterfaceKit with:

  $oPhid1 = ObjCreate("Phidget21COM.PhidgetInterfacekit")
  $oPhid1.Open()

The object name for any type of Phidget is listed in the COM API manual, as well as the variety of open calls available. Every type of Phidget also shares some functionality with the base Phidget class.

Step Two: Wait for Attachment (plugging in) of the Phidget

An attached Phidget is one that is attached in hardware - i.e. plugged it. We can account for this connection by waiting or by catching an AttachEvent. WaitForAttachment will block indefinitely until a connection is made to the Phidget, or an optional timeout is exceeded:

  $oPhid1.WaitForAttachment(3000)
  If NOT $oPhid1.IsAttached Then
     MsgBox(0, "Error", "Phidget Device not attached")
  Exit
  EndIf

One important thing to remember is that when working with Phidgets, a local connection will reserve the device until closed. This means only one program can access the Phidget locally. Many computers can access one Phidget over the Phidget WebService.

Step Three: Do Things with the Phidget

We recommend the use of event driven programming when working with Phidgets. This allows the program to execute other tasks until the Phidget generates a new event. In AutoIt, you enable event handlers for a Phidget at initialization with the following line:

  $oPhidEvents = ObjEvent($oPhid1, "phid1_")

AutoIt will use the phidl1_ prefix we declared when looking for the handler to execute. You can define the handler functions for events such as OnSensorChange or Attached elsewhere in your code:

 
  Func phid1_OnSensorChange($Index, $SensorValue)
     GUICtrlSetData($InputControl, $SensorValue)
  EndFunc

With this method, the code inside phid1_OnSensorChange will get executed every time the PhidgetInterfaceKit reports a change on one of its analog inputs. Some events such as Attach and Detach belong to the base Phidget object and thus are common to all types of Phidgets. Please refer to the API manual for a full list of events and their usage.

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 instance properties such as SensorValue(Index as Long) or OutputState(Index as Long) for PhidgetInterfaceKits.

  $oPhid1.OutputState(0) = "true"

Note that when setting booleans on the Phidget, it must be encapsulated in quotes. Alternatively, you can usually use the integer value 0 for false and 1 for true.

Step Four: Close and Delete

Multiple Phidgets of the same type can easily be run inside the same program. In our case, it requires another PhidgetInterfaceKit object to be defined and initialized. 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.

More How-To's

The General Phidget Programming page gives more information about:

Common Problems and Solutions/Workarounds

None at this time.