Skip to main content

A Python library for communicating with Cognex In-Sight vision systems. Wrapper of the native commands

Project description

📷 🐍 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

CognexNativePy-1.0.5.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

CognexNativePy-1.0.5-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file CognexNativePy-1.0.5.tar.gz.

File metadata

  • Download URL: CognexNativePy-1.0.5.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for CognexNativePy-1.0.5.tar.gz
Algorithm Hash digest
SHA256 6c1bf79c1cc26ec9a6236b1130b1c61b12434f750c19c85a6fed895c30468b02
MD5 73221340e0a40177955ed08190045432
BLAKE2b-256 5d12ebb5c91aaf3f96f34eb7e2242369c1d80effe6c56937df83cf6eff421708

See more details on using hashes here.

File details

Details for the file CognexNativePy-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for CognexNativePy-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 14489dee7146f5713b8e421b799eb3fa72f9a2fba46ccec75061c29e54c9c868
MD5 b0903bdd958c1ba8436af83327f6cc70
BLAKE2b-256 a09b8ea17dee905a1b1cd0db16d3dd28171ee81c786852d367d11ac04f0f0c3a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page