Skip to Main Content
Centre d’assistance Cognex
LogoLogo

Script - Disabling Currently Running Custom Communication Protocol

If there is a Communication Script running on the DataMan device, then it can happen that the reader cannot respond to DMCC commands, or in case of serial connection, DataMan Setup Tool is not able to connect. This sample script shows how the communication can be disabled in the Communication Script until the device is rebooted.

30/03/2025

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;
       }
   };
}

Ressources connexes

Loading component...