node package manager
Easy sharing. Manage teams and permissions with one click. Create a free org ยป

phidget22

Synopsis

Official Phidget22 JavaScript library.

This library includes both nodjs and browser support.

Note that the Phidget Network Server is required for JavaScript clients to access Phidget devices.

Code Example

Examples for each Phidget channel class are available at www.phidgets.com.

var jPhidget22 = require('phidget22');

var SERVER_PORT = 5661;

function main() {

    if (process.argv.length != 3) {
        console.log('usage: node TemperatureSensor.js <server address>');
        process.exit(1);
    }

    var url = 'phid://' + process.argv[2] + ':' + SERVER_PORT;

    console.log('connecting to:' + url);
    var conn = new jPhidget22.Connection(url, { name: 'Server Connection', passwd: '' });
    conn.connect()
      .then(runExample)
      .catch(function (err) {
      	console.log('Error running example:' + err);
        process.exit(1);
      });
}

function runExample() {

    var ch = new jPhidget22.TemperatureSensor();

    ch.onAttach = function(ch) {
        console.log(ch + ' attached');
        console.log('min temperature:' + ch.getMinTemperature());
        console.log('max temperature:' + ch.getMaxTemperature());
    };

    ch.onDetach = function(ch) {
        console.log(ch + ' detached');
    };

    ch.onTemperatureChange = function (temp) {
        console.log('temperature:' + temp + ' (' + this.getTemperature() + ')');
    };

    ch.open().then(function (ch) {
        console.log('channel open');
    }).catch(function (err) {
        console.log('failed to open the channel:' + err);
    });
}

if (require.main === module)
    main();

API Reference

Please see the online documentation at www.phidgets.com.