-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPHSensor.js
More file actions
50 lines (39 loc) · 1.1 KB
/
PHSensor.js
File metadata and controls
50 lines (39 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var phidget22 = require('phidget22');
var SERVER_PORT = 5661;
function main() {
if (process.argv.length != 3) {
console.log('usage: node PHSensor.js <server address>');
process.exit(1);
}
var hostname = process.argv[2];
console.log('connecting to:' + hostname);
var conn = new phidget22.Connection(SERVER_PORT, hostname, { name: 'Server Connection', passwd: '' });
conn.connect()
.then(runExample)
.catch(function (err) {
console.error('Error running example:', err.message);
process.exit(1);
});
}
function runExample() {
console.log('connected to server');
var ch = new phidget22.PHSensor();
ch.onAttach = function (ch) {
console.log(ch + ' attached');
console.log('Min PH:' + ch.getMinPH());
console.log('Max PH:' + ch.getMaxPH());
};
ch.onDetach = function (ch) {
console.log(ch + ' detached');
};
ch.onPHChange = function (pH) {
console.log('pH:' + pH + ' (' + this.getPH() + ')');
};
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();