Using Python With Critical Link GenTL Producer¶
The GenTLViewer Package has basic support for the Harvester python library
The docs for harvesters as well as some additional examples can be found: https://harvesters.readthedocs.io/en/latest/TUTORIAL.html
Critical Link does not officially support the use of python with our GenTL producer implementation, but if you have questions please feel free to post them on the forum. We will try to help when time permits.
Here is an example of capturing and plotting a monochrome image from the CMV50K EVK camera from a base windows install of miniconda
Note: Harvesters 1.4.0 requires GenTLViewer 2.7.2+
Note: Harvesters 1.4.2 doesn't currently work, see Known issues below
64-bit Python 3.10:
(base) C:\Users\jcormier\Documents>conda create -n gentl_310 matplotlib python=3.10 (base) C:\Users\jcormier\Documents>conda activate gentl_310 (gentl_38) C:\Users\jcormier\Documents>pip install numpy harvesters==1.4.0 genicam==1.2.0 (gentl_38) C:\Users\jcormier\Documents>pip show harvesters genicam Name: harvesters Version: 1.4.0 ... Name: genicam Version: 1.2.0 ... (gentl_38) C:\Users\jcormier\Documents>python -V Python 3.10.11 (gentl_38) C:\Users\jcormier\Documents>set PATH=c:\Program Files\Critical Link LLC\GenTL Viewer\bin;%PATH% (gentl_38) C:\Users\jcormier\Documents>python snap.py
The snap.py script is included as a downloadable file on this page.
Critical Link has not performed extensive testing with these bindings. Your mileage may vary.
Notes / Known Issues:¶
- You need to limit the number of buffers used by the image_acquirer to 5 for large U3V images.
- You must have the GenTL Viewer binary directory in your path. Our GenTL producer uses a couple of additional DLLs in that directory
- The genicam python package only supports up to python 3.10. https://github.com/genicam/harvesters/issues/125 https://pypi.org/project/genicam/#files
- "PermissionError: [Errno 13] Permission denied: 'c:///criticallink_systemgentl.xml'" https://github.com/genicam/harvesters/issues/126
- Failed to load CTI file
Make sure you've added the PATH to the GenTL Viewer bin folderTraceback (most recent call last): File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 3142, in _open_gentl_producers raw_producer.open(file_path) File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\genicam\gentl.py", line 2326, in open return _gentl.GenTLProducer_open(self, path_name) _gentl.LoadLibraryException: GenTL exception: Failed to load CTI file; The specified module could not be found. (ID: -10001)
- Using SimCamera results in error "OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '/C:/Users/jcormier/Documents/GenTL/GenTL/sim_camera.xml'"
> copy "c:\Program Files\Critical Link LLC\GenTL Viewer\bin\sim_camera.xml" . > set SIMCAM_XML_FILE=sim_camera.xml > python snap.py
- gentl.NotImplementedException "_gentl.Buffer_get_tl_type"
BUFFER_INFO_TLTYPE support was added in GenTL Viewer release 2.7.0File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\genicam\gentl.py", line 4358, in _get_tl_type return _gentl.Buffer__get_tl_type(self) _gentl.NotImplementedException: GenTL exception: Requested operation not implemented. (Message from the source: Function not implemented) (ID: -1003)
https://github.com/genicam/harvesters/issues/357 - GenTL exception: Requested operation not implemented. "_gentl.DeviceInfo__get_user_defined_name"
This can be treated as a warning. Our producer doesn't implement user defined names and harvesters will just skip over and keep going.
GenTLViewer 2.7.1 addresses this by returning an empty string instead of NOT_IMPLEMENTED2022-09-26 13:45:32,266 - harvesters - DEBUG - GenTL exception: Requested operation not implemented. (Message from the source: Function not implemented) (ID: -1003) Traceback (most recent call last): File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 446, in _build_dict value = getattr(self._module, p, None) File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\genicam\gentl.py", line 3569, in _get_user_defined_name return _gentl.DeviceInfo__get_user_defined_name(self) _gentl.NotImplementedException: GenTL exception: Requested operation not implemented. (Message from the source: Function not implemented) (ID: -1003)
- _genapi.RuntimeException: Invalid layout of buffer attached to chunk parser
https://github.com/genicam/harvesters/pull/369
GenTLViewer 2.7.2 was updated to return false for BUFFER_INFO_CONTAINS_CHUNKDATATraceback (most recent call last): File "snap.py", line 77, in <module> with fetch(timeout=4) as buffer: File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 2387, in fetch buffer = self._finalize_fetching_process(raw_buffer, is_raw) File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 2319, in _finalize_fetching_process self._update_chunk_data(buffer=raw_buffer) File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 2202, in _update_chunk_data self._chunk_adapter.attach_buffer(buffer.raw_buffer[:size]) File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\genicam\genapi.py", line 2963, in attach_buffer self._adapter.attach_buffer(self._buffer, statistics) File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\genicam\genapi.py", line 3130, in attach_buffer return _genapi._ChunkAdapterU3V_attach_buffer(self, pBuffer, pAttachStatistics) _genapi.RuntimeException: Invalid layout of buffer attached to chunk parser! : RuntimeException thrown (file 'ChunkAdapterU3V.cpp', line 95)
- Error while parsing XML stream... criticallink_systemgentl.xml
This is resolved with the release of GenTLViewer 2.7.1https://github.com/genicam/harvesters/issues/3682022-09-26 14:12:34,050 - harvesters - WARNING - Error while parsing XML stream at line 2 and column 0 : 'syntax error' : RuntimeException thrown (file 'XmlParser.cpp', line 1720) Traceback (most recent call last): File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 258, in _create_node_map node_map.load_xml_from_zip_file(file_path) File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\genicam\genapi.py", line 1826, in load_xml_from_zip_file return _genapi.NodeMap_load_xml_from_zip_file(self, ZipFileName) _genapi.RuntimeException: File open failed in ParseXmlFile. Filename = 'C:\Users\jcormier\AppData\Local\Temp\20220926141234_ox02n2hh\criticallink_systemgentl.xml' : RuntimeException thrown (file 'XmlParser.cpp', line 131) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 261, in _create_node_map node_map.load_xml_from_file(file_path) File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\genicam\genapi.py", line 1820, in load_xml_from_file return _genapi.NodeMap_load_xml_from_file(self, FileName) _genapi.RuntimeException: Error while parsing XML stream at line 2 and column 0 : 'syntax error' : RuntimeException thrown (file 'XmlParser.cpp', line 1720) Traceback (most recent call last): File "snap.py", line 40, in <module> h.update() ... File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\genicam\genapi.py", line 1857, in _connect return _genapi.NodeMap__connect(self, *args) _genapi.AccessException: Feature not present (reference not valid) : AccessException thrown (file 'NodeMapRef.h', line 497)
- harvesters 1.4.2: GenTL exception: Buffer used is too small for operation
https://github.com/genicam/harvesters/issues/409Traceback (most recent call last): File "snap.py", line 81, in <module> ia = h.create(index) File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 3082, in create return self._create_acquirer(device_proxy=device_proxy, config=config) File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 3112, in _create_acquirer ia = ImageAcquirer(device_proxy=device_proxy_, config=config, manager(module.register_event(event_type)) File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 228, in m return getattr(self._source_object, attribute)(*args) File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\genicam\gentl.py", line 2303, in register_event return _gentl.System_register_event(self, event_id) _gentl.BufferTooSmallException: GenTL exception: Buffer used is too small for operation. (Message from the source: Buffer was too small) (ID: -1016)
Go to top