-
Notifications
You must be signed in to change notification settings - Fork 4
/
nisa.js
101 lines (87 loc) · 2.38 KB
/
nisa.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var raw = require('bindings')({ bindings: 'nisa' });
var EventEmitter = require('events').EventEmitter;
var util = require ("util");
for (var key in EventEmitter.prototype) {
raw.VisaEmitter.prototype[key] = EventEmitter.prototype[key];
}
var _options = {
enableSRQ: true,
assertREN: true,
timeoutMiliSeconds: 2000
}
function VisaPort(path, options) {
VisaPort.super_.call (this);
var self = this;
options = (typeof options !== 'function') && options || {};
var opts = {};
opts.enableSRQ = _options.enableSRQ;
if (options.hasOwnProperty('enableSRQ')) {
opts.enableSRQ = options.enableSRQ;
}
opts.assertREN = _options.assertREN;
if (options.hasOwnProperty('assertREN')) {
opts.assertREN = options.assertREN;
}
opts.timeoutMiliSeconds = _options.timeoutMiliSeconds;
if (options.hasOwnProperty('timeoutMiliSeconds') && options.timeoutMiliSeconds > 100) {
opts.timeoutMiliSeconds = options.timeoutMiliSeconds;
}
this.options = opts;
this.wrap = new raw.VisaEmitter(path);
this.wrap.on ("srq", this.onSrq.bind (self));
}
util.inherits (VisaPort, EventEmitter);
VisaPort.prototype.open = function (callback) {
var me = this;
this.wrap.open(this.options, function(err, res) {
if (!err) {
me.emit ("open", res);
return callback(err, res);
} else if (callback) {
return callback(err, res);
}
else {
me.emit ("error", err);
}
});
return this;
}
VisaPort.prototype.write = function (query, callback) {
this.wrap.write(query, callback);
return this;
}
VisaPort.prototype.query = function (query, callback) {
this.wrap.query(query, callback);
return this;
}
VisaPort.prototype.read = function (numberOfBytes, callback) {
var args = Array.prototype.slice.call(arguments);
callback = args.pop();
if (typeof (callback) !== 'function') {
callback = null;
}
numberOfBytes = args.pop();
if (typeof (numberOfBytes) !== 'number') {
numberOfBytes = 256;
}
this.wrap.read(numberOfBytes, callback);
return this;
}
VisaPort.prototype.trigger = function(callback) {
this.wrap.trigger(callback);
return this;
}
VisaPort.prototype.deviceClear = function(callback) {
this.wrap.deviceClear(callback);
return this;
}
VisaPort.prototype.close = function(callback) {
this.wrap.close(callback);
return this;
}
VisaPort.prototype.onSrq = function (stb) {
var me = this;
me.emit ("srq", stb);
}
exports.Visa = VisaPort;
exports.version = '1.0.0';