Skip to Main Content
Centro Assistenza Cognex
Logo

How To Send Native Commands To In-Sight Cameras Through Modbus TCP Protocol

This article explains how the String Command blocks of the In-Sight camera's Modbus TCP interface can be used to execute Native Commands.

23/03/2025

Question

How can I send Native Commands to In-Sight cameras through Modbus TCP protocol?

Answer

The String Command related tags can be used for executing Native Commands on In-Sight cameras:

Placeholder

Modbus addresses of the String Command related tags:

Placeholder
Tag NameAddressAlternative Holding Register Address
Initiate String CommandCoil 17Holding Register 0 / Bit 17
String Command AckDiscrete Input 17Holding Register 100 / Bit 17
String Command ErrorDiscrete Input 18Holding Register 100 / Bit 18
String Command LengthHolding Register 1000Holding Register 1000
String CommandHolding Register 1001...1999Holding Register 1001...1999
Result CodeInput Register 1000Holding Register 6000
String Command Result LengthInput Register 1001Holding Register 6001
String Command ResultInput Register 1002...1999Holding Register 6002...6999

Notes:

  • Cognex cameras are using zero-based offsets for addressing.
  • Cognex cameras do not support Function Code 0x06 (Write Single Holding Register). Function Code 0x10 (Write Multiple Holding Registers) must be used for writing into Holding Registers.

The further example will use the GI (Get Info) Native Command. If this command is sent over Native Mode Protocol, then the camera's response looks like the below one:

Placeholder

Steps to send Native Command over Modbus TCP protocol:

  1. Write the Native Command into the String Command and its length into the String Command Length. Notes:

    • String Command Length is the number of characters in the Native Command,
    • there is no need to use CRLF terminating characters,
    • since the Modbus registers are 16-bit registers, each of them can hold up to 2 characters of the Native Command,
    • the first character of each character-pairs of the Native Command should be placed in the lower byte of the Holding Register, and the second character should be placed in the higher byte of the Holding Register.
    Placeholder

    This example uses the free QModMaster application as the Modbus master. Since this application cannot display strings, an ASCII code lookup table is needed to convert characters into hexadecimal ASCII codes and vice versa.

    Address 1000: 0002, this is the String Command Length, number of characters of the Native Command, which is 2 in this example because GI contains 2 characters.
    Address 1001: 4947, this is the String Command, where 47 is the hexadecimal ASCII code of character "G", and 49 is the hexadecimal ASCII code of character "I".

  2. Set the Initiate String Command to 1.

    Placeholder
  3. Wait for the String Command Ack bit to become 1.

    Placeholder
  4. After this step, if the command was successfully interpreted, the String Command Error bit should be 0.

    Placeholder
  5. Clear the Initiate String Command.

    Placeholder
  6. Read the Result Code, String Command Result Length and String Command Result.

    Placeholder

Address 1000: 0001, this is the Result Code, 1 means successful execution.
Address 1001: 00B2, equals to decimal 178, this is the String Command Result Length that means the number of characters in the String Command Result.
Address 1002...: 6553 6972 6C61 4E20 6D75 6562 3A72 ..., these are the characters of the String Command Result, after checking these hexadecimal codes in an ASCII lookup table, it starts as string "Serial Number:".
Note that the characters are swapped within each character-pairs because due to the lower-byte upper-byte order.

Risorse correlate