Communications and Programming
Communications and Programming
2024 January 04
Revision: 24.1.0.2
Legal Notices
Legal Notices
The software described in this document is furnished under license, and may be used or copied only in accordance with the
terms of such license and with the inclusion of the copyright notice shown on this page. Neither the software, this document,
nor any copies thereof may be provided to, or otherwise made available to, anyone other than the licensee. Title to, and
ownership of, this software remains with Cognex Corporation or its licensor. Cognex Corporation assumes no responsibility
for the use or reliability of its software on equipment that is not supplied by Cognex Corporation. Cognex Corporation makes
no warranties, either express or implied, regarding the described software, its merchantability, non-infringement or its fitness
for any particular purpose.
The information in this document is subject to change without notice and should not be construed as a commitment by
Cognex Corporation. Cognex Corporation is not responsible for any errors that may be present in either this document or the
associated software.
Companies, names, and data used in examples herein are fictitious unless otherwise noted. No part of this document may be
reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, nor transferred to any
other media or language without the written permission of Cognex Corporation.
Copyright © 2023. Cognex Corporation. All Rights Reserved.
Portions of the hardware and software provided by Cognex may be covered by one or more U.S. and foreign patents, as well
as pending U.S. and foreign patents listed on the Cognex web site at: cognex.com/patents.
Other product and company trademarks identified herein are the trademarks of their respective owners.
2
Table of Contents
Table of Contents
Legal Notices 2
Table of Contents 3
Symbols 5
About This Manual 6
Networking 7
Connecting Your DataMan to the Network 7
Connecting Your Fixed-Mount DataMan Reader to the Network 7
Connecting Your Handheld DataMan Reader to the Network 7
Connecting Your Wireless DataMan 8050 Reader to the Network 8
Ad-hoc Connection 8
Infrastructure Mode Connection (DM8050) 9
EAP-TLS Authentication Mode (DM8050) 10
Error Management 33
Formatting Script 33
Output 60
Code Completion and Snippets 62
Custom Communication Protocol API 64
3
Table of Contents
Event Callback 91
Event Types 91
Examples 92
4
Symbols
Symbols
The following symbols indicate safety precautions and supplemental information:
WARNING: This symbol indicates a hazard that could cause death, serious personal injury or electrical shock.
CAUTION: This symbol indicates a hazard that could result in property damage.
Tip: This symbol indicates suggestions and shortcuts that might not otherwise be apparent.
5
About This Manual
The DataMan reader acquires images by several methods when connected to a network:
l using the DataMan Setup Tool
l trigger bits
l through a DMCC command
l manipulating objects through industrial protocols
For information on industrial protocols, see the DataMan Industrial Protocol Manual. All the other methods are explained in
detail in this document.
6
Networking
Networking
You can connect your DataMan device via a simple Ethernet connection. You can either set the IP address and subnet mask
of your DataMan device manually or let them be configured automatically using DHCP.
1. Connect the PoE injector to the Ethernet network (both ends of the patch cable).
2. Connect the power cord (AC 230V/110V) to the PoE injector.
3. Connect the reader to the PoE injector.
7
Networking
If you are using a serial slide-in with your handheld DataMan reader, connect the serial cable to your PC, power your reader
through an external power supply and connect your PC to the network.
Ad-hoc Connection
The default factory settings for the wireless configuration of the device are:
l ad-hoc connection
l no encryption and no authentication
l SSID: the name of the device
This means that you can connect to your DataMan without the Base Station or a router.
To connect to your DataMan reader in ad-hoc mode, perform the following steps:
8
Networking
9
Networking
10
Networking
Certificate Files
In the DataMan Setup Tool, the following restrictions apply to the PEM files:
l Their format must be the industry-standard PEM format (generated by OpenSSL toolkit).
l The PEM dialect may be either PKCS8 or SSLeay.
l Only an unencrypted private key and certificate files are allowed.
l The Client’s private key and certificate must contain exactly one section; the CA’s certificate can contain one or more
certificates.
l Make sure that you know the user name stored within your own certificate file, and use the same name in the Client’s
user name text box. This is necessary because the DataMan Setup Tool does not look into the certificate files to
extract this user name information.
When you leave the Wireless tab, a reboot confirmation window pops up and the settings are saved to the device.
11
Networking
Note: If the reader display shows a router icon, the reader is already configured to connect to a Wi-Fi network. If
you want to connect to the reader in AP mode, navigate to Settings > Communication > Connect > Reset to
AP Mode on the reader display, or reset the reader to factory default.
Note: If the network of the reader is not visible, it means the reader is already configured to connect to a Wi-Fi
network.
Note: The passphrase always starts with CGNXPW, and continues with the last six numbers of the serial
number of the device. The reader display can show the actual AP mode passphrase. To reach the AP mode
passphrase, navigate to Wi-Fi Connection Status > AP Passphrase.
Now you can configure your reader using the DataMan Setup Tool.
12
Networking
Note: Check the Wi-Fi connection in Windows if the reader is not listed in the DataMan Setup Tool.
3. Navigate to the Communications application step and choose the Wi-Fi tab.
13
Networking
Note: The layout of this dropdown menu can change depending on the country code of your reader.
14
Networking
6. Select the Authentication mode your network uses. Enter the passphrase if needed.
7. Save the changes and reboot the reader by clicking on the triangle icon in the upper-right corner.
While the reader reboots, it connects to the Wi-Fi network. You can confirm this on the reader screen, which displays a router
icon with signal strength indicator. Up to ten seconds delay can occur until the signal shows up.
15
Networking
Note: If the reader display shows a router icon with a red X, it means the reader failed to connect to the network, or the
reader is out of range. Make sure your settings are correct.
16
Networking
A short message shows if a certificate is specified. The text “<not set>” appears in the field if there is no key or certificate
specified. If the certificate is not uploaded, the check mark is not green and the text "Please upload before rebooting"
appears.
Certificate Files
In the DataMan Setup Tool, the following restrictions apply to the PEM files:
l Their format must be the industry-standard PEM format (generated by OpenSSL toolkit).
l The PEM dialect may be either PKCS8 or SSLeay.
l Only an unencrypted private key and certificate files are allowed.
l The Client’s private key and certificate must contain exactly one section; the CA’s certificate can contain one or more
certificates.
l Make sure that you know the user name stored within your own certificate file, and use the same name in the Client’s
user name text box. This is necessary because the DataMan Setup Tool does not look into the certificate files to
extract this user name information.
When you leave the Wireless tab, a reboot confirmation window pops up and the settings are saved to the device.
1. If you use DMA-IBASE-00, power up your Base Station using one of these two options:
l If you want to connect the Ethernet cable directly to the network or your PC, power up the Base Station using
a 24V power supply.
17
Networking
l If you want to use a Power over Ethernet (PoE) adapter, that will power up your Base Station. If you use the
DMA-IBASE-BT-01 Base Station, use direct connection with a 24V power supply. DMA-IBASE-BT-01 offers
a 3-pin terminal block:
Pin # Signal
1 +24V
2 Shield
3 GND
Note: Never connect the terminal block and barrel connector power supply at the same time.
3. The Base Station becomes visible as connected through Ethernet, and it routes data through the wireless (Wi-Fi or
Bluetooth) interface to the reader.
18
Networking
Note:
When you connect the Base Station through USB, always use a power supply. When using a DM8700 with a
USB cable (DMC-HH-USBA-02 or DMC-HH-USBC-02) or Base Station, make sure to connect the USB
connector to a USB hub that stays enabled even if the PC or notebook goes to sleep. Otherwise, the Base
Station cannot charge the reader when the computer is in sleep mode.
2. The Base Station becomes visible as connected through either RS-232, USB, or Ethernet.
Note: You cannot configure the Base Station to act as a network client.
The Base Station transfers data to the reader with the following methods:
l through the wireless interface
l through the cradle USB, when the reader is placed on the Base Station
19
Networking
Note: Remember to update the IP address of your DataMan device. The IP address that is copied belongs to your PC.
A triangle with an exclamation mark in the upper right-hand corner reminds you that you have to reboot the device in order for
the changes to take effect.
To force the network settings on your DataMan, select Use Static IP Address and enter an IP Address and Subnet Mask
that will be on the same subnet as the PC. Make sure this IP address is not yet in use (for example, test by pinging it). For
example:
l IP Address: 169.254.135.200
l Subnet Mask: 255.255.0.0
Note: The default Subnet Mask is 255.255.255.0. You can set it back to default by scanning the Reset Scanner to
Factory Defaults Configuration Code.
20
Networking
Your DataMan device is now configured to the specified network settings, and it reboots automatically. After the address has
been resolved, your DataMan device appears under the Network node. This can take up to 60 seconds. If the device does
not appear after 1 or 2 minutes, press the Refresh button in the DataMan Setup Tool’s Connect page. This will force the
DataMan Setup Tool to scan for DataMan devices connected to the PC or connected to the same network.
21
Networking
Once the IP Address and Subnet Mask of the DataMan device are known, the PC’s network settings can be changed.
Perform the following steps to configure your PC (examples here are of Windows XP):
1. In the Start Menu, start typing Control Panel and open it.
2. Click Network and Internet.
3. Click Network and Sharing Center and under active networks, click Ethernet.
22
Networking
5. In the Ethernet Properties window that pops up, select Internet Protocol Version 4 (TCP/IPv4) and click
Properties.
6. Under the General tab, select the Use the following IP address option and enter an IP address and Subnet mask
that are on the same subnet as your DataMan. Click OK.
23
Networking
7. Click Close. The network settings of your PC will change to the new specified values.
8. Reboot the DataMan device. It appears under the Discovered Devices node on the Connect page after the network
address has been resolved.
9. If the device does not appear after 1 or 2 minutes, click the Refresh button on the DataMan Setup Tool’s Connect
page. The DataMan Setup Tool scans for DataMan devices connected to the PC or connected to the same network.
1. In the DataMan Setup Tool’s Reader Maintenance page, click Add Network Device.
24
Networking
3. Click OK. The reader appears under the Network node. Double click the new node or select it and click the Connect
button. If the device is available, the reader will be connected.
25
DataMan Application Development
Note: For a complete list of DMCC commands, click the Windows Start menu and browse to Cognex -> DataMan Setup
Tool v x.x -> Documentation -> Command Reference. Alternatively, you can open the Command Reference through the
Setup Tool Help menu.
DMCC Overview
DataMan Control Commands (DMCC) are a method of configuring and controlling a DataMan reader from a COM port, either
directly or programatically through a custom application. Depending on the DataMan reader you are using, the COM port
connection can be either RS232, USB, or the Telnet protocol in the case of Ethernet capable readers. By default, Ethernet
capable readers are configured to communicate over TCP port number 23, but you can use the DataMan Setup Tool to
assign a different port number as necessary.
Note: Use a third party client such as PuTTY to make changes to the Telnet client provided by Windows to
communicate with the DataMan.
Command Syntax
All DMCC commands are formed of a stream of ASCII printable characters with the following syntax:
command-header command [arguments] footer
For example:
||>trigger on\CR\LF
All options are colon separated ASCII text. A header without the header-option block will use header defaults.
checksum
0: no checksum (default)
Header Examples
Example Description
||> Default Header
||0:123> Header indicating no-checksum and ID of 123
||1> Header indicating checksum after command and data.
Command
The command is an ASCII typable string possibly followed by data. All command names and public parameters data are case
insensitive. Only a single command can be issued within a header-footer block. Commands, parameters and arguments are
separated by a space character.
26
DataMan Application Development
Commands
Short names specifying an action. A commonly used command is GET or SET followed by a Parameter and Value.
Parameters
Short names specifying a device setting. Parameter names are organized with a group of similar commands with one level of
structural organization separated by a period ('.').
Arguments
Boolean: ON or OFF
Integer: 123456
String: ASCII text string enclosed by quotes (“).The string content is passed to a function to translate the string to the final
format. The following characters must be backslash escaped: quote (\”), backslash (\\), pipe (\|), tab (\t), CR(\r), LF (\n).
Footer
The footer is a carriage return and linefeed (noted as \CR\LF or \r\n).
Reader Response
The reader will have one of several response formats. The choice of response format is configured using the SET
COM.DMCC-RESPONSE command.
Silent: (0, Default) No response will be sent from the reader. Invalid commands are ignored without feedback. Command
responses are sent in space delimited ASCII text without a header or footer.
Extended: (1) The reader responds with a header data footer block similar to the command format.
Note: While the reader can process a stream of DMCC commands, it is typically more robust to either wait for a
response, or insert a delay between consecutive commands.
||checksum:command-id[status]
checksum
The response uses the same checksum format as the command sent to the reader.
0: no checksum
1: last byte before footer is XOR of bytes
command-id
27
DataMan Application Development
Examples
Command Silent Response Extended Response Description
||>GET ON ||[0]ON\r\n Is the DataMatrix symbology enabled?
SYMBOL.DATAMATRIX\r\n
||>SET no response ||[0]\r\n Enable the DataMatrix symbology.
SYMBOL.DATAMATRIX
ON\r\n
||>TRIGGER ON\r\n decoded data or ||[0]\r\n ||[1]decoded Trigger Command
no-read response data or no-read
response in base64\r\n
Example
Command Response
||>GET DEVICE.NAME\r\n DM8700Base-86F30A
||>SET COM.DMCC-TARGET 1\r\n no response
||>GET DEVICE.NAME\r\n DM8700DX-8E6FD0
||>SET COM.DMCC-TARGET 0\r\n no response
||>GET DEVICE.NAME\r\n DM8700Base-86F30A
Scripting
DataMan readers offer script-based customization options to adapt data formatting, communication handling, and FTP
naming. The system loads the corresponding scripts and executes their global contexts in the following order:
1. FTP naming
2. Communication
3. Data formatting
28
DataMan Application Development
When you define symbols in one script and try to access them from the global context of another script, consider the loading
order to avoid attempting to access symbols that are not yet defined.
Note: Script-based formatting limits the user to performing two custom events and overwriting the system event.
The functions make use of the variable arguments feature of the script engine. The types of the function arguments are
compared to the expected types defined by the DMCC commands. If the number of arguments or an argument type is
incorrect an error status is returned.
The functions return an object with a property for the status. If a command returns a response it can be accessed by the
response property. The status codes are the same as for the DMCC commands.
If a function executes successfully, a zero status value is returned. Script exceptions are not used.
To simplify the integration of DMCC commands in scripting, it is now possible to evaluate a DMCC command line as full
command string. It is not required to split the DMCC command into the type correct command arguments.
Note:
l The data formatting script function is executed after the output delay time or distance elapsed.
l All scripting functions run in a separate thread and the execution is mutual exclusive. It is not possible that a
script function is interrupted by another.
l Use [0,1] or [true,false] instead of [ON|OFF] when scripting.
DMCC Description
dmccGet Based on the DMCC implementation the response is always returned as a single string even for multi-
value responses.
dmccSet It supports multiple and type correct parameters.
dmccCommand N/A
dmccSend The functions evaluates a DMCC command. The return value contains the dmcc response type
containing status and response string. The function requires one string argument.
Example
var foo = dmccGet(”DECODER.ROI”);
The set command supports multiple and type correct parameters, for example:
29
DataMan Application Development
Example
The following example uses the dmccSet functions to issue a beep signal, set the ftp server IP for image storage and adds
the MAC to the output response:
var myoutput;
var result_tmp = dmccCommand(”BEEP”, 1, 1);
}
var mac = dmccGet(”DEVICE.MAC-ADDRESS”);
In case the DMCC set command for the IP address fails, a non-zero status will be returned, and a script exception will be
thrown that is reported by the DataMan Setup Tool.
Note: If you use the Throw() command, like in the example above, to report the occurrence of an anomalous situation
(exception), the error will appear in the Setup Tool’s error log. To access the error log, in the Setup Tool’s menu bar,
click System and then click Show Device Log.
Example
To get the device name using the dmccGet function the correct string argument is required:
The dmccSend function can be used in a similar way, but without splitting the command and type correct arguments:
DMCC Support
The following DMCC commands are available for Script-Based Formatting:
30
DataMan Application Development
Auxiliary Functions
The following auxiliary global functions are also available:
l function for decoding escape sequences
l function to encode a string argument into base64 encoding
Function decode_sequences
This global function is used to decode escape sequences. The function returns the string that contains the decoded escape
sequence. The return value can be used to add keyboard control commands to a result transmitted over a HID connection.
To simulate Alt-key, Ctrl-key, or Shift-key combinations, the following four escape sequences are available:
l \ALT- for <ALT-key> sequences
l \CTRL- for <CTRL-key> sequences
l \SHIFT- for <SHIFT-key> sequences
l \K for special keys
Note: The key after the backslash needs to be a capital letter, otherwise no special key combination is recognized.
31
DataMan Application Development
if (decodeResults[0].decoded)
{
output.content = ctrl_b+decodeResults[0].content+ctrl_b;
Note: The backslash for initiating the escape sequence must also be escaped in the input string. The terminating
semicolon is necessary to be able to distinguish between sequences with the same prefix, otherwise key sequences
could be interpreted arbitrarily, e.g. there would be no means to detect if \KF11 means "press F11" or "Press F1
followed by a one”. If a wrong or incomplete sequence is used, the two characters which mark the escape sequence are
ignored. In this case, the first two letters of the escape sequence are skipped and the remaining characters will be sent.
For example, the sequence "\ALT-M11;" is invalid and will result in displaying "LT-M11;".
Function encode_base64
This global function is used to encode a string argument into base64 encoding. The encoded result is returned as a string
object.
32
DataMan Application Development
Error Management
Scripting errors may occur when the script is loaded or the code parser function is called. These errors are shown in the
following locations:
l device log
l error box in Script-Based Formatting window
Formatting Script
When script-based formatting is enabled, a user-defined JavaScript module is responsible for data formatting. The parsing
function, which defaults to onResult, is called with three objects as arguments holding the array of DecodeResult objects,
ReaderProperties objects such as trigger mode or statistics, and the output object. There is only one entry point for both
single and multicode results.
Class hierarchy is structured in the following way:
DecodeResult
SymbologyProperties
Point
ValidationResult
GS1Validation
DoDValidation
QualityMetrics
Metric
ReaderProperties
Trigger
Statistics
Output
Event
Function onResult
This is the event handler for decode events, with zero, one or more decoded results.
Function onGenerateFTPFilename
The name of the file to be sent to the FTP server can be generated with this function.
33
DataMan Application Development
decodeResults DecodeResult[] Input, an array of DecodeResult objects. One decode result will hold all
information related to that decode attempt.
readerProperties ReaderProperties Input, the reader properties not tied to the actual decode result.
output Output Output, the object which needs to be updated to modify the output string
or raise events.
The file name of the image to be uploaded is taken from the string return value of the script. For example:
}
function onGenerateFTPPCMReportFilename(decodeResults, readerProperties, output)
{
DecodeResult Object
The following tables list the details of the DecodeResult object, its types and properties.
Decode Result
Describes the details of one decoded result.
34
DataMan Application Development
Symbology Properties
PtpTimeStamp
Peer to peer timestamp value on image acquisition.
35
DataMan Application Development
Point
Point is the ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional plane.
ImageProperties Object
The following tables list the details of the ImageProperties object, its types and properties.
Image Properties
Properties of a captured image.
Rect
Rect describes the width, height, and location of a rectangle.
36
DataMan Application Development
top integer This specifies the top value relative to the top left sensor corner.
bottom integer This specifies the bottom value relative to the top left sensor corner.
left integer This specifies the left value relative to the top left sensor corner.
right integer This specifies the right value relative to the top left sensor corner.
Note: The following TruCheck metrics are only available for devices with TruCheck verifier capability, such as the
DM475 Verifier and the DM8072 Verifier.
TruCheckMetric
A graded verification parameter that has a measurement associated with it.
TruCheckMetricGradeOnly
A graded verification parameter that has a measurement associated with it.
TruCheckApplicationStd
TruCheckCodeword
TruCheckEncodationAnalysis
TruCheckMetricGeneral
37
DataMan Application Development
TruCheckMetricModulation
TruCheckMetricOverall
TruCheckResult
38
DataMan Application Development
39
DataMan Application Development
ValidationResult Object
The following tables list the details of the ValidationResult object, its types and properties.
Validation Result
Describes all details of the validation.
40
DataMan Application Development
GS1Validation
GS1 validation details.
41
DataMan Application Development
42
DataMan Application Development
43
DataMan Application Development
DoD Validation
DoD validation details.
QualityMetrics Object
The following tables list the details of the QualityMetrics object, its types and properties. The details of the Metric property
type are listed in the Metric table below. All the metrics listed are available for all the standards available under the
Symbology Settings pane in the DataMan Setup Tool.
Quality Metrics
Describes the quality of all measured parameters.
44
DataMan Application Development
45
DataMan Application Development
46
DataMan Application Development
47
DataMan Application Development
48
DataMan Application Development
49
DataMan Application Development
50
DataMan Application Development
51
DataMan Application Development
52
DataMan Application Development
53
DataMan Application Development
54
DataMan Application Development
55
DataMan Application Development
56
DataMan Application Development
Metric
Describes the quality of a measured parameter.
Barcode Assignment
57
DataMan Application Development
Stats
Reader Properties
The following tables list the details of the reader properties.
ReaderProperties
Reader properties not tied to the actual decode result.
Trigger
Describes the details of the initiating trigger event.
58
DataMan Application Development
Statistics
Operational information about the reader.
59
DataMan Application Development
Status3D
Output
Output describes the result and events after a decode. It is possible to specify different results for individual protocol targets.
The output object has target-specific properties of type string. The name of the output property is the same as the target
protocol name. If no target-specific output is assigned, the result falls back to the default result taken from the output.content
property.
*These properties suppress the output information that was previously set via the output.content property.
An example for the protocol-specific formatting feature can be found here:
60
DataMan Application Development
if (decodeResults[0].decoded)
{
output.content = mymsg;
}
else
{
output.content = ”bad read”;
}
Note: For every channel that is not addressed in special, the output is the normal content text. For example:
if (decodeResults[0].decoded)
{
}
else
{
DecodeEvents
Describes the events to be emitted after a decode.
61
DataMan Application Development
62
DataMan Application Development
The toolbar at the top of the editor collects the following actions available within the editor:
l Cut (Ctrl-x)
l Copy (Ctrl-c)
l Paste (Ctrl-v)
l Complete Word (Ctrl-k and then press w)
l Insert Snippet (Ctrl-k and then press x)
Snippets
The editor provides a selection of preset code fragments as examples. You can insert these snippets by right-clicking in the
editor, using the toolbar or using the Ctrl-k and x key combination.
63
DataMan Application Development
The user must implement these functions, as the custom communications function will call them.
l There are five member functions that the reader script engine offers, implemented by the reader:
n send
n close
n setTimer
n expectFramed
n setEncoder
By using these functions, a user could write javascript code that allows the reader to interact with another system. In
particular, the user can write code to send messages back to the other system, something that is not supported in basic
scripting.
Advantage
The script engine uses the same context for function execution and object creation. This allows the sharing of data between
the script-based formatting and the custom communication scripts using global accessible objects.
List of functions
The communication member functions define the following method prototypes to be implemented by the user:
CommHandler – The constructor function for the communication object. The constructor must return a new communication
handler object implementing the user methods in the communication script. The reader methods are added to the
communication handler object directly after construction. The implementation of the constructor is mandatory and an error
will be thrown if it does not exist. Since software version 5.5 the constructor function call offers the following argument:
o localName: The local name of the connection. The local name of a network connection is ”<READER_IP>:<PORT>”.
An example for a Telnet connection is “10.82.80.156:23” with the default telnet port of 23. An example for a Network
Client connection is “10.82.80.156:57350”. The local name for the serial connection is “COM1” or “COM USB”. The
local name for the HID connection is “keybrd”.
64
DataMan Application Development
o onConnect – Initialize state upon connection (a network connection established or protocol stack starts on serial
connection). If the method is not implemented an error occurs. The method has one argument and a return value:
l peerName – The peer name of the connection. The peer name for a network connection is ”<PEER_
IP>:<PORT>”. An example peer name for a Telnet connection is “10.82.80.71:19772”, for a “Network Client”
connection it is “10.82.80.71:1000”, where the host port is configured to 1000. The peer name for the serial
connection is “COM1” or “COM USB”. The peer name for the HID connection is “keybrd”.
l return – The boolean return value defines if the handler for this connection should be activated:
n true: Enables customization of the communication protocol. Therefore, if you want to use your own
protocol for communicating with the Dataman device, return true.
n false: If you do not need the customized protocol for this peer, return false.
o onDisconnect – Cleanup method called when closing the connection channel
o onExpectedData – Method called if data matching the set properties has arrived. The method has one argument:
l inputString – The received frame matched data excluding header and termination
l return – Determines if the data should be removed from input buffer
n true: clear the buffer.
n false: keep the value in buffer.
o onTimer – The timer value expired
o onUnexpectedData – The recieved data is not matching the requirements. The boolean return value determines if
the data should be removed from input. The method has one argument:
l inputString – The received data
l return – Determines if the data should be removed from input buffer
n true: clear the buffer.
n false: keep the value in buffer.
o onError – An error occurred in the firmware and can be reported. The implementation of the method is mandatory.
The method has one argument and no return value:
l errorMsg – The error message for trigger overruns (“Trigger Overrun”), buffer overruns (“Buffer Overflow”)
and general errors reported by the firmware.
o onEncoder – Executed if a configured encoder distance is reached. The distance can be configured by the
setEncoder method. The method has no arguments or return value.
o send – Send data to channel, returns the number of send characters. The method must be called with one argument:
l Data argument is a string
o close – Actively terminates connection for the communication object (for example, close TCP/IP socket). On UART,
this causes onConnect to be called right afterwards.
o setTimer – Set the one-shot timer value when the onTimer will be executed. The timer can be re-initialized and
aborted.
l Timeout in seconds of type double, internal resolution is us (1e-6 sec). A zero value aborts a running timer.
Active timer will be overwritten.
65
DataMan Application Development
o expectFramed – Tells the communication listener which data to pass on to the onExpectedData and
onUnexpectedData methods. It is possible to change the match parameter at runtime. The following three arguments
are required:
n header of type string, can be empty (””)
n terminator of type string, can be empty (””)
n max length of type integer, specifies the maximum length of an input message to check for a match [required]
o setEncoder – Units of the distance argument are millimetres. The encoder is configured in Setup Tool under System
Settings -> Pulse Encoder. If encoder ticks should be used instead of distance set the value of the parameter
“Resolution (mm)” to 1.
n distance (double) – The encoder distance in which the onEncoder method will be called.
66
DataMan Application Development
function CommHandler()
{
var num_trigger = 0;
var num_send;
function onTimeout2()
{
dmccCommand("TRIGGER", true);
this.setTimer(1.0);
function replace_crlf(input_str)
{
return {
my_name = peerName;
// we may ignore the connection
if(my_name == "COM1")
return false;
},
onDisconnect: function ()
{
},
msg = 'done';
}
else if (inputString == "close")
{
this.close();
}
else if (inputString == "stop")
{
this.setTimer(0.0);
}
else if (inputString == "start")
{
this.setTimer(10.0);
}
else if (inputString == "switch")
{
this.onTimer = onTimeout2;
}
else if (inputString == "time")
{
}
else
{
},
return true;
},
onTimer: onTimeout
};
} 68
DataMan Application Development
69
DataMan Application Development
// Data Formatting:
if (decodeResults[0].decoded) {
output.content = decodeResults[0].content+'\r\n';
for (var i = 0; i < comm_handler.length; i++)
{
comm_handler[i].resetHeartBeat();
// Communication:
// Heart beat example without disturbing the DMCC communication function CommHandler() {
return {
peer_name = peerName;
this.resetHeartBeat(); // initial timer
this.expectFramed("\0", "\0", 128); // some pattern
unlikely to happen
comm_handler.push(this); // register the handler for
results
// enable the handler for this connection:
return true;
},
onDisconnect: function ()
{
},
onError: function (errorMsg)
{
},
onExpectedData: function (inputString) {
return false;
},
onTimer: function () {
resetHeartBeat: function () {
this.setTimer(beat_timer); // schedule next timer event [sec]
}
};
71
DataMan Application Development
// communication script
var time_offset=0;
function CommHandler()
{
var peer_name;
return {
peer_name = peerName;
this.expectFramed("||;1>SET TIME.NOW ", "\r\n", 128); //
some pattern unlikely to happen
// enable the handler for this connection:
return true;
},
onDisconnect: function ()
{
},
onError: function (errorMsg)
{
},
onExpectedData: function (inputString) {
realTime = parseInt(inputString)*1000;
localTime = (new Date()).getTime();
time_offset = realTime - localTime;
this.send("||[0]\r\n");
return true;
},
72
DataMan Application Development
return false;
},
onTimer: function () {
}
};
73
DataMan Application Development
var CMF400_PROTOCOL_STATUS =
{
};
// make the enum non-modifyable
Object.freeze(CMF400_PROTOCOL_STATUS);
// TODO: how to configure parameter, where to store them with a out of stock firmware?
var cmf400_protocol_profibus_node_number = 1;
var cmf400_protocol_profibus_mode = 1;
var cmf400_protocol_test_diagnostic_enabled = 0;
// Protocol strings
var cmf400_gateway_init = '+Gateway-Init+';
var cmf400_gateway_ident_ok = '+GW SOK TSICDPS';
var cmf400_gateway_ident_no = '+GW SNO TSICDPS';
var cmf400_gateway_run = '+GW-RUN+';
var cmf400_gateway_error = '+GW-ERR';
74
DataMan Application Development
function CommHandler()
{
function _configTimedOut()
{
if (cmf400_status == CMF400_PROTOCOL_STATUS_CONFIGURING)
{
cmf400_status = CMF400_PROTOCOL_STATUS_STOPPED;
this.setTimer(30.0);
onTimer = _onSync;
function _onSync()
{
if (cmf400_status == CMF400_PROTOCOL_STATUS.SYNCRONIZING)
this.send(cmf400_protocol_stx + cmf400_gateway_init +
cmf400_protocol_etx);
this.setTimer(1.0);
onTimer = _onSync;
}
function _onTimer()
{
if (cmf400_status == CMF400_PROTOCOL_STATUS.STOPPED)
{
cmf400_status = CMF400_PROTOCOL_STATUS.SYNCRONIZING;
return;
return {
},
onDisconnect: function ()
{
},
onExpectedData: function (inputData)
{
data = inputData.slice(1,inputData.length-1);
if (cmf400_status == CMF400_PROTOCOL_
STATUS.SYNCRONIZING)
{
cmf400_status = CMF400_PROTOCOL_
STATUS.CONFIGURING;
var msg = cmf400_protocol_stx;
}
if (data == cmf400_gateway_error)
{
cmf400_status = CMF400_PROTOCOL_
STATUS.STOPPED;
this.setTimer(30.0);
this.onTimer = _onTimer;
}
else if (data == cmf400_gateway_run) // missing check
for status, e.g. CMF400_PROTOCOL_STATUS.CONFIGURING?
{
cmf400_status = CMF400_PROTOCOL_STATUS.RUN;
this.setTimer(0);
this.onTimer = _onTimer;
}
return true;
},
onUnexpectedData: function (inputData)
{
76
// ignore all unexpected data
DataMan Application Development
77
DataMan Application Development
// the constructor:
function CommHandler()
{
var num_trigger = 0;
var my_name;
var num_send = 99;
function privFunc ()
{
}
return {
my_name = peerName;
num_send = this.send(my_name + ": connected\r\n");
num_send = this.expectFramed("\x02", "\x03", 128);
return true;
},
onDisconnect: function ()
{
},
onExpectedData: function (inputString) {
input_string = inputString;
return true;
},
};
78
DataMan Application Development
if (decodeResults[0].decoded)
{
FMPCS protocol
79
DataMan Application Development
dmccSet('TRIGGER.TYPE', 0);
dmccSet('SYMBOL.4STATE-IMB', 1);
dmccSet('SYMBOL.DATAMATRIX', 1);
dmccSet('SYMBOL.I2O5', 1);
dmccSet('SYMBOL.PDF417', 1);
dmccSet('SYMBOL.POSTNET', 1);
function CommHandler()
{
var ErrorToId = {
return {
},
onError: function (msg) // TODO: this is new!
{
80
DataMan Application Development
bConnected = false;
},
case 'B':
dmccCommand("TRIGGER", true);
break;
case 'E':
dmccCommand("TRIGGER", false);
break;
case 'I':
match = package_id_
expr.exec(input);
packageID = match[1];
if(match[2])
tray = match[2];
else
tray = "0000";
break;
81
DataMan Application Development
case 'C':
}
break;
case 'P':
this.send('Q\r\n');
break;
case 'Q':
}
return true;
},
onUnexpectedData: function (input) {
return true;
}
};
}
The data formatting formats the result based on global variables set by the communication handler:
82
DataMan Application Development
function getFixedPsocId(id_)
{
var id = id_;
switch (id.charAt(1))
{
case 'd':
id = "[D0";
break;
case 'X':
switch (id.charAt(2))
{
83
DataMan Application Development
case '0':
case '1':
id = "[P0";
break;
case '2':
case '3':
id = "[L0";
break;
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
id = "[O0";
break;
}
break;
}
return id;
}
function onResult (decodeResults, readerProperties, output)
{
if(!decodeResults[i].decoded)
continue;
switch (decodeResults[i].symbology.name)
{
continue;
if (decodeResults[i].content.length >
lengthLimit)
continue;
case 'PDF417':
if (decodeResults[i].content.length >
lengthLimit)
continue;
default:
84
my_decode_results.push(decodeResults[i]);
DataMan Application Development
msg += ',?';
output.content = "no result";
}
else
{
switch (my_decode_results[i].symbology.name)
{
msg += my_decode_results
[i].content;
}
packageID = "000000000"; // reset the package id
output.Telnet = output.Serial = msg + '\r\n';
85
DataMan Application Development
function CommHandler()
{
return {
},
onDisconnect: function ()
{
},
onExpectedData: function (inputString) {
dmccSet("DVALID.PROG-TARG", i);
dmccSet("DVALID.MATCH-STRING", new_match_
string);
}
// The following DMCC command resets all statistic
values
// the CR reset only a view of them
dmccCommand("STATISTICS.RESET");
}
this.send("DEBUG: "+inputString + "\r\n");
return true;
},
onUnexpectedData: function (inputString) {
return true;
},
onTimer: function (inputString) {
}
};
}
86
DataMan Application Development
output.content = '';
output.SetupTool = decodeResults[0].content;
if (decodeResults[0].decoded) {
87
DataMan Application Development
// Parameter:
var system_id = '\x43'; // the system ID
var heartbeat_time_s = 5.0; // heartbeat timer in sec [0-50] (0 is disabled)
var append_crlf = true; // wether to
function CommHandler()
{
function getChecksum(data)
{
var sum = 0;
for(var i = 0; i < data.length; i++)
sum += data.charCodeAt(i);
return 0x7F - (sum % 0x7f);
var TelegramState = {
};
var errorCodes = {
undef_index: 0x31,
multi_index: 0x32,
index_in_use: 0x33,
telegram_error: 0x34,
trigger_overrun: 0x40,
buffer_overflow: 0x41,
};
var telegram_types = {
// initialization: J
// index: S
var telegram;
var status;
var index;
var all_index = new Array();
return { 88
DataMan Application Development
if (!index)
{
this.sendErrorTelegram(errorCodes.undef_index);
index = '9999';
data += index;
for (var i = 0; i < decodeResults.length; i++) {
length = decodeResults[i].content.length;
data += String.fromCharCode(length / 256, length % 256);
length += decodeResults[i].content.length;
data += decodeResults[i].content;
}
if (length & 0x1)
data += filler;
data += String.fromCharCode(getChecksum(data));
this.sendTelegram({type: system_id, content: data});
},
sendErrorTelegram: function (errcode)
{
this.sendTelegram(errtel);
},
sendTelegram: function (telegram)
{
this.send('\r\n');
},
checkTelegram: function(data, checksum)
{
this.sendTelegram(telegram_types.init_resp);
this.sendErrorTelegram(errorCodes.multi_index);
break;
}
index = data.substr(1, 4);
if (all_index.indexOf(index) >= 0)
this.sendErrorTelegram(errorCodes.index_in_use);
else
all_index.push(index);
break;
default:
break;
},
status = TelegramState.WAIT4CONTENT;
this.expectFramed('\x02', '\x03', 203);
this.setTimer(heartbeat_time_s);
index = null;
comm_handler.push(this);
all_index = new Array();
return true;
},
onDisconnect: function ()
{
},
switch (status)
{
case TelegramState.WAIT4CONTENT:
default:
throw("unknown state");
}
return true;
},
onUnexpectedData: function (inputString) {
this.expectFramed('\x02', '\x03', 203); // enable framing for the
next telegram
status = TelegramState.WAIT4CONTENT;
return true;
},
onTimer: function (inputString) {
this.sendTelegram(telegram_types.heartbeat);
this.setTimer(heartbeat_time_s);
}
};
}
Event Callback
The callback mechanism allows to register handler for trigger and input events. Handler for these events can be registered by
the registerHandler method:
Available events identifier are defined in a constant object named “Callback”. Optional arguments can be used to configure
the event, e.g. to filter the sensitivity.
A handle is returned that must be used to de-register the callback. To de-register the handler use the deregisterHandler
function:
deregisterHandler(callback_handle)
It is possible to register the callback handler within the global scope, e.g. to be used in data formatting.
Event Types
Current available events that can be registered are “onInput” and “onTrigger” events.
onInput event: It calls the callback function on input signal and button changes. The optional third argument allows to set
filter for certain inputs. The object “ConstInput” defines masks for inputs:
o Input0:
o Input1:
o Input2:
91
DataMan Application Development
o Input3:
o Input4:
o Input5:
o Input6:
o InputAll
o BnTrig
o BnTune
The input mask can be combined. The input values are sampled with an accuracy of 1 ms. The callback function for the
onInput event has one argument for the new state of the input.
onTrigger event: It executes the callback function on trigger start and trigger end events. The callback function for the
onTrigger event has two arguments: The first argument is the trigger object, the second argument the boolean state of the
trigger, true for a trigger start and false for a trigger end.
Examples
The example defines three event handler:
l onInput0 – reacting on input0 signal and the switch button
l onInput1 – reacting on input1 signal
l onTrigger – reacting on trigger events
92
DataMan Application Development
function CommHandler()
{
return {
this.peer = peerName;
this.input1 = registerHandler(Callback.onInput,
this.onInput0.bind(this),
ConstInput.Input0|ConstInput.BnTrig);
this.input2 = registerHandler(Callback.onInput,
this.onInput1.bind(this), ConstInput.Input1);
this.ontrigger = registerHandler(Callback.onTrigger,
this.onTrigger.bind(this));
return true;
},
onDisconnect: function ()
{
deregisterHandler(this.input1);
deregisterHandler(this.input2);
deregisterHandler(this.ontrigger);
},
if (state)
else
93
DataMan Application Development
},
onInput0: function (inputs) {
},
};
}
With the following event sequence: input1 on, input0 on, input0 off, input1 off, software trigger, switch on, switch off, we get
the following output on the terminal:
The following example registers a handler on Input1 events and stores the state in a global variable. The state of the input is
output by the data formatting.
94
DataMan Application Development
function onInput(inputs)
{
95
Copyright © 2023
Cognex Corporation. All Rights Reserved.