Skip to content

it can not work in macos, can not load dll #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
slightc opened this issue Apr 6, 2025 · 1 comment
Open

it can not work in macos, can not load dll #3

slightc opened this issue Apr 6, 2025 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@slightc
Copy link

slightc commented Apr 6, 2025

error in below

File "/Users/chenh/Library/Python/3.12/lib/python/site-packages/i2cpy/driver/ch341/__init__.py", line 13, in <module>
    from .dll import ch341dll
  File "/Users/chenh/Library/Python/3.12/lib/python/site-packages/i2cpy/driver/ch341/dll.py", line 47, in <module>
    ch341dll = load()
               ^^^^^^
  File "/Users/chenh/Library/Python/3.12/lib/python/site-packages/i2cpy/driver/ch341/dll.py", line 22, in load
    dll = cdll.LoadLibrary(dll_name)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ctypes/__init__.py", line 460, in LoadLibrary
    return self._dlltype(name)
           ^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ctypes/__init__.py", line 379, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: dlopen(libch347.so, 0x0006): tried: 'libch347.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibch347.so' (no such file), '/usr/lib/libch347.so' (no such file, not in dyld cache), 'libch347.so' (no such file), '/usr/lib/libch347.so' (no such file, not in dyld cache)
@iynehz
Copy link
Owner

iynehz commented Apr 7, 2025

Short answer is i2cpy does not really support macOS yet.

Actually my present code is not just missing that libch347.so file, it also lacks the logic that initializes ch341 and finding device handlers on macos. And it looks to me that it's hard to get it work for I2C on macOS. I should fix my doc to explicitly mention that macOS is not supported.

And here let me note what parts are possible to work, and what are not, as I am trying it now:

  • For I2C/SPI QinHeng has a driver zipball downloadable here https://www.wch-ic.com/downloads/CH341PAR_MAC_ZIP.html It has not the libch347.so which exists in their Linux zipball. On macOS it has a libch347.a file. It's however possible to extract obj files from this libch347.a file and build a libch347.so file.
  • On this basis I can update my Python code, according to their pdf doc which is included in above mentioned zip ball, for how to get it work on macOC. Basically I can firstly call CH34xInit() to initialize the library, and then use CH34xGetDeviceList() to get all devices. And once the CH341 device is detected, from output of CH34xGetDeviceList() I can get the device handle. The rest should ideally be similar to what we do on Linux. However, CH34xStreamI2C() seems to be buggy on macOS in that when I do several write/read operations, it could be good at first couple write/reads but then fail timeout at later CH34xStreamI2C operations.

@iynehz iynehz added the help wanted Extra attention is needed label Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants