Details
This sample script shows how the communication can be disabled in the Communication Script until the device is rebooted. Sending the below command to the reader will close the connection from the Custom Communication Script:
||>CLOSE-CUSTOM-CONNECTION<CR><LF>
var openConnection = true;
const CMD_HEADER = "||>"
const CMD_TERMINATOR = "\r\n"
const CMD_COMMAND = "CLOSE-CUSTOM-CONNECTION"
function CommHandler() {
return {
onConnect: function (peerName) {
this.expectFramed(CMD_HEADER, CMD_TERMINATOR, CMD_COMMAND.length);
openConnection ? this.send("Custom connection is Connected.\r\n") : this.send("Custom connection is Disconnected.\r\n");
return openConnection;
},
onDisconnect: function () {
},
onExpectedData: function (inputString) {
if (inputString == CMD_COMMAND) {
openConnection = false;
this.close();
}
return true;
}
};
}