genicam / harvesters

Image Acquisition Library for GenICam-based Machine Vision System
Apache License 2.0
513 stars 88 forks source link

Python & Critical Link GenTL (XML parser error) #368

Open vmazlin opened 2 years ago

vmazlin commented 2 years ago

Describe the Issue Parsing XML file throws a syntax error in the same line (1720) as in [https://github.com/genicam/harvesters/issues/207]. This error was supposed to be fixed in harvester version 1.3.2 ...

error

To Reproduce We followed the steps to control Critical Link GenTL camera with Python (https://support.criticallink.com/redmine/projects/gentl_apps/wiki/Using_Python_With_Critical_Link_GenTL_Producer) and (https://support.criticallink.com/redmine/boards/21/topics/6147?r=6148).

Device and GenTL producer were found without a problem. Environment variable was created for XML camera file.

Configuration

Reproducibility This phenomenon can be stably reproduced:

Thank you in advance for any ideas

jcormier commented 2 years ago

This appears to be an issue between our (Critical Link) camera and the genicam 1.2.0 release. The latest genapi release must have changed something in the producer XML requirements.

Sticking with genicam==1.1.0 until we figure this out should help.

jcormier commented 2 years ago

I'm having a hard time tracking this down as the exception is being thrown from genapi xmlparser.cpp _genapi.NodeMap_load_xml_from_file

Though I can't tell what the syntax error is. It passes XML validation.

Here is a picture of the debugger right before the exception is thrown: harvesters_unicode_error

And the error

2022-09-26 18:35:14,851 - harvesters - DEBUG - fetched url: local:///criticallink_systemgentl.xml;0;3075
2022-09-26 18:35:14,855 - harvesters - DEBUG - created: C:\Users\jcormier\AppData\Local\Temp\20220926183514_btng_obq\criticallink_systemgentl.xml
2022-09-26 18:35:25,277 - 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\20220926183514_btng_obq\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)
2022-09-26 18:35:25,284 - harvesters - DEBUG - deleted: C:\Users\jcormier\AppData\Local\Temp\20220926183514_btng_obq\criticallink_systemgentl.xml
Traceback (most recent call last):
  File "C:\Users\jcormier\.conda\envs\gentl_38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\jcormier\.conda\envs\gentl_38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "c:\Users\jcormier\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
    cli.main()
  File "c:\Users\jcormier\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\Users\jcormier\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\Users\jcormier\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "c:\Users\jcormier\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "c:\Users\jcormier\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "c:\Users\jcormier\Documents\GenTL\python_scripts\snap.py", line 48, in <module>
    h.update()
  File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 3264, in update
    self._open_systems()
  File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 3159, in _open_systems
    self._systems.append(System(module=raw_system, parent=producer))
  File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 420, in __init__
    super().__init__(module=module, parent=parent, port=module.port)
  File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 230, in __init__
    self._node_map = self._create_node_map(
  File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\harvesters\core.py", line 276, in _create_node_map
    node_map.connect(concrete_port, port.name)
  File "C:\Users\jcormier\.conda\envs\gentl_38\lib\site-packages\genicam\genapi.py", line 1947, in connect
    return self._connect(*args)
  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)

Attached the XML. Note I zipped it to appease the github file restrictions but it is sent uncompressed from the camera. criticallink_systemgentl.zip

jcormier commented 2 years ago

Just to be thorough

Configuration

OS: windows 10
Harvester: 1.4.0
Genicam: 1.2.0
Python (Anaconda): 3.8.12
GenTL Producer: Critical Link
GenTL Viewer: 2.7.0
Camera: MityCAM-35MMFHDXS
kazunarikudo commented 1 year ago

@jcormier Hi, I have just confirmed that the provided XML can reproduce the phenomenon on my side. As far as I check your XML file, the RegisterDescription tag has xmlns:schemaLocation="..." but it should be xsi:schemaLocation="...". I hope you can have a chance to check the difference on your side as well. Thanks, Kazunari.

@vmazlin Please wait for a while until the issue is resolved. Thanks.

jcormier commented 1 year ago

it should be xsi:schemaLocation="..."

Thanks for checking it out. I already made that change but its possible I didn't update my gentl.dll when testing. hmm. Is there a easier way to test the xml without having to connect to a camera?

jcormier commented 1 year ago

With the release of GenTLViewer 2.7.2, the latest harvesters 1.4.0 and genicam 1.2.0 python packages now work. I've updated the wiki https://support.criticallink.com/redmine/projects/gentl_apps/wiki/Using_Python_With_Critical_Link_GenTL_Producer

Relevant changes: