node-red-contrib-v430-barcode 0.2.6
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.
- package/LICENSE +21 -0
- package/README.md +78 -0
- package/V430_barcode_reader.html +67 -0
- package/V430_barcode_reader.js +393 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nicholas Cifuni
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# V430 WebSocket Barcode Node
|
|
2
|
+
|
|
3
|
+
Node-RED node for streaming barcode reads from an Omron V430 over websocket.
|
|
4
|
+
|
|
5
|
+
## Behavior
|
|
6
|
+
|
|
7
|
+
- Connects to `websocket`
|
|
8
|
+
- translates incoming data packets into Json data
|
|
9
|
+
- outputs data into 2 nodes
|
|
10
|
+
- output 1 being just the barcode being read
|
|
11
|
+
- output 2 being the metadata found in Json formatting
|
|
12
|
+
- Starts the websocket client only when `Enabled` is checked.
|
|
13
|
+
|
|
14
|
+
## Outputs
|
|
15
|
+
|
|
16
|
+
Output 1 sends the barcode read:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"topic": "v430/barcode",
|
|
21
|
+
"payload": {
|
|
22
|
+
"barcode": "0041199006794",
|
|
23
|
+
"symbology": "EAN13",
|
|
24
|
+
"host": "192.168.250.2",
|
|
25
|
+
"port": 50502,
|
|
26
|
+
"path": "/",
|
|
27
|
+
"cycle_id": "0x000000e6",
|
|
28
|
+
"read_time_ms": 86,
|
|
29
|
+
"cycle_time_ms": 485,
|
|
30
|
+
"received_at": "2026-07-06T14:30:00.000Z"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Output 2 sends the metadata JSON:
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{
|
|
39
|
+
"topic": "v430/barcode/metadata",
|
|
40
|
+
"payload": {
|
|
41
|
+
"barcode": "0041199006794",
|
|
42
|
+
"symbology": "EAN13",
|
|
43
|
+
"cycle_id": "0x000000e6",
|
|
44
|
+
"read_time_ms": 86,
|
|
45
|
+
"cycle_time_ms": 485,
|
|
46
|
+
"received_at": "2026-07-06T14:30:00.000Z",
|
|
47
|
+
"frame_format": "text",
|
|
48
|
+
"decoded_type": "string",
|
|
49
|
+
"source": {
|
|
50
|
+
"host": "192.168.250.2",
|
|
51
|
+
"port": 50502,
|
|
52
|
+
"path": "/",
|
|
53
|
+
"websocket_url": "ws://192.168.250.2:50502/"
|
|
54
|
+
},
|
|
55
|
+
"event": "<cycleReport ... />"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
For compatibility, Output 1 still includes the decoded frame on `msg.raw_event`.
|
|
61
|
+
|
|
62
|
+
## Files
|
|
63
|
+
|
|
64
|
+
- `package.json`: Node-RED package manifest
|
|
65
|
+
- `V430_barcode_reader.js`: runtime node implementation
|
|
66
|
+
- `V430_barcode_reader.html`: Node-RED editor UI
|
|
67
|
+
|
|
68
|
+
## Local Use
|
|
69
|
+
|
|
70
|
+
1. Run `npm.cmd install` in this folder.
|
|
71
|
+
2. In your Node-RED user directory, run `npm.cmd install <path-to-this-folder>`.
|
|
72
|
+
3. Restart Node-RED.
|
|
73
|
+
4. Add `V430 Barcode` to a flow.
|
|
74
|
+
|
|
75
|
+
## Notes
|
|
76
|
+
|
|
77
|
+
- Uncheck `Enabled` in the node editor to keep the node loaded in the flow without opening a websocket connection.
|
|
78
|
+
- If the V430 payload uses different barcode or symbology field names, update `BARCODE_VALUE_KEYS` or `SYMBOLOGY_KEYS` in `V430_barcode_reader.js`.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
(() => {
|
|
3
|
+
const nodeType = "v430-websocket-barcode";
|
|
4
|
+
const nodeDisplayName = "V430 Barcode";
|
|
5
|
+
|
|
6
|
+
RED.nodes.registerType(nodeType, {
|
|
7
|
+
category: "omron",
|
|
8
|
+
color: "#cfe8ff",
|
|
9
|
+
defaults: {
|
|
10
|
+
name: { value: "" },
|
|
11
|
+
host: { value: "192.168.250.2", required: true },
|
|
12
|
+
websocketPort: { value: 50502, required: true, validate: RED.validators.number() },
|
|
13
|
+
websocketPath: { value: "/", required: true },
|
|
14
|
+
enabled: { value: true },
|
|
15
|
+
receiveTimeoutMs: { value: 5000, required: true, validate: RED.validators.number() },
|
|
16
|
+
reconnectDelayMs: { value: 3000, required: true, validate: RED.validators.number() }
|
|
17
|
+
},
|
|
18
|
+
inputs: 0,
|
|
19
|
+
outputs: 2,
|
|
20
|
+
outputLabels: ["barcode json", "metadata json"],
|
|
21
|
+
icon: "bridge.svg",
|
|
22
|
+
paletteLabel: nodeDisplayName,
|
|
23
|
+
label: function () {
|
|
24
|
+
return this.name || nodeDisplayName;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
})();
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<script type="text/html" data-template-name="v430-websocket-barcode">
|
|
31
|
+
<div class="form-row">
|
|
32
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
33
|
+
<input type="text" id="node-input-name" placeholder="V430 barcode">
|
|
34
|
+
</div>
|
|
35
|
+
<div class="form-row">
|
|
36
|
+
<label for="node-input-host"><i class="fa fa-globe"></i> Host / IP</label>
|
|
37
|
+
<input type="text" id="node-input-host" placeholder="192.168.250.2">
|
|
38
|
+
</div>
|
|
39
|
+
<div class="form-row">
|
|
40
|
+
<label for="node-input-websocketPort"><i class="fa fa-plug"></i> Port</label>
|
|
41
|
+
<input type="text" id="node-input-websocketPort" placeholder="50502">
|
|
42
|
+
</div>
|
|
43
|
+
<div class="form-row">
|
|
44
|
+
<label for="node-input-websocketPath"><i class="fa fa-link"></i> Path</label>
|
|
45
|
+
<input type="text" id="node-input-websocketPath" placeholder="/">
|
|
46
|
+
</div>
|
|
47
|
+
<div class="form-row">
|
|
48
|
+
<label for="node-input-enabled"><i class="fa fa-power-off"></i> Enabled</label>
|
|
49
|
+
<input type="checkbox" id="node-input-enabled" style="display:inline-block; width:auto; vertical-align:middle;">
|
|
50
|
+
</div>
|
|
51
|
+
<div class="form-row">
|
|
52
|
+
<label for="node-input-receiveTimeoutMs"><i class="fa fa-clock-o"></i> Timeout ms</label>
|
|
53
|
+
<input type="text" id="node-input-receiveTimeoutMs">
|
|
54
|
+
</div>
|
|
55
|
+
<div class="form-row">
|
|
56
|
+
<label for="node-input-reconnectDelayMs"><i class="fa fa-refresh"></i> Reconnect ms</label>
|
|
57
|
+
<input type="text" id="node-input-reconnectDelayMs">
|
|
58
|
+
</div>
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<script type="text/html" data-help-name="v430-websocket-barcode">
|
|
62
|
+
<p>Connects to an Omron V430 websocket endpoint at <code>ws://<host>:<port><path></code> and emits decoded barcode data.</p>
|
|
63
|
+
<p>The default V430 data stream is <code>ws://192.168.250.2:50502/</code>.</p>
|
|
64
|
+
<p>Disable the node with the <code>Enabled</code> checkbox to prevent websocket handshakes and reconnect attempts.</p>
|
|
65
|
+
<p>The node accepts both text websocket frames and binary MessagePack websocket frames.</p>
|
|
66
|
+
<p>Output 1 sends the barcode payload. Output 2 sends the full metadata JSON, including source details and the decoded event.</p>
|
|
67
|
+
</script>
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { decode } = require("@msgpack/msgpack");
|
|
4
|
+
const WebSocket = require("ws");
|
|
5
|
+
|
|
6
|
+
const NODE_TYPE = "v430-websocket-barcode";
|
|
7
|
+
const DEFAULTS = {
|
|
8
|
+
host: "192.168.250.2",
|
|
9
|
+
websocketPort: 50502,
|
|
10
|
+
websocketPath: "/",
|
|
11
|
+
receiveTimeoutMs: 5000,
|
|
12
|
+
reconnectDelayMs: 3000
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const BARCODE_VALUE_KEYS = new Set([
|
|
16
|
+
"datautf8",
|
|
17
|
+
"data_utf8",
|
|
18
|
+
"decodeddata",
|
|
19
|
+
"decode_data",
|
|
20
|
+
"decoded_data",
|
|
21
|
+
"decode",
|
|
22
|
+
"barcode",
|
|
23
|
+
"code",
|
|
24
|
+
"data",
|
|
25
|
+
"text",
|
|
26
|
+
"value"
|
|
27
|
+
].map(normalizeKey));
|
|
28
|
+
|
|
29
|
+
const SYMBOLOGY_KEYS = new Set([
|
|
30
|
+
"symbology",
|
|
31
|
+
"symbologyname",
|
|
32
|
+
"symbol",
|
|
33
|
+
"type",
|
|
34
|
+
"decodetype",
|
|
35
|
+
"codelabel"
|
|
36
|
+
].map(normalizeKey));
|
|
37
|
+
|
|
38
|
+
module.exports = function (RED) {
|
|
39
|
+
function V430WebsocketBarcodeNode(config) {
|
|
40
|
+
RED.nodes.createNode(this, config);
|
|
41
|
+
const node = this;
|
|
42
|
+
|
|
43
|
+
node.host = String(config.host || DEFAULTS.host).trim() || DEFAULTS.host;
|
|
44
|
+
node.websocketPort = Number(config.websocketPort) || DEFAULTS.websocketPort;
|
|
45
|
+
node.websocketPath = normalizeWebsocketPath(config.websocketPath);
|
|
46
|
+
node.enabled = config.enabled !== false;
|
|
47
|
+
node.receiveTimeoutMs = Number(config.receiveTimeoutMs) || DEFAULTS.receiveTimeoutMs;
|
|
48
|
+
node.reconnectDelayMs = Number(config.reconnectDelayMs) || DEFAULTS.reconnectDelayMs;
|
|
49
|
+
node.ws = null;
|
|
50
|
+
node.reconnectTimer = null;
|
|
51
|
+
node.isClosing = false;
|
|
52
|
+
|
|
53
|
+
const wsUrl = `ws://${node.host}:${node.websocketPort}${node.websocketPath}`;
|
|
54
|
+
|
|
55
|
+
function setStatus(fill, shape, text) {
|
|
56
|
+
node.status({ fill, shape, text });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function scheduleReconnect(reason) {
|
|
60
|
+
if (node.isClosing || !node.enabled || node.reconnectTimer) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
setStatus("yellow", "ring", `reconnecting: ${reason}`);
|
|
65
|
+
node.reconnectTimer = setTimeout(() => {
|
|
66
|
+
node.reconnectTimer = null;
|
|
67
|
+
connect();
|
|
68
|
+
}, node.reconnectDelayMs);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function cleanupSocket() {
|
|
72
|
+
if (!node.ws) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
node.ws.removeAllListeners();
|
|
78
|
+
node.ws.terminate();
|
|
79
|
+
} catch {
|
|
80
|
+
// Ignore shutdown errors.
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
node.ws = null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function emitRead(frameInfo, barcodeData) {
|
|
87
|
+
const receivedAt = new Date().toISOString();
|
|
88
|
+
const source = {
|
|
89
|
+
host: node.host,
|
|
90
|
+
port: node.websocketPort,
|
|
91
|
+
path: node.websocketPath,
|
|
92
|
+
websocket_url: wsUrl
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const barcodeMessage = {
|
|
96
|
+
topic: "v430/barcode",
|
|
97
|
+
payload: {
|
|
98
|
+
barcode: barcodeData.barcode,
|
|
99
|
+
symbology: barcodeData.symbology,
|
|
100
|
+
host: source.host,
|
|
101
|
+
port: source.port,
|
|
102
|
+
path: source.path,
|
|
103
|
+
cycle_id: barcodeData.cycle_id,
|
|
104
|
+
read_time_ms: barcodeData.read_time_ms,
|
|
105
|
+
cycle_time_ms: barcodeData.cycle_time_ms,
|
|
106
|
+
received_at: receivedAt
|
|
107
|
+
},
|
|
108
|
+
raw_event: frameInfo.decoded,
|
|
109
|
+
websocket_url: wsUrl
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const metadataMessage = {
|
|
113
|
+
topic: "v430/barcode/metadata",
|
|
114
|
+
payload: {
|
|
115
|
+
barcode: barcodeData.barcode,
|
|
116
|
+
symbology: barcodeData.symbology,
|
|
117
|
+
cycle_id: barcodeData.cycle_id,
|
|
118
|
+
read_time_ms: barcodeData.read_time_ms,
|
|
119
|
+
cycle_time_ms: barcodeData.cycle_time_ms,
|
|
120
|
+
received_at: receivedAt,
|
|
121
|
+
frame_format: frameInfo.frameFormat,
|
|
122
|
+
decoded_type: frameInfo.decodedType,
|
|
123
|
+
source,
|
|
124
|
+
event: frameInfo.decoded
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
node.send([barcodeMessage, metadataMessage]);
|
|
129
|
+
setStatus("green", "dot", barcodeData.barcode);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function handleFrame(frame, isBinary) {
|
|
133
|
+
const frameInfo = decodeFrame(frame, isBinary);
|
|
134
|
+
if (!frameInfo) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const barcodeData = extractBarcodeData(frameInfo.decoded);
|
|
139
|
+
if (!barcodeData) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
emitRead(frameInfo, barcodeData);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function connect() {
|
|
147
|
+
if (node.isClosing || !node.enabled) {
|
|
148
|
+
setStatus("grey", "ring", "disabled");
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
cleanupSocket();
|
|
153
|
+
setStatus("yellow", "ring", "connecting");
|
|
154
|
+
|
|
155
|
+
const ws = new WebSocket(wsUrl, {
|
|
156
|
+
handshakeTimeout: node.receiveTimeoutMs
|
|
157
|
+
});
|
|
158
|
+
node.ws = ws;
|
|
159
|
+
|
|
160
|
+
ws.on("open", () => {
|
|
161
|
+
setStatus("green", "ring", "connected");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
ws.on("message", (data, isBinary) => {
|
|
165
|
+
try {
|
|
166
|
+
handleFrame(data, isBinary);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
node.warn(`Frame handling error: ${error.message}`);
|
|
169
|
+
setStatus("red", "ring", "frame error");
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
ws.on("error", (error) => {
|
|
174
|
+
node.warn(`WebSocket error: ${error.message}`);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
ws.on("close", (code, reason) => {
|
|
178
|
+
cleanupSocket();
|
|
179
|
+
scheduleReconnect(String(reason || code || "closed"));
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (node.enabled) {
|
|
184
|
+
connect();
|
|
185
|
+
} else {
|
|
186
|
+
setStatus("grey", "ring", "disabled");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
node.on("close", function (removed, done) {
|
|
190
|
+
node.isClosing = true;
|
|
191
|
+
if (node.reconnectTimer) {
|
|
192
|
+
clearTimeout(node.reconnectTimer);
|
|
193
|
+
node.reconnectTimer = null;
|
|
194
|
+
}
|
|
195
|
+
cleanupSocket();
|
|
196
|
+
setStatus("grey", "ring", removed ? "removed" : "closed");
|
|
197
|
+
done();
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
RED.nodes.registerType(NODE_TYPE, V430WebsocketBarcodeNode);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
function normalizeWebsocketPath(value) {
|
|
205
|
+
const trimmed = String(value || "").trim();
|
|
206
|
+
if (!trimmed) {
|
|
207
|
+
return DEFAULTS.websocketPath;
|
|
208
|
+
}
|
|
209
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function decodeFrame(frame, isBinary) {
|
|
213
|
+
const decoded = isBinary ? decodeBinaryFrame(frame) : parseTextFrame(frame);
|
|
214
|
+
if (decoded == null) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
decoded,
|
|
220
|
+
frameFormat: isBinary ? "msgpack" : "text",
|
|
221
|
+
decodedType: Array.isArray(decoded) ? "array" : typeof decoded
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function parseTextFrame(frame) {
|
|
226
|
+
const text = String(frame).trim();
|
|
227
|
+
if (!text) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
return JSON.parse(text);
|
|
233
|
+
} catch {
|
|
234
|
+
return text;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function decodeBinaryFrame(frame) {
|
|
239
|
+
const binary = frame instanceof Uint8Array ? frame : new Uint8Array(frame);
|
|
240
|
+
return decode(binary, { useBigInt64: false });
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function extractBarcodeData(decoded) {
|
|
244
|
+
if (typeof decoded === "string") {
|
|
245
|
+
return extractBarcodeFromString(decoded);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (decoded == null) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const barcode = findFieldValue(decoded, BARCODE_VALUE_KEYS);
|
|
253
|
+
if (!barcode) {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
barcode,
|
|
259
|
+
symbology: findFieldValue(decoded, SYMBOLOGY_KEYS),
|
|
260
|
+
cycle_id: null,
|
|
261
|
+
read_time_ms: null,
|
|
262
|
+
cycle_time_ms: null
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function extractBarcodeFromString(text) {
|
|
267
|
+
const cycleReport = extractCycleReport(text);
|
|
268
|
+
if (cycleReport) {
|
|
269
|
+
return cycleReport;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const barcode = text.trim();
|
|
273
|
+
if (!barcode || barcode.startsWith("<")) {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
barcode,
|
|
279
|
+
symbology: null,
|
|
280
|
+
cycle_id: null,
|
|
281
|
+
read_time_ms: null,
|
|
282
|
+
cycle_time_ms: null
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function extractCycleReport(text) {
|
|
287
|
+
if (!text.startsWith("<cycleReport")) {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const barcode = matchValue(text, /<outData>([\s\S]*?)<\/outData>/i, decodeXmlEntities);
|
|
292
|
+
if (!barcode) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return {
|
|
297
|
+
barcode,
|
|
298
|
+
symbology: null,
|
|
299
|
+
cycle_id: matchValue(text, /\bcycleId="([^"]+)"/i),
|
|
300
|
+
read_time_ms: toNumberOrNull(matchValue(text, /\breadTime="([^"]+)"/i)),
|
|
301
|
+
cycle_time_ms: toNumberOrNull(matchValue(text, /\bcycleTime="([^"]+)"/i))
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function matchValue(text, regex, transform = (value) => value) {
|
|
306
|
+
const match = text.match(regex);
|
|
307
|
+
if (!match) {
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const value = transform(match[1]).trim();
|
|
312
|
+
return value || null;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function decodeXmlEntities(value) {
|
|
316
|
+
return String(value || "")
|
|
317
|
+
.replace(/</g, "<")
|
|
318
|
+
.replace(/>/g, ">")
|
|
319
|
+
.replace(/&/g, "&")
|
|
320
|
+
.replace(/"/g, "\"")
|
|
321
|
+
.replace(/'/g, "'");
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function findFieldValue(rootValue, candidateKeys) {
|
|
325
|
+
const visited = new Set();
|
|
326
|
+
const queue = [rootValue];
|
|
327
|
+
|
|
328
|
+
while (queue.length > 0) {
|
|
329
|
+
const value = queue.shift();
|
|
330
|
+
if (value == null) {
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (typeof value === "object") {
|
|
335
|
+
if (visited.has(value)) {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
visited.add(value);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (Array.isArray(value)) {
|
|
342
|
+
queue.push(...value);
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (!isPlainObject(value)) {
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
for (const [key, nestedValue] of Object.entries(value)) {
|
|
351
|
+
if (candidateKeys.has(normalizeKey(key))) {
|
|
352
|
+
const candidate = asBarcodeString(nestedValue);
|
|
353
|
+
if (candidate != null) {
|
|
354
|
+
return candidate;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
queue.push(nestedValue);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function normalizeKey(value) {
|
|
365
|
+
return String(value || "").replace(/[^a-z0-9]+/gi, "").toLowerCase();
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function isPlainObject(value) {
|
|
369
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function asBarcodeString(value) {
|
|
373
|
+
if (value == null) {
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
if (typeof value === "string") {
|
|
377
|
+
const trimmed = value.trim();
|
|
378
|
+
return trimmed || null;
|
|
379
|
+
}
|
|
380
|
+
if (typeof value === "number" || typeof value === "bigint") {
|
|
381
|
+
return String(value);
|
|
382
|
+
}
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function toNumberOrNull(value) {
|
|
387
|
+
if (value == null) {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const number = Number(value);
|
|
392
|
+
return Number.isFinite(number) ? number : null;
|
|
393
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-red-contrib-v430-barcode",
|
|
3
|
+
"version": "0.2.6",
|
|
4
|
+
"description": "Node-RED node for streaming barcode data from an Omron V430 websocket endpoint.",
|
|
5
|
+
"main": "V430_barcode_reader.js",
|
|
6
|
+
"author": "Nicholas Cifuni",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"node-red",
|
|
10
|
+
"omron",
|
|
11
|
+
"v430",
|
|
12
|
+
"barcode",
|
|
13
|
+
"websocket",
|
|
14
|
+
"msgpack"
|
|
15
|
+
],
|
|
16
|
+
"files": [
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"README.md",
|
|
19
|
+
"V430_barcode_reader.html",
|
|
20
|
+
"V430_barcode_reader.js"
|
|
21
|
+
],
|
|
22
|
+
"node-red": {
|
|
23
|
+
"version": ">=3.0.0",
|
|
24
|
+
"nodes": {
|
|
25
|
+
"v430-websocket-barcode": "V430_barcode_reader.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test": "node --check V430_barcode_reader.js",
|
|
30
|
+
"prepublishOnly": "npm test"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@msgpack/msgpack": "^3.1.2",
|
|
40
|
+
"ws": "^8.18.3"
|
|
41
|
+
}
|
|
42
|
+
}
|