Phidget Dictionary: Difference between revisions
Line 7: | Line 7: | ||
The basic functionality of a Dictionary is to maintain configuration information in a central location. Multiple clients can attach to the same dictionary, and set handlers for ''add'', ''update'' and ''delete'' events, making the dictionary useful for monitoring and communicating state. | The basic functionality of a Dictionary is to maintain configuration information in a central location. Multiple clients can attach to the same dictionary, and set handlers for ''add'', ''update'' and ''delete'' events, making the dictionary useful for monitoring and communicating state. | ||
==Creating a Dictionary== | |||
Dictionaries are managed by the [[Phidget Network Server]]. To create a dictionary, go to the [[Phidget Control Panel]] and click on the '''Network Server''' tab. There are options to create and manage dictionaries. The server must be enabled for clients to access dictionaries. | |||
==Using The Dictionary== | ==Using The Dictionary== | ||
To | To access a dictionary, create a channel, set the serial number or the label and open the channel. | ||
To "listen" for changes to the Dictionary, {{Code|onAdd()}}, {{Code|onRemove()}}, and {{Code|onUpdate()}} event handlers can be set. Refer to the {{Phidget22API}} to see the methods supported by Dictionary. | |||
Here's an example of how you might use the dictionary in a C program: | Here's an example of how you might use the dictionary in a C program: | ||
<div class="source"> | <div class="source"> | ||
<syntaxhighlight lang=c> | <syntaxhighlight lang=c> | ||
PhidgetDictionaryHandle dict; | PhidgetDictionaryHandle dict; | ||
char val[32]; | |||
PhidgetDictionary_create(&dict); | PhidgetDictionary_create(&dict); | ||
// Open connection to the dictionary using the serial number | // Open connection to the dictionary using the serial number | ||
Line 32: | Line 30: | ||
Phidget_open(dict); | Phidget_open(dict); | ||
// | PhidgetDictionary_add(dict, "my_key", "my_value"); // add a key that does not already exist | ||
PhidgetDictionary_get(dict, "my_key", val, sizeof (val)); // get the value back | |||
printf("Value: %s\n",newValue); | |||
PhidgetDictionary_remove(dict, "my_key"); // remove the key | |||
Phidget_close(dict); | Phidget_close(dict); | ||
PhidgetDictionary_delete(&dict); | PhidgetDictionary_delete(&dict); | ||
Line 51: | Line 41: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</div> | </div> | ||
Revision as of 20:26, 12 July 2017
General Overview
Dictionary is Phidget channel class that exports a key-value pair database. Dictionaries are create and made accessible by the Phidget Network Server. A Dictionary channel is created and opened like any other Phidget channel. Matching is done using either the serial number or the label assigned to the dictionary.
The backing pseudo-device that exports the Dictionary device channel is maintained by the Phidget Network Server, and is created when the server starts. When the server exits, the pseudo-device is deleted, and any changes to dictionaries are lost.
The basic functionality of a Dictionary is to maintain configuration information in a central location. Multiple clients can attach to the same dictionary, and set handlers for add, update and delete events, making the dictionary useful for monitoring and communicating state.
Creating a Dictionary
Dictionaries are managed by the Phidget Network Server. To create a dictionary, go to the Phidget Control Panel and click on the Network Server tab. There are options to create and manage dictionaries. The server must be enabled for clients to access dictionaries.
Using The Dictionary
To access a dictionary, create a channel, set the serial number or the label and open the channel.
To "listen" for changes to the Dictionary, onAdd()
, onRemove()
, and onUpdate()
event handlers can be set. Refer to the Phidget22 API to see the methods supported by Dictionary.
Here's an example of how you might use the dictionary in a C program:
PhidgetDictionaryHandle dict;
char val[32];
PhidgetDictionary_create(&dict);
// Open connection to the dictionary using the serial number
Phidget_setDeviceSerialNumber(dict, 5000);
Phidget_open(dict);
PhidgetDictionary_add(dict, "my_key", "my_value"); // add a key that does not already exist
PhidgetDictionary_get(dict, "my_key", val, sizeof (val)); // get the value back
printf("Value: %s\n",newValue);
PhidgetDictionary_remove(dict, "my_key"); // remove the key
Phidget_close(dict);
PhidgetDictionary_delete(&dict);