Etas dll 空指针异常

huangapple go评论66阅读模式
英文:

Etas dll NULL pointer exception

问题

以下是代码部分的中文翻译:

from can.interfaces.etas import EtasBus

if __name__ == "__main__":
    channels = EtasBus._detect_available_configs()
    for entry in channels:
        print("{channel}".format(**entry))

这是用于创建 .exe 文件的命令:

pyinstaller --noconfirm --onefile --windowed --add-binary "C:/Program Files/ETAS/BOA_V2/Bin/x64/Dll/Framework/dll-csiBind.dll;." --add-binary "C:/Program Files/ETAS/BOA_V2/Bin/x64/Dll/Framework/dll-ocdProxy.dll;." --paths "C:/Program Files/ETAS/BOA_V2/Bin/x64/Dll/Framework" "<脚本路径>run.py"

在运行二进制文件时,我遇到以下错误消息:

Traceback (most recent call last):
  File "run.py", line 5, in <module>
  File "can\interfaces\etas\__init__.py", line 312, in _detect_available_configs
  File "can\interfaces\etas\__init__.py", line 300, in _findNodes
ValueError: NULL pointer access
英文:

I do have a problem with the following code when converting it to an .exe.

from can.interfaces.etas import EtasBus


if __name__ == &quot;__main__&quot;:
    channels = EtasBus._detect_available_configs()
    for entry in channels:
        print(&quot;{channel}&quot;.format(**entry))

Running it from the console works fine.

This is the command for my .exe:

pyinstaller --noconfirm --onefile --windowed --add-binary &quot;C:/Program Files/ETAS/BOA_V2/Bin/x64/Dll/Framework/dll-csiBind.dll;.&quot; --add-binary &quot;C:/Program Files/ETAS/BOA_V2/Bin/x64/Dll/Framework/dll-ocdProxy.dll;.&quot; --paths &quot;C:/Program Files/ETAS/BOA_V2/Bin/x64/Dll/Framework&quot;  &quot;&lt;Path-to-script&gt;run.py&quot;

Running the binary I do get this error message:

Traceback (most recent call last):
  File &quot;run.py&quot;, line 5, in &lt;module&gt;
  File &quot;can\interfaces\etas\__init__.py&quot;, line 312, in _detect_available_configs
  File &quot;can\interfaces\etas\__init__.py&quot;, line 300, in _findNodes
ValueError: NULL pointer access

答案1

得分: 1

I had the same issue and found a solution now.

In (your env)\Lib\site-packages\can\interfaces\etas\boa.py, it tries to load the DLLs "dll-csiBind" and "dll-ocdProxy" with the path "C:\Program Files\ETAS\BOA_V2\Bin\x64\Dll\Framework" first. Additionally, it tries to load the DLLs with a path when the file is not found.

try:
    # try to load libraries from the system default paths
    _csi = ctypes.windll.LoadLibrary("dll-csiBind")
    _oci = ctypes.windll.LoadLibrary("dll-ocdProxy")
except FileNotFoundError:
    # try to load libraries with hardcoded paths
    if ctypes.sizeof(ctypes.c_voidp) == 4:
        # 32 bit
        path = "C:/Program Files (x86)/ETAS/BOA_V2/Bin/Win32/Dll/Framework/"
    elif ctypes.sizeof(ctypes.c_voidp) == 8:
        # 64 bit
        path = "C:/Program Files/ETAS/BOA_V2/Bin/x64/Dll/Framework/"
    _csi = ctypes.windll.LoadLibrary(path + "dll-csiBind")
    _oci = ctypes.windll.LoadLibrary(path + "dll-ocdProxy")

When I build and run with the original boa.py, it loads the DLLs without a path and raises a NULL pointer access error. In this case, CSI_CreateProtocolTree is not working.

You can remove the "try" block and let it load the DLLs with the hardcoded path in boa.py.

if ctypes.sizeof(ctypes.c_voidp) == 4:
    # 32 bit
    path = "C:/Program Files (x86)/ETAS/BOA_V2/Bin/Win32/Dll/Framework/"
elif ctypes.sizeof(ctypes.c_voidp) == 8:
    # 64 bit
    path = "C:/Program Files/ETAS/BOA_V2/Bin/x64/Dll/Framework/"
_csi = ctypes.windll.LoadLibrary(path + "dll-csiBind")
_oci = ctypes.windll.LoadLibrary(path + "dll-ocdProxy")

In my case, it works with pyinstaller and pyside6.

英文:

I had same issue and find something now.

In (your env)\Lib\site-packages\can\interfaces\etas\boa.py
It try load dll("dll-csiBind", "dll-ocdProxy") with path("C:\Program Files\ETAS\BOA_V2\Bin\x64\Dll\Framework") first,
and additionally try load dll with path when file not be found.

try:
    # try to load libraries from the system default paths
    _csi = ctypes.windll.LoadLibrary(&quot;dll-csiBind&quot;)
    _oci = ctypes.windll.LoadLibrary(&quot;dll-ocdProxy&quot;)
except FileNotFoundError:
    # try to load libraries with hardcoded paths
    if ctypes.sizeof(ctypes.c_voidp) == 4:
        # 32 bit
        path = &quot;C:/Program Files (x86)/ETAS/BOA_V2/Bin/Win32/Dll/Framework/&quot;
    elif ctypes.sizeof(ctypes.c_voidp) == 8:
        # 64 bit
        path = &quot;C:/Program Files/ETAS/BOA_V2/Bin/x64/Dll/Framework/&quot;
    _csi = ctypes.windll.LoadLibrary(path + &quot;dll-csiBind&quot;)
    _oci = ctypes.windll.LoadLibrary(path + &quot;dll-ocdProxy&quot;)

When I build and run with original boa.py, it load dll without path and raise NULL pointer access error.
In this case, CSI_CreateProtocolTree is not working.

You can remove "try" and let it load dll with hardcoded path in boa.py

if ctypes.sizeof(ctypes.c_voidp) == 4:
    # 32 bit
    path = &quot;C:/Program Files (x86)/ETAS/BOA_V2/Bin/Win32/Dll/Framework/&quot;
elif ctypes.sizeof(ctypes.c_voidp) == 8:
    # 64 bit
    path = &quot;C:/Program Files/ETAS/BOA_V2/Bin/x64/Dll/Framework/&quot;
_csi = ctypes.windll.LoadLibrary(path + &quot;dll-csiBind&quot;)
_oci = ctypes.windll.LoadLibrary(path + &quot;dll-ocdProxy&quot;)

In my case it works with pyinstaller and pyside6.

huangapple
  • 本文由 发表于 2023年3月8日 15:22:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75670272.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定