dial_a_device_node 0.0.153
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +674 -0
- data/README.md +94 -0
- data/Rakefile +1 -0
- data/app/assets/images/denver_summit.jpg +0 -0
- data/app/assets/images/eppendorf_innova_42.jpg +0 -0
- data/app/assets/images/heidolph.jpg +0 -0
- data/app/assets/images/ika_ret_control.jpg +0 -0
- data/app/assets/images/kern.jpg +0 -0
- data/app/assets/images/knf_rc900.jpg +0 -0
- data/app/assets/images/knf_sc920.jpg +0 -0
- data/app/assets/images/knf_simdos_02.jpg +0 -0
- data/app/assets/images/pce_balance.jpg +0 -0
- data/app/assets/images/purebeaglebone.jpg +0 -0
- data/app/assets/images/weathercape.jpg +0 -0
- data/app/assets/javascripts/dial_a_device_node/consolelogger.js +176 -0
- data/app/assets/javascripts/dial_a_device_node/deviceconnection.js +225 -0
- data/app/assets/javascripts/dial_a_device_node/devices/denver_summit.js +153 -0
- data/app/assets/javascripts/dial_a_device_node/devices/denver_summit_SIM.js +111 -0
- data/app/assets/javascripts/dial_a_device_node/devices/denver_summit_UI.js +121 -0
- data/app/assets/javascripts/dial_a_device_node/devices/eppendorf_innova_42.js +128 -0
- data/app/assets/javascripts/dial_a_device_node/devices/eppendorf_innova_42_SIM.js +66 -0
- data/app/assets/javascripts/dial_a_device_node/devices/eppendorf_innova_42_UI.js +46 -0
- data/app/assets/javascripts/dial_a_device_node/devices/heidolph.js +62 -0
- data/app/assets/javascripts/dial_a_device_node/devices/heidolph_SIM.js +24 -0
- data/app/assets/javascripts/dial_a_device_node/devices/heidolph_UI.js +17 -0
- data/app/assets/javascripts/dial_a_device_node/devices/ika_ret_control.js +192 -0
- data/app/assets/javascripts/dial_a_device_node/devices/ika_ret_control_SIM.js +233 -0
- data/app/assets/javascripts/dial_a_device_node/devices/ika_ret_control_UI.js +96 -0
- data/app/assets/javascripts/dial_a_device_node/devices/kern.js +137 -0
- data/app/assets/javascripts/dial_a_device_node/devices/kern_SIM.js +118 -0
- data/app/assets/javascripts/dial_a_device_node/devices/kern_UI.js +121 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_rc900.js +289 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_rc900_SIM.js +188 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_rc900_UI.js +179 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_sc920.js +309 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_sc920_SIM.js +298 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_sc920_UI.js +441 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_simdos_02.js +283 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_simdos_02_SIM.js +130 -0
- data/app/assets/javascripts/dial_a_device_node/devices/knf_simdos_02_UI.js +188 -0
- data/app/assets/javascripts/dial_a_device_node/devices/legacy_vnc.js +106 -0
- data/app/assets/javascripts/dial_a_device_node/devices/legacy_vnc_SIM.js +32 -0
- data/app/assets/javascripts/dial_a_device_node/devices/legacy_vnc_UI.js +26 -0
- data/app/assets/javascripts/dial_a_device_node/devices/pce_balance.js +111 -0
- data/app/assets/javascripts/dial_a_device_node/devices/pce_balance_SIM.js +80 -0
- data/app/assets/javascripts/dial_a_device_node/devices/pce_balance_UI.js +69 -0
- data/app/assets/javascripts/dial_a_device_node/devices/purebeaglebone.js +286 -0
- data/app/assets/javascripts/dial_a_device_node/devices/purebeaglebone_SIM.js +13 -0
- data/app/assets/javascripts/dial_a_device_node/devices/purebeaglebone_UI.js +256 -0
- data/app/assets/javascripts/dial_a_device_node/devices/weathercape.js +75 -0
- data/app/assets/javascripts/dial_a_device_node/devices/weathercape_SIM.js +33 -0
- data/app/assets/javascripts/dial_a_device_node/devices/weathercape_UI.js +42 -0
- data/app/assets/javascripts/dial_a_device_node/folderwatcher.js +43 -0
- data/app/assets/javascripts/dial_a_device_node/helper/WebSocket-Node-wrapper.js +36 -0
- data/app/assets/javascripts/dial_a_device_node/helper/XMLHttpRequest.js +579 -0
- data/app/assets/javascripts/dial_a_device_node/helper/agent.js +125 -0
- data/app/assets/javascripts/dial_a_device_node/helper/ajax.js +300 -0
- data/app/assets/javascripts/dial_a_device_node/helper/type.js +10 -0
- data/app/assets/javascripts/dial_a_device_node/php/comport.php +49 -0
- data/app/assets/javascripts/dial_a_device_node/php/php_serial.class.php +622 -0
- data/app/assets/javascripts/dial_a_device_node/systemstatus.js +124 -0
- data/app/assets/javascripts/dial_a_device_node/webconnection.js +197 -0
- data/app/assets/javascripts/dial_a_device_node/websocket_rails/abstract_connection.js.coffee +45 -0
- data/app/assets/javascripts/dial_a_device_node/websocket_rails/channel.js.coffee +70 -0
- data/app/assets/javascripts/dial_a_device_node/websocket_rails/event.js.coffee +42 -0
- data/app/assets/javascripts/dial_a_device_node/websocket_rails/http_connection.js.coffee +89 -0
- data/app/assets/javascripts/dial_a_device_node/websocket_rails/websocket_connection.js.coffee +37 -0
- data/app/assets/javascripts/dial_a_device_node/websocket_rails/websocket_rails.js.coffee +164 -0
- data/app/views/devices/ui/_denver_summit.html.erb +52 -0
- data/app/views/devices/ui/_eppendorf_innova_42.html.erb +72 -0
- data/app/views/devices/ui/_heidolph.html.erb +54 -0
- data/app/views/devices/ui/_ika_ret_control.html.erb +81 -0
- data/app/views/devices/ui/_kern.html.erb +52 -0
- data/app/views/devices/ui/_knf_rc900.html.erb +143 -0
- data/app/views/devices/ui/_knf_sc920.html.erb +194 -0
- data/app/views/devices/ui/_knf_simdos_02.html.erb +98 -0
- data/app/views/devices/ui/_pce_balance.html.erb +37 -0
- data/app/views/devices/ui/_purebeaglebone.html.erb +137 -0
- data/app/views/devices/ui/_weathercape.html.erb +313 -0
- data/beaglebonechip.js +57 -0
- data/dial-a-device-web.js +84 -0
- data/dial_a_device_node.gemspec +23 -0
- data/dial_a_device_node.js +419 -0
- data/lib/dial_a_device_node.rb +6 -0
- data/lib/dial_a_device_node/version.rb +3 -0
- data/package.json +35 -0
- data/start.js +40 -0
- metadata +161 -0
data/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
dial-a-device-node
|
|
2
|
+
==================
|
|
3
|
+
|
|
4
|
+
This package contains a gem AND a npm package AND a standalone node.js application.
|
|
5
|
+
|
|
6
|
+
## Installation in node.js (Ubuntu Linux)
|
|
7
|
+
|
|
8
|
+
Install the latest node.js and node package manager
|
|
9
|
+
|
|
10
|
+
sudo apt-get install software-properties-common python-software-properties
|
|
11
|
+
sudo add-apt-repository ppa:chris-lea/node.js
|
|
12
|
+
sudo apt-get update
|
|
13
|
+
sudo apt-get install nodejs git-core curl build-essential openssl libssl-dev coffeescript
|
|
14
|
+
|
|
15
|
+
Install the packages manually for development use: Download the dial-a-device-node source code and the required packages
|
|
16
|
+
|
|
17
|
+
sudo git clone https://github.com/Cominch/dial-a-device-node.git
|
|
18
|
+
|
|
19
|
+
sudo npm install -g coffee-script
|
|
20
|
+
sudo npm install -g serialport
|
|
21
|
+
sudo npm install -g websocket
|
|
22
|
+
sudo npm install -g bonescript
|
|
23
|
+
sudo npm install -g getmac
|
|
24
|
+
|
|
25
|
+
Go! on Linux
|
|
26
|
+
|
|
27
|
+
Make sure your user is in the dialout group or give full access to your serial port
|
|
28
|
+
|
|
29
|
+
sudo chmod 777 /dev/ttyUSB0
|
|
30
|
+
|
|
31
|
+
Edit start.js
|
|
32
|
+
|
|
33
|
+
Define your serial port and websocket URL, if you don't want to use the default values
|
|
34
|
+
|
|
35
|
+
Run the dial-a-device-node client
|
|
36
|
+
|
|
37
|
+
node start.js
|
|
38
|
+
|
|
39
|
+
## Installation on BeagleBone (Angstrom Linux) for development and debugging
|
|
40
|
+
|
|
41
|
+
Install required OS packages
|
|
42
|
+
|
|
43
|
+
opkg update
|
|
44
|
+
opkg install python-compiler
|
|
45
|
+
opkg install python-misc
|
|
46
|
+
opkg install python-multiprocessing
|
|
47
|
+
|
|
48
|
+
Install the npm package
|
|
49
|
+
|
|
50
|
+
npm update
|
|
51
|
+
npm install -g coffee-script
|
|
52
|
+
npm install -g serialport
|
|
53
|
+
npm install -g websocket
|
|
54
|
+
npm install -g getmac
|
|
55
|
+
|
|
56
|
+
cd /var/lib/cloud9
|
|
57
|
+
|
|
58
|
+
env GIT_SSL_NO_VERIFY=true git clone https://github.com/Cominch/dial-a-device-node
|
|
59
|
+
|
|
60
|
+
cd /var/lib/cloud9/dial-a-device-node
|
|
61
|
+
|
|
62
|
+
npm install
|
|
63
|
+
|
|
64
|
+
node start.js
|
|
65
|
+
|
|
66
|
+
You can access and modify the source code via the cloud9 editor on your BeagleBone:
|
|
67
|
+
|
|
68
|
+
http://192.168.7.2:3000
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
## Installation as part of a Ruby on Rails project (gem)
|
|
72
|
+
|
|
73
|
+
Add this line to your application's Gemfile:
|
|
74
|
+
|
|
75
|
+
gem 'dial_a_device_node'
|
|
76
|
+
|
|
77
|
+
Change these settings in /config/environments/production.rb
|
|
78
|
+
|
|
79
|
+
config.serve_static_assets = true
|
|
80
|
+
config.assets.compress = false
|
|
81
|
+
config.assets.compile = true
|
|
82
|
+
|
|
83
|
+
And then execute:
|
|
84
|
+
|
|
85
|
+
$ bundle
|
|
86
|
+
|
|
87
|
+
Or install it yourself as:
|
|
88
|
+
|
|
89
|
+
$ gem install dial_a_device_node
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
GPLv3
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
(function (exports) {
|
|
2
|
+
|
|
3
|
+
exports.init = function (eventbus) {
|
|
4
|
+
localeventbus = eventbus;
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
localeventbus.on("folderwatcher.event", function (event, path) {
|
|
8
|
+
|
|
9
|
+
console.log("folderwatcher "+ event + " - "+ path);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
localeventbus.on("serial.initialized", function () {
|
|
14
|
+
|
|
15
|
+
console.log("serial port library initialized");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
localeventbus.on("serial.portopened", function () {
|
|
20
|
+
|
|
21
|
+
console.log("serial port opened");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
localeventbus.on("serial.portclosed", function () {
|
|
25
|
+
|
|
26
|
+
console.log("serial port closed");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
localeventbus.on("serial.command", function (data) {
|
|
30
|
+
|
|
31
|
+
console.log("serial send command: " + data);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
localeventbus.on("serial.immediatecommand", function (data) {
|
|
35
|
+
|
|
36
|
+
console.log("serial send immediatecommand: " + data);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
localeventbus.on("serial.incoming", function (data) {
|
|
40
|
+
|
|
41
|
+
console.log("serial incoming: " + JSON.stringify(data));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
localeventbus.on("serial.retrieve", function (data) {
|
|
45
|
+
|
|
46
|
+
console.log("serial retrieve string: " + JSON.stringify(data));
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
localeventbus.on("serial.rawretrieve", function (data) {
|
|
50
|
+
|
|
51
|
+
console.log("serial retrieve raw: " + JSON.stringify(data));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
localeventbus.on("serial.set.baud", function (data) {
|
|
55
|
+
console.log("serial set baud: " + data);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
localeventbus.on("serial.set.port", function (data) {
|
|
59
|
+
console.log("serial set port: " + data);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
localeventbus.on("serial.openfailed", function (data) {
|
|
65
|
+
|
|
66
|
+
console.log("serial openfailed: " + data);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
localeventbus.on("status.deviceendpoint", function (url) {
|
|
72
|
+
|
|
73
|
+
console.log("device endpoint? " + url);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
localeventbus.on("connecting", function (url) {
|
|
78
|
+
|
|
79
|
+
console.log("connecting to " + url);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
localeventbus.on("webconnection.connected", function (url) {
|
|
83
|
+
|
|
84
|
+
console.log("connected to " + url);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
localeventbus.on("channel.subscribing", function (channelname) {
|
|
88
|
+
|
|
89
|
+
console.log("subscribing to " + channelname);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
localeventbus.on("connectionclosed", function () {
|
|
93
|
+
|
|
94
|
+
console.log("connection closed");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
localeventbus.on("channel.subscription", function (channelname, channel) {
|
|
98
|
+
|
|
99
|
+
console.log("subscribed to " + channelname);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
localeventbus.on("channel.ui_connected", function (data) {
|
|
105
|
+
|
|
106
|
+
console.log("new ui conection: " + JSON.stringify(data));
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
localeventbus.on("channel.ui_disconnected", function (data) {
|
|
110
|
+
|
|
111
|
+
console.log("ui disconection: " + JSON.stringify(data));
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
localeventbus.on("channel.dev_connected", function (data) {
|
|
115
|
+
|
|
116
|
+
console.log("new dev conection: " + JSON.stringify(data));
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
localeventbus.on("channel.dev_disconnected", function (data) {
|
|
120
|
+
|
|
121
|
+
console.log("dev disconection: " + JSON.stringify(data));
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
localeventbus.on("device.log", function (lm, data) {
|
|
127
|
+
|
|
128
|
+
console.log(JSON.stringify(data));
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
localeventbus.on("device.initialized", function () {
|
|
132
|
+
|
|
133
|
+
console.log("device initialized");
|
|
134
|
+
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
localeventbus.on("device.snapshot", function (device_model) {
|
|
138
|
+
|
|
139
|
+
console.log("device snapshot: " + JSON.stringify(device_model));
|
|
140
|
+
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
localeventbus.on("device.command", function (message) {
|
|
144
|
+
|
|
145
|
+
console.log("device command: " + JSON.stringify(message));
|
|
146
|
+
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
localeventbus.on("device.reply", function (message, data) {
|
|
150
|
+
|
|
151
|
+
console.log("device reply: " + JSON.stringify(message)+ " --> "+ JSON.stringify(data));
|
|
152
|
+
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
localeventbus.on("ui.update", function (message) {
|
|
156
|
+
|
|
157
|
+
console.log("ui update: " + JSON.stringify(message));
|
|
158
|
+
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
localeventbus.on("ui.command", function (message) {
|
|
162
|
+
|
|
163
|
+
console.log("ui command: " + JSON.stringify(message));
|
|
164
|
+
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
localeventbus.on("status.incoming", function (message) {
|
|
168
|
+
|
|
169
|
+
console.log("status incoming " + JSON.stringify(message));
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
localeventbus.emit("consolelogger.initialized");
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
})(typeof exports == 'undefined' ? this['consolelogger'] = {} : exports);
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
var util = require('util');
|
|
2
|
+
var ser = require('serialport');
|
|
3
|
+
|
|
4
|
+
var serialport;
|
|
5
|
+
|
|
6
|
+
var localeventbus;
|
|
7
|
+
|
|
8
|
+
var lastmessage = new Array;
|
|
9
|
+
var currentmessage;
|
|
10
|
+
var waiting = false;
|
|
11
|
+
|
|
12
|
+
var port;
|
|
13
|
+
var baud;
|
|
14
|
+
var databit = 8;
|
|
15
|
+
var parity = "none";
|
|
16
|
+
var stopbit = 1;
|
|
17
|
+
|
|
18
|
+
var linebreak = hex2a('0D');
|
|
19
|
+
var suffix = hex2a('0D');
|
|
20
|
+
var prefix = "";
|
|
21
|
+
|
|
22
|
+
function hex2a(hexx) {
|
|
23
|
+
var hex = hexx.toString();//force conversion
|
|
24
|
+
var str = '';
|
|
25
|
+
for (var i = 0; i < hex.length; i += 2)
|
|
26
|
+
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
|
|
27
|
+
return str;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function knfsimdosparser() {
|
|
31
|
+
|
|
32
|
+
var data = new Buffer(0);
|
|
33
|
+
|
|
34
|
+
return function(emitter, buffer){
|
|
35
|
+
|
|
36
|
+
data = Buffer.concat([data, buffer]);
|
|
37
|
+
|
|
38
|
+
while (data.toJSON().indexOf(2) > -1 && data.toJSON().indexOf(3) > data.toJSON().indexOf(2) && data.toJSON().length > data.toJSON().indexOf(3)+1) {
|
|
39
|
+
|
|
40
|
+
var out = data.slice(data.toJSON().indexOf(2)+1, data.toJSON().indexOf(3));
|
|
41
|
+
|
|
42
|
+
data = data.slice(data.toJSON().indexOf(3)+2);
|
|
43
|
+
|
|
44
|
+
emitter.emit('data', out.toString());
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
exports.init = function (eventbus) {
|
|
54
|
+
localeventbus = eventbus;
|
|
55
|
+
localeventbus.emit("serial.initialized");
|
|
56
|
+
|
|
57
|
+
localeventbus.on("serial.set.baud", function (data) {
|
|
58
|
+
baud = data;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
localeventbus.on("serial.set.port", function (data) {
|
|
62
|
+
port = data;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
localeventbus.on("serial.set.linebreak", function (data) {
|
|
66
|
+
linebreak = data;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
localeventbus.on("serial.set.prefix", function (data) {
|
|
70
|
+
prefix = data;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
localeventbus.on("serial.set.suffix", function (data) {
|
|
74
|
+
suffix = data;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
localeventbus.on("serial.set.databit", function (data) {
|
|
78
|
+
databit = data;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
localeventbus.on("serial.set.parity", function (data) {
|
|
82
|
+
parity = data;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
localeventbus.on("serial.set.stopbit", function (data) {
|
|
86
|
+
stopbit = data;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
localeventbus.on("serial.connect", function () {
|
|
91
|
+
|
|
92
|
+
if (linebreak == "") {
|
|
93
|
+
serialport = new ser.SerialPort(port, {
|
|
94
|
+
baudrate: baud,
|
|
95
|
+
databit: databit,
|
|
96
|
+
parity: parity,
|
|
97
|
+
stopbit: stopbit,
|
|
98
|
+
parser: (ser.parsers.raw)
|
|
99
|
+
});
|
|
100
|
+
} else if (linebreak == "knfsimdos") {
|
|
101
|
+
|
|
102
|
+
serialport = new ser.SerialPort(port, {
|
|
103
|
+
baudrate: baud,
|
|
104
|
+
databit: databit,
|
|
105
|
+
parity: parity,
|
|
106
|
+
stopbit: stopbit,
|
|
107
|
+
parser: (knfsimdosparser())
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
} else if (linebreak == "denver") {
|
|
111
|
+
|
|
112
|
+
serialport = new ser.SerialPort(port, {
|
|
113
|
+
baudrate: baud,
|
|
114
|
+
databit: databit,
|
|
115
|
+
parity: parity,
|
|
116
|
+
stopbit: stopbit,
|
|
117
|
+
parser: (ser.parsers.readline(hex2a("0D"), "ascii"))
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
}else {
|
|
121
|
+
|
|
122
|
+
serialport = new ser.SerialPort(port, {
|
|
123
|
+
baudrate: baud,
|
|
124
|
+
databit: databit,
|
|
125
|
+
parity: parity,
|
|
126
|
+
stopbit: stopbit,
|
|
127
|
+
parser: (ser.parsers.readline(hex2a(linebreak)))
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
serialport.on("error", function (err) {
|
|
132
|
+
localeventbus.emit("serial.openfailed", err);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
serialport.on("close", function () {
|
|
136
|
+
localeventbus.emit("serial.portclosed", port);
|
|
137
|
+
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
serialport.on("open", function () {
|
|
142
|
+
localeventbus.emit("serial.portopened", port, baud);
|
|
143
|
+
|
|
144
|
+
serialport.on("data", function (data) {
|
|
145
|
+
localeventbus.emit("serial.incoming", data);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
localeventbus.on("serial.immediatecommand", function (msg) {
|
|
149
|
+
waiting = false;
|
|
150
|
+
lastmessage = new Array;
|
|
151
|
+
serialport.write(hex2a(prefix) + msg + hex2a(suffix), function (err, results) {});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
localeventbus.on("serial.sendraw", function (msg) {
|
|
155
|
+
|
|
156
|
+
waiting = false;
|
|
157
|
+
lastmessage = new Array;
|
|
158
|
+
serialport.write(hex2a(prefix) + hex2a(msg) + hex2a(suffix), function (err, results) {});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
localeventbus.on("serial.command", function (data) {
|
|
162
|
+
lastmessage.push(data);
|
|
163
|
+
localeventbus.emit("serial.writenext");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
localeventbus.on("serial.close", function (msg) {
|
|
168
|
+
|
|
169
|
+
serialport.close();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
localeventbus.on("serial.writenext", function () {
|
|
173
|
+
setTimeout(function () {
|
|
174
|
+
|
|
175
|
+
if (waiting) {
|
|
176
|
+
localeventbus.emit('serial.writenext');
|
|
177
|
+
} else if (lastmessage.length > 0) {
|
|
178
|
+
|
|
179
|
+
waiting = true;
|
|
180
|
+
currentmessage = lastmessage.pop();
|
|
181
|
+
serialport.write(hex2a(prefix) + currentmessage + hex2a(suffix), function (err, results) {});
|
|
182
|
+
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
}, 50);
|
|
186
|
+
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
localeventbus.on("serial.incoming", function (data) {
|
|
194
|
+
|
|
195
|
+
if ((typeof data === "object")) {
|
|
196
|
+
|
|
197
|
+
localeventbus.emit("serial.rawretrieve", data);
|
|
198
|
+
|
|
199
|
+
} else {
|
|
200
|
+
|
|
201
|
+
if (data.substring(0, 1) == "\n") {
|
|
202
|
+
data = data.substring(1);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// data = data.replace(/[^A-Za-z 0-9 \.,\?""!@#\$%\^&\*\(\)-_=\+;:<>\/\\\|\}\{\[\]`~]*/g, '');
|
|
206
|
+
|
|
207
|
+
localeventbus.emit("serial.retrieve", data);
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
if (waiting) {
|
|
213
|
+
|
|
214
|
+
localeventbus.emit("device.reply", currentmessage, data);
|
|
215
|
+
waiting = false;
|
|
216
|
+
} else {
|
|
217
|
+
lastmessage = new Array;
|
|
218
|
+
localeventbus.emit("device.reply", "heartbeat", data);
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
};
|