[add] refactor socket client
This commit is contained in:
parent
0f9590715c
commit
24e9a576ce
3 changed files with 56 additions and 10 deletions
34
tests/scripts/socket.js
Normal file
34
tests/scripts/socket.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
function onData(data, recvLen) {
|
||||
console.log(`Data: ${data} ${recvLen}`);
|
||||
log.Trace("onData: %v %v", data, recvLen);
|
||||
}
|
||||
|
||||
function onError(err) {
|
||||
console.log(`Error: ${err} `);
|
||||
}
|
||||
|
||||
function onClosed(data, err) {
|
||||
console.log(`Closed: ${data} ${err} `);
|
||||
}
|
||||
|
||||
function onConnected(option) {
|
||||
console.log("onConnected", option);
|
||||
}
|
||||
|
||||
// Convert a hex string to a byte array
|
||||
function hexToBytes(hex) {
|
||||
for (var bytes = [], c = 0; c < hex.length; c += 2) {
|
||||
bytes.push(parseInt(hex.substr(c, 2), 16));
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
// Convert a byte array to a hex string
|
||||
function bytesToHex(bytes) {
|
||||
for (var hex = [], i = 0; i < bytes.length; i++) {
|
||||
var current = bytes[i] < 0 ? bytes[i] + 256 : bytes[i];
|
||||
hex.push((current >>> 4).toString(16));
|
||||
hex.push((current & 0xf).toString(16));
|
||||
}
|
||||
return hex.join("");
|
||||
}
|
||||
|
|
@ -1,12 +1,17 @@
|
|||
{
|
||||
"name": "RFID Receiver (Server Mode)",
|
||||
"description": "RFID Receiver (Server Mode)",
|
||||
"description": "RFID Receiver",
|
||||
"mode": "server",
|
||||
"version": "0.9.2",
|
||||
"version": "0.0.1",
|
||||
"protocol": "tcp",
|
||||
"host": "0.0.0.0",
|
||||
"port": "3019",
|
||||
"process": "flows.rfid.read",
|
||||
"buffer": 60,
|
||||
"keep": 0
|
||||
"event": {
|
||||
"data": "scripts.socket.onData",
|
||||
"closed": "scripts.socket.onClosed",
|
||||
"connected": "scripts.socket.onConnected",
|
||||
"error": "scripts.socket.onError"
|
||||
},
|
||||
"keep": 0,
|
||||
"buffer": 60
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,19 @@
|
|||
{
|
||||
"name": "RFID Receiver (Client Mode)",
|
||||
"description": "RFID Receiver (Client Mode)",
|
||||
"description": "RFID Receiver",
|
||||
"mode": "client",
|
||||
"version": "0.9.2",
|
||||
"protocol": "tcp",
|
||||
"host": "192.168.1.192",
|
||||
"port": "6000",
|
||||
"process": "flows.rfid.read",
|
||||
"host": "192.168.31.33",
|
||||
"port": "3019",
|
||||
"event": {
|
||||
"data": "scripts.socket.onData",
|
||||
"closed": "scripts.socket.onClosed",
|
||||
"connected": "scripts.socket.onConnected",
|
||||
"error": "scripts.socket.onError"
|
||||
},
|
||||
"buffer": 60,
|
||||
"keep": 0
|
||||
"keep": 0,
|
||||
"attempts": 9,
|
||||
"attempt_after": 10
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue