-
Notifications
You must be signed in to change notification settings - Fork 0
/
scom.js
52 lines (36 loc) · 1.15 KB
/
scom.js
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
51
52
var SerialPort = require("serialport").SerialPort;
var serialPort = new SerialPort('COM3',{baudrate: 38400}, true);
var scanstr="\x02\x01\x08\x00\x00\x01\x00\x0a";
var program = require('commander');
program
.version('0.0.1')
.option('-r, --read', 'read tag data')
.option('-w, --write', 'write tag data')
.option('-i, --id <id>', 'term id')
.option('-f, --file <filename>', 'Add file name for read write')
.parse(process.argv);
console.log('you ordered a pizza with:');
if (program.read && program.id && program.file) {
console.log(' read tag data from tag id');
}
if (program.write && program.id && program.file) {
console.log(' write tag data from tag id');
}
serialPort.on ('open', function (error) {
if ( error ) {
console.log('failed to open: '+error);
} else {
console.log('open');
serialPort.write(scanstr, function(err, results) {
if (error){
console.log("failed write")
console.log('err ' + err);
console.log('results ' + results);
}else{
}
});
serialPort.on ('data', function( data ) {
console.log("data" + data.toString());
});
}
});