Phidget Manager: Difference between revisions

From Phidgets Support
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 2: Line 2:
==General Overview==
==General Overview==


The Phidget Manager is an interface into the device channels available to the Phidget library.  The API is strictly asynchronous, a continuously monitors channels as they attach and detach.  Each Phidget exports one or more device channels, and when a Phidget is plugged into a system (or become available over the network), an attach event is fired for each channel available on that Phidget.  
The Phidget Manager is an interface into the device channels available to the Phidget library.  The API is strictly asynchronous, and continuously monitors channels as they attach and detach.


It is important to understand the concepts of '''attach''' and '''detach''' as the they relate to the manager.  A manager attach does not imply that a user channel has attached to a device channel, but that the device channel have become available.  The device channel is now ready to be attached to a user channel.  When a user channel closes and detaches from a device channel a manager event will not be fired.  A manager '''detach''' event is fired when the Phidget device is removed from the system.
Each Phidget exports one or more device channels, and when a Phidget is plugged into a system (or becomes available over the network), a manager attach event is fired for each channel available from the Phidget.  When the Phidget is removed from the system, a manger detach event is fired for each channel that is no longer available.
 
It is important to understand the concepts of '''attach''' and '''detach''' as the they relate to the manager.  A manager attach does not imply that a user channel has attached to a device channel, but that the device channel has ''appeared'', and the device channel is now ready to be attached to a user channel.  When a user channel closes and detaches from a device channel, a manager event is not fired.  A manager '''detach''' event is fired when the Phidget is removed from the system.


==Purpose==
==Purpose==
Line 10: Line 12:
The primary function of a Phidget Manager is to fire an attach event for each new device channel when a Phidget becomes available to a system, and to fire a detach event for each device channel that is no longer available when the Phidget is removed from the system.  For example, when a 1044_0 - PhidgetSpatial is connected, a Phidget Manager would fire three attach events, one for each device channel, as illustrated below:
The primary function of a Phidget Manager is to fire an attach event for each new device channel when a Phidget becomes available to a system, and to fire a detach event for each device channel that is no longer available when the Phidget is removed from the system.  For example, when a 1044_0 - PhidgetSpatial is connected, a Phidget Manager would fire three attach events, one for each device channel, as illustrated below:


[[Image:manager22.jpg|link=|1000px|alt=]]
[[Image:manager22.jpg|link=|850px|alt=]]


==Using the Phidget Manager==
==Using the Phidget Manager==
Line 26: Line 28:


static void CCONV
static void CCONV
mgrAttachHandler(PhidgetManagerHandle mgr, void *ctx, PhidgetHandle devch) {
mgrAttachHandler(PhidgetManagerHandle mgr, void *ctx, PhidgetHandle mgrch) {


     PhidgetLog_log("%P attached", devch);
     PhidgetLog_log("%P attached", mgrch);
}
}


static void CCONV
static void CCONV
mgrDetachHandler(PhidgetManagerHandle mgr, void *ctx, PhidgetHandle devch) {
mgrDetachHandler(PhidgetManagerHandle mgr, void *ctx, PhidgetHandle mgrch) {


     PhidgetLog_log("%P detached", devch);
     PhidgetLog_log("%P detached", mgrch);
}
}


Line 58: Line 60:
</div>
</div>


A further example would be "HelloWorld" for most [[Software Overview#Language Support|supported languages]] uses the Phidget Manager.
A further example would be "HelloWorld" for most [[Programming_Resources|supported languages]] uses the Phidget Manager.


==Opening a Manager Channel==
==Opening a Manager Channel==
Line 64: Line 66:
A manager channel passed to a Phidget Manager attach handler is assigned all of the matching parameters for the Phidget device and the device channel the manager channel refers to; however, the manager channel is not attached to the device channel, and is not receiving data and status information from the device.
A manager channel passed to a Phidget Manager attach handler is assigned all of the matching parameters for the Phidget device and the device channel the manager channel refers to; however, the manager channel is not attached to the device channel, and is not receiving data and status information from the device.


User code may {{Code|Open()}} a manager channel, and just like a channel created by the user code, the Phidget library will begin trying to match the manager channel with a device channel.  User code may also set attach and detach handlers on the manager channel, and set change event handlers.  The manager channel can be treated exactly the same as a user channel, except that the manager channel must never be deleted, and after calling {{Code|Close()}}, should not be referred to again.
User code may {{Code|Open()}} a manager channel, and just like a channel created by the user code, the Phidget library will begin trying to match the manager channel with a device channel.  User code may also set attach and detach handlers on the manager channel, and set change event handlers.  The manager channel can be treated exactly the same as a user channel.

Latest revision as of 16:41, 24 March 2022

General Overview

The Phidget Manager is an interface into the device channels available to the Phidget library. The API is strictly asynchronous, and continuously monitors channels as they attach and detach.

Each Phidget exports one or more device channels, and when a Phidget is plugged into a system (or becomes available over the network), a manager attach event is fired for each channel available from the Phidget. When the Phidget is removed from the system, a manger detach event is fired for each channel that is no longer available.

It is important to understand the concepts of attach and detach as the they relate to the manager. A manager attach does not imply that a user channel has attached to a device channel, but that the device channel has appeared, and the device channel is now ready to be attached to a user channel. When a user channel closes and detaches from a device channel, a manager event is not fired. A manager detach event is fired when the Phidget is removed from the system.

Purpose

The primary function of a Phidget Manager is to fire an attach event for each new device channel when a Phidget becomes available to a system, and to fire a detach event for each device channel that is no longer available when the Phidget is removed from the system. For example, when a 1044_0 - PhidgetSpatial is connected, a Phidget Manager would fire three attach events, one for each device channel, as illustrated below:

Using the Phidget Manager

Much like a Phidget channel, a Phidget Manager must be created and opened. Refer to the Phidget22 API for details.

As soon as a manager is opened the Phidget library will fire an event for each device channel that is currently know to the system. After those initial events, attach and detach events will be fired when new Phidgets become available or existing Phidget are removed.

In the C programming language, it is not safe to refer to a PhidgetHandle after an event handler returns, unless Phidget_retain() is first called (Phidget_open() and Phidget_close() retain and release handlers automatically). The PhidgetHandle must be released with Phidget_release() if it has been retained. The object oriented languages supported in the Phidget22 API automatically retain and release handles.

What follows is an example of how to use a manager in C:

static void CCONV
mgrAttachHandler(PhidgetManagerHandle mgr, void *ctx, PhidgetHandle mgrch) {

    PhidgetLog_log("%P attached", mgrch);
}

static void CCONV
mgrDetachHandler(PhidgetManagerHandle mgr, void *ctx, PhidgetHandle mgrch) {

    PhidgetLog_log("%P detached", mgrch);
}

int
main(int argc, char **argv) {
    PhidgetManagerHandle mgr;

    PhidgetManager_create(&mgr);

    PhidgetManager_setOnAttachHandler(mgr, mgrAttachHandler, NULL);
    PhidgetManager_setOnDetachHandler(mgr, mgrDetachHandler, NULL);

    PhidgetManager_open(mgr);

    /* Do something long running, like run a GUI threads */
 
    /* Now close and delete the manager */
    PhidgetManager_close(mgr);
    PhidgetManager_delete(&mgr);
    exit(0);
}

A further example would be "HelloWorld" for most supported languages uses the Phidget Manager.

Opening a Manager Channel

A manager channel passed to a Phidget Manager attach handler is assigned all of the matching parameters for the Phidget device and the device channel the manager channel refers to; however, the manager channel is not attached to the device channel, and is not receiving data and status information from the device.

User code may Open() a manager channel, and just like a channel created by the user code, the Phidget library will begin trying to match the manager channel with a device channel. User code may also set attach and detach handlers on the manager channel, and set change event handlers. The manager channel can be treated exactly the same as a user channel.