Skip to main content

📷 🐍 CognexNativePy 🐍 📷

CognexNativePy is a Python wrapper for the Cognex native mode commands. It provides a simple and intuitive wrapper to interact with Cognex cameras. It's based on the Cognex native mode commands, which can be found in Cognex Documentation Website.

Table of Contents 📜

Installation 🚀

Using pip 🐍

To install the library using pip, run the following command:

pip install CognexNativePy

Manual Installation 📦

To use this library in your project, first download the repository and place the CognexNativePy folder in your project's directory. You can then import the NativeInterface class from this library to interact with the Cognex camera. See Usage section for an example.

Usage 📚

The NativeInterface class provides four categories of commands: exectution_and_online, file_and_job, image, and settings_and_cell_value. Each category corresponds to a set of related commands as documented in the Cognex Documentation Website.

Each command category is an attribute of the NativeInterface class, allowing you to easily access and execute the commands you need for your specific use case.

Example of how to use the wrapper:

from CognexNativePy import NativeInterface


def main():
    try:
        # Create a socket connection to the Cognex In-Sight vision system and log in
        native_interface = NativeInterface('192.168.56.1', 'admin', '')
        execution_and_online = native_interface.execution_and_online
        file_and_job = native_interface.file_and_job
        image = native_interface.image
        settings_and_cells_values = native_interface.settings_and_cells_values

        # Load the job if it is not already loaded
        job_name = "1myJob.job"
        if file_and_job.get_file() != job_name:
            if execution_and_online.get_online() == 1:
                execution_and_online.set_online(0)
            file_and_job.load_file(job_name)

        # Get the last image from the camera and save it as a BMP file
        with open('image.bmp', 'wb') as f:
            f.write(image.read_image()["data"])

        # Get the value of the cell B010 (spreadsheet view)
        print(settings_and_cells_values.get_value("B", 10))
        # Set the value of the cell D019 (spreadsheet view) to 53
        settings_and_cells_values.set_integer_value("D", 19, 53)
        # Set the value of the symbolic tag "Pattern_1.Horizontal_Offset" to 69.3 (EasyBuilder view)
        settings_and_cells_values.set_float_value("Pattern_1.Horizontal_Offset", 69.3)
        # Get the information of the settings and cells values
        print(settings_and_cells_values.get_info())

        # Close the socket connection
        native_interface.close()

    except Exception as e:
        print(f"Error: {e}")


if __name__ == '__main__':
    main()

Contributing 🤝

If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.

License 📝

License: MIT

Known Issues 🐞

Cognex Models : In-Sight 3805 and In-Sight 2800 seem to have issues with the current implementation. The In-Sight Explorer software is unable to emulate these models, so it is difficult to debug the issues. If you have access to these models, please test the library and suggest fixes for the issues.

Release files for CognexNativePy 1.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for CognexNativePy 1.0.12
File Size Uploaded
cognexnativepy-1.0.12.tar.gz 19.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for CognexNativePy 1.0.12
File Interpreter ABI Platform
cognexnativepy-1.0.12-py3-none-any.whl Python 3 none any Details

Total release size: 39.9 kB

Release files / cognexnativepy-1.0.12.tar.gz

Download URL cognexnativepy-1.0.12.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2ba2fac706ea09a067fcd4d0b15a27c80da837daa162b35c0662fac572253479
BLAKE2b-256 checksum
How to use checksums
1e2a0a9670b332a0fe38ca5a80a9b78b1a270f284b258aa60e4bd463f332d83f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / cognexnativepy-1.0.12-py3-none-any.whl

Download URL cognexnativepy-1.0.12-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc8b92509addd66e69ab5601479ff2391f96b64836229afd8d4122bf4a126072
BLAKE2b-256 checksum
How to use checksums
85a44f61cc8144f05af4cbc52cec4d2fd317dda5cf0cbef3a897227c6b8cd322
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

1.0.12 This release

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.5

2 release files

1.0.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page