mccdaq / mcculw

MCC Universal Library Python API for Windows
MIT License
78 stars 30 forks source link

Module cbw64.dll not found #19

Closed FurkanToprak closed 4 years ago

FurkanToprak commented 4 years ago

I've installed the test code:

from mcculw import ul
from mcculw.enums import ULRange
from mcculw.ul import ULError

board_num = 0
channel = 0
ai_range = ULRange.BIP5VOLTS

try:
    # Get a value from the device
    value = ul.a_in(board_num, channel, ai_range)
    # Convert the raw value to engineering units
    eng_units_value = ul.to_eng_units(board_num, ai_range, value)

    # Display the raw value
    print("Raw Value: " + str(value))
    # Display the engineering value
    print("Engineering Value: " + '{:.3f}'.format(eng_units_value))
except ULError as e:
    # Display the error
    print("A UL error occurred. Code: " + str(e.errorcode)
          + " Message: " + e.message)

From the documentation after installing the mcculw library. I have gotten this error in two different Windows computers. What am I missing?

Traceback (most recent call last):
  File "C:/Users/Toprak/PycharmProjects/Furgostat/index.py", line 1, in <module>
    from mcculw import ul
  File "C:\Users\Toprak\PycharmProjects\Furgostat\venv\lib\site-packages\mcculw\ul.py", line 35, in <module>
    _cbw = WinDLL('cbw64.dll')
  File "C:\Users\Toprak\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'cbw64.dll'. Try using the full path with constructor syntax.
FaSoa commented 4 years ago

Hello FurkanToprak.

What are you using for your development environment? Did you install the latest version of MCC's InstaCal, on your Windows 10 system, and then run InstaCal to detect your MCC device? Readme: https://github.com/mccdaq/mcculw/blob/master/README.rst InstaCal: https://www.mccdaq.com/daq-software/instacal.aspx

Also, the online Universal Library Help has useful information for Python users. https://www.mccdaq.com/PDFs/Manuals/Mcculw_WebHelp/ULStart.htm

Regards.

LudovicRicard commented 4 years ago

Hi Furkan, I had the same issue. It is because the path variable does not link the location of the file cbw64.dll. I modified the ul.py file to include the full path to this file, it worked for me. I had a few more issues like that to solve before everything was working fine. Cheers,

FurkanToprak commented 4 years ago

Credit to @LudovicRicard for the very helpful tip. Include the full file path before cbw32.dll or cbw64.dll Specifically, here is the required code, found under ul.py:

# Load the correct library based on the Python architecture in use
if struct.calcsize("P") == 4:
    _cbw = WinDLL('C:\\Program Files (x86)\\Measurement Computing\\DAQ\\cbw32.dll')
else:
    _cbw = WinDLL('C:\\Program Files (x86)\\Measurement Computing\\DAQ\\cbw64.dll')