mabuchilab / Instrumental

Python-based instrumentation library from the Mabuchi Lab.
http://instrumental-lib.readthedocs.org/
GNU General Public License v3.0
117 stars 77 forks source link

Absoulte beginner - some basic help with Instrumental #138

Closed jlozanol closed 3 years ago

jlozanol commented 3 years ago

Hi Team,

Sorry if this is not the right forum to put this question. I'm brand new to general programming and I'm trying to understand how the Instrumental Library works. My short term goal is to create a python program to communicate a Thorlabs Spectrometer CCS175 and I just installed this library.

I just tried to run the list of instruments to see if the spectrometer appeared and I just got the following:

>>> from instrumental import instrument, list_instruments
>>> paramsets = list_instruments()
Traceback (most recent call last):
  File "C:\Users\s3853339\Miniconda3\lib\site-packages\instrumental\drivers\__init__.py", line 677, in list_instruments
    inst_list.extend(list_visa_instruments())
  File "C:\Users\s3853339\Miniconda3\lib\site-packages\instrumental\drivers\__init__.py", line 621, in list_visa_instruments
    return list(gen_visa_instruments())
  File "C:\Users\s3853339\Miniconda3\lib\site-packages\instrumental\drivers\__init__.py", line 567, in gen_visa_instruments
    rm = visa.ResourceManager()
AttributeError: module 'visa' has no attribute 'ResourceManager'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\s3853339\Miniconda3\lib\site-packages\instrumental\drivers\__init__.py", line 678, in list_instruments
    except visa.VisaIOError:
AttributeError: module 'visa' has no attribute 'VisaIOError'

I'm not sure what I'm doing wrong of if I didn't install any other library. I can see visa and pyvisa are already installed in my base env, so I don't know where to go from here. I'm running Python 3.9.1

As I said, I'm brand new and there are a lot of things I really don't understand. Do you know where I could get some information or some examples on how to use the Instrumental library? (my google searches haven't been successfull on finding something useful so far).

Again, so sorry if this is not the right place to ask this question!

Cheers,

jondoesntgit commented 3 years ago

There are several packages that are named "visa". It's possible that you've installed the wrong one. This is the one you're after: https://pyvisa.readthedocs.io/en/latest/introduction/getting.html

jlozanol commented 3 years ago

There are several packages that are named "visa". It's possible that you've installed the wrong one. This is the one you're after: https://pyvisa.readthedocs.io/en/latest/introduction/getting.html

Thx for the answer @jondoesntgit ! I had already installed pyvisa as I thought it could be the problem. I can see it's in my base env (as well as visa):

(base) PS C:\> conda list
# packages in environment at C:\Users\s3853339\Miniconda3:
#
# Name                    Version                   Build  Channel
...
pyvisa                    1.11.3                   pypi_0    pypi
...
visa                      1.0.0                    pypi_0    pypi

I tried the basic command that the pyvisa doc indicates:

>>> import pyvisa
>>> rm = pyvisa.ResourceManager()
>>> rm.list_resources()
()

I imagine there's something wrong with pyvisa that cannot see any devices connected to the computer? BTW, I have also connected a NI myDAQ device that I have successfully made it work via nidaqmx library. It seems an issue with pyvisa, maybe?

Thanks heaps!

Jorge

jondoesntgit commented 3 years ago

Have you installed NI Visa on your machine? PyVISA is a wrapper around some lower-level libraries, and relies on those lower-level libraries being installed. It's been a while since Iast installed, but I hazily remember that there may have been a configuration step in connecting PyVISA with NI VISA (or some other alternative if you're on Linux or something).

jlozanol commented 3 years ago

Have you installed NI Visa on your machine? PyVISA is a wrapper around some lower-level libraries, and relies on those lower-level libraries being installed. It's been a while since Iast installed, but I hazily remember that there may have been a configuration step in connecting PyVISA with NI VISA (or some other alternative if you're on Linux or something).

Hi @jondoesntgit!

Sorry for the long time replying, I've been so busy with other stuff.

I was able to figure out what was the issue with the visa that was on my env.

(instruments) PS C:\> python
Python 3.9.4 (default, Apr  9 2021, 11:43:21) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from instrumental import instrument, list_instruments
>>> paramsets = list_instruments()
C:\Users\s3853339\Miniconda3\envs\instruments\lib\site-packages\visa.py:13: FutureWarning: The visa module provided by PyVISA is being deprecated. You can replace `import visa` by `import pyvisa as visa` to achieve the same effect.

The reason for the deprecation is the possible conflict with the visa package provided by the https://github.com/visa-sdk/visa-python which can result in hard to debug situations.
  warnings.warn(
C:\Users\s3853339\Miniconda3\envs\instruments\lib\site-packages\instrumental\drivers\motion\ecc100.py:24: UserWarning: Driver 'instrumental.drivers.motion.ecc100' is out of date and incompatible with the current Instrumental core. Pull requests fixing this are welcome.
  warnings.warn(
>>> paramsets
[] # seems instrumental is not able to pick the devices that are connected...

So I checked how my visa info looked:

(instruments) PS C:\> python -m visa info
C:\Users\s3853339\Miniconda3\envs\instruments\lib\site-packages\visa.py:13: FutureWarning: The visa module provided by PyVISA is being deprecated. You can replace `import visa` by `import pyvisa as visa` to achieve the same effect.

The reason for the deprecation is the possible conflict with the visa package provided by the https://github.com/visa-sdk/visa-python which can result in hard to debug situations.
  warnings.warn(
Machine Details:
   Platform ID:    Windows-10-10.0.18362-SP0
   Processor:      Intel64 Family 6 Model 142 Stepping 12, GenuineIntel

Python:
   Implementation: CPython
   Executable:     C:\Users\s3853339\Miniconda3\envs\instruments\python.exe
   Version:        3.9.4
   Compiler:       MSC v.1916 64 bit (AMD64)
   Bits:           64bit                                                                                                                                                       Build:          Apr  9 2021 11:43:21 (#default)                                                                                                                             Unicode:        UCS4                                                                                                                                                                                                                                                                                                                                 PyVISA Version: 1.11.3

Backends:
   ivi:
      Version: 1.11.3 (bundled with PyVISA)
      #1: C:\WINDOWS\system32\visa32.dll:
         found by: auto
         bitness: 64
         Vendor: National Instruments
         Impl. Version: National Instruments
         Spec. Version: National Instruments
      #2: C:\WINDOWS\system32\visa64.dll:
         found by: auto
         bitness: 64
         Vendor: National Instruments
         Impl. Version: National Instruments
         Spec. Version: National Instruments
   py:
      Version: 0.5.2
      ASRL INSTR:
         Please install PySerial (>=3.0) to use this resource type.
         No module named 'serial'
      USB INSTR: Available via PyUSB (1.1.1). Backend: libusb0
      USB RAW: Available via PyUSB (1.1.1). Backend: libusb0
      TCPIP INSTR: Available
      TCPIP SOCKET: Available
      GPIB INSTR:
         Please install linux-gpib (Linux) or gpib-ctypes (Windows, Linux) to use this resource type. Note that installing gpib-ctypes will give you access to a broader range of funcionality.
         No module named 'gpib'

So it looks PyUSB is configured correctly. I tried to check what's going on with PyUSB:

>>> import usb.core
>>> dev = usb.core.find()
>>> print(dev)
DEVICE ID 1313:8087 on Bus 000 Address 001 =================
 bLength                :   0x12 (18 bytes)
 bDescriptorType        :    0x1 Device
 bcdUSB                 :  0x200 USB 2.0
 bDeviceClass           :    0x0 Specified at interface
 bDeviceSubClass        :    0x0
 bDeviceProtocol        :    0x0
 bMaxPacketSize0        :   0x40 (64 bytes)
 idVendor               : 0x1313
 idProduct              : 0x8087
 bcdDevice              :    0x0 Device 0.0
 iManufacturer          :    0x1 Thorlabs
 iProduct               :    0x2 CCS175
 iSerialNumber          :    0x3 M00601006
 bNumConfigurations     :    0x1
  CONFIGURATION 1: 500 mA ==================================
   bLength              :    0x9 (9 bytes)
   bDescriptorType      :    0x2 Configuration
   wTotalLength         :   0x2e (46 bytes)
   bNumInterfaces       :    0x1
   bConfigurationValue  :    0x1
   iConfiguration       :    0x0
   bmAttributes         :   0x80 Bus Powered
   bMaxPower            :   0xfa (500 mA)
    INTERFACE 0: Vendor Specific ===========================
     bLength            :    0x9 (9 bytes)
     bDescriptorType    :    0x4 Interface
     bInterfaceNumber   :    0x0
     bAlternateSetting  :    0x0
     bNumEndpoints      :    0x4
     bInterfaceClass    :   0xff Vendor Specific
     bInterfaceSubClass :    0x0
     bInterfaceProtocol :    0x0
     iInterface         :    0x0
      ENDPOINT 0x2: Bulk OUT ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x2 OUT
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
      ENDPOINT 0x4: Bulk OUT ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :    0x4 OUT
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
      ENDPOINT 0x86: Bulk IN ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x86 IN
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0
      ENDPOINT 0x88: Bulk IN ===============================
       bLength          :    0x7 (7 bytes)
       bDescriptorType  :    0x5 Endpoint
       bEndpointAddress :   0x88 IN
       bmAttributes     :    0x2 Bulk
       wMaxPacketSize   :  0x200 (512 bytes)
       bInterval        :    0x0

And it's able to see the Spectrometer!

rm = visa.ResourceManager()
rm.list_resources('?*')
('USB0::0x1313::0x8087::M00601006::RAW',)
test=rm.open_resource('USB0::0x1313::0x8087::M00601006::RAW')
print(test)
USBRaw at USB0::0x1313::0x8087::M00601006::0::RAW

I see then that by default the resource manager only list INSTR resources. So I used the rm.list_resources('?*') to see this device.

However, as the resource manager only list INSTR, how can I pass this information to paramsets = list_instruments() ?

Thanks heaps!

Cheers,

jlozanol commented 3 years ago

Hi @jondoesntgit,

I just found the following information on #120.

After checking I discovered I might face the same issue as indicated there:

>>> from instrumental.log import log_to_screen
>>> log_to_screen()
<RootLogger root (INFO)>
>>> list_instruments()
[    INFO]2021-04-29 10:41:00,486 nicelib.util: Looking for ('TLCCS.h',) in ('{PROGRAMFILES}\\IVI Foundation\\VISA\\Win64\\Include', '{PROGRAMFILES(X86)}\\IVI Foundation\\VISA\\Win64\\Include')
[    INFO]2021-04-29 10:41:00,488 nicelib.build: Found ['C:\\Program Files\\IVI Foundation\\VISA\\Win64\\Include\\TLCCS.h']
[    INFO]2021-04-29 10:41:00,494 nicelib.build: Parsing and cleaning headers...
[    INFO]2021-04-29 10:41:00,554 instrumental.drivers: Error when importing driver module spectrometers.thorlabs_ccs: <<Unsupported constant type 'long int'>>

Unfortunately I'm still a newbie in programing and even in github! So just wanted to ask where I can have the patch that Nate Bogdanowicz mentioned before and where I need to install it on my computer as I don't know where to find it in github:

I pushed a change to the CCS driver that will instruct NiceLib to choose the right set of typedefs in visatype.h. I'd suggest pulling this new code and deleting your Instrumental\instrumental\drivers\spectrometers_tlccslib.py file so it gets regenerated.

Thank you very much for your help and again apologies if this is not the right way to make this request.

Regards,

jondoesntgit commented 3 years ago

What you're going to need to do is to clone the current commit of github. That's well documented on the web, but it's gonna be something like:

git clone https://github.com/mabuchilab/Instrumental/

And then you'll want to install it using

cd Instrumental
pip install -e .
jlozanol commented 3 years ago

Hi!

Thanks for the information, I already installed this latest version as advised:

(test) PS C:\Instrumental> dir                                                                                          

    Directory: C:\Instrumental

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        4/30/2021   8:08 AM                docs
d-----        4/30/2021   8:08 AM                examples
d-----        4/30/2021   8:08 AM                images
d-----        4/30/2021   8:14 AM                instrumental
d-----        4/30/2021   8:08 AM                Instrumental_lib.egg-info
d-----        4/30/2021   8:08 AM                tests
d-----        4/30/2021   8:08 AM                tools
-a----        4/30/2021   8:08 AM            214 .gitignore
-a----        4/30/2021   8:08 AM            481 .travis.yml
-a----        4/30/2021   8:08 AM           1679 appveyor.yml
-a----        4/30/2021   8:08 AM            352 AUTHORS
-a----        4/30/2021   8:08 AM           7488 CHANGELOG.rst
-a----        4/30/2021   8:14 AM           7291 lextab.py
-a----        4/30/2021   8:08 AM          35831 LICENSE
-a----        4/30/2021   8:08 AM            214 MANIFEST.in
-a----        4/30/2021   8:08 AM           2904 README.rst
-a----        4/30/2021   8:08 AM             51 readthedocs-requirements.txt
-a----        4/30/2021   8:08 AM            150 setup.cfg
-a----        4/30/2021   8:08 AM           4203 setup.py
-a----        4/30/2021   8:14 AM         175998 yacctab.py

(test) PS C:\Instrumental> pip install -e .                                                                             Obtaining file:///C:/Instrumental
Requirement already satisfied: numpy in c:\users\s3853339\miniconda3\envs\test\lib\site-packages (from Instrumental-lib==0.6) (1.20.2)
Requirement already satisfied: scipy in c:\users\s3853339\miniconda3\envs\test\lib\site-packages (from Instrumental-lib==0.6) (1.6.3)
Requirement already satisfied: pint>=0.7 in c:\users\s3853339\miniconda3\envs\test\lib\site-packages (from Instrumental-lib==0.6) (0.17)
Requirement already satisfied: future in c:\users\s3853339\miniconda3\envs\test\lib\site-packages (from Instrumental-lib==0.6) (0.18.2)
Requirement already satisfied: packaging in c:\users\s3853339\miniconda3\envs\test\lib\site-packages (from pint>=0.7->Instrumental-lib==0.6) (20.9)
Requirement already satisfied: pyparsing>=2.0.2 in c:\users\s3853339\miniconda3\envs\test\lib\site-packages (from packaging->pint>=0.7->Instrumental-lib==0.6) (2.4.7)
Installing collected packages: Instrumental-lib
  Attempting uninstall: Instrumental-lib
    Found existing installation: Instrumental-lib 0.6
    Uninstalling Instrumental-lib-0.6:
      Successfully uninstalled Instrumental-lib-0.6
  Running setup.py develop for Instrumental-lib
Successfully installed Instrumental-lib
(test) PS C:\Instrumental>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

I tried then to re-run the script but having some issues to import the CCS driver:

(test) PS C:\> python
Python 3.9.4 (default, Apr  9 2021, 11:43:21) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from instrumental.log import log_to_screen
>>> log_to_screen()
<RootLogger root (INFO)>
>>> from instrumental import instrument, list_instruments
>>> from instrumental.drivers.spectrometers.thorlabs_ccs import CCS
C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\visa.py:13: FutureWarning: The visa module provided by PyVISA is being deprecated. You can replace `import visa` by `import pyvisa as visa` to achieve the same effect.

The reason for the deprecation is the possible conflict with the visa package provided by the https://github.com/visa-sdk/visa-python which can result in hard to debug situations.
  warnings.warn(
[    INFO]2021-04-30 08:32:46,592 nicelib.nicelib: Creating class NiceObject...
[    INFO]2021-04-30 08:32:46,592 nicelib.nicelib: Creating class NiceLib...
[    INFO]2021-04-30 08:32:46,592 nicelib.nicelib: Processing attr '__module__' (<class 'str'>)...
[    INFO]2021-04-30 08:32:46,592 nicelib.nicelib: ...as an ordinary class attribute
[    INFO]2021-04-30 08:32:46,593 nicelib.nicelib: Processing attr '__qualname__' (<class 'str'>)...
[    INFO]2021-04-30 08:32:46,593 nicelib.nicelib: ...as an ordinary class attribute
[    INFO]2021-04-30 08:32:46,594 nicelib.nicelib: Processing attr '__doc__' (<class 'str'>)...
[    INFO]2021-04-30 08:32:46,594 nicelib.nicelib: ...as an ordinary class attribute
[    INFO]2021-04-30 08:32:46,595 nicelib.nicelib: Processing attr '_ffi' (<class 'NoneType'>)...
[    INFO]2021-04-30 08:32:46,595 nicelib.nicelib: ...as a special NiceLib attribute
[    INFO]2021-04-30 08:32:46,596 nicelib.nicelib: Processing attr '_ffilib' (<class 'NoneType'>)...
[    INFO]2021-04-30 08:32:46,597 nicelib.nicelib: ...as a special NiceLib attribute
[    INFO]2021-04-30 08:32:46,598 nicelib.nicelib: Processing attr '_defs' (<class 'dict'>)...
[    INFO]2021-04-30 08:32:46,599 nicelib.nicelib: ...as a special NiceLib attribute
[    INFO]2021-04-30 08:32:46,599 nicelib.nicelib: Processing attr '_ret_return' (<class 'nicelib.nicelib.RetHandler'>)...
[    INFO]2021-04-30 08:32:46,600 nicelib.nicelib: ...as a RetHandler
[    INFO]2021-04-30 08:32:46,601 nicelib.nicelib: Processing attr '_ret_ignore' (<class 'nicelib.nicelib.RetHandler'>)...
[    INFO]2021-04-30 08:32:46,606 nicelib.nicelib: ...as a RetHandler
[    INFO]2021-04-30 08:32:46,606 nicelib.nicelib: Processing attr '__new__' (<class 'function'>)...
[    INFO]2021-04-30 08:32:46,609 nicelib.nicelib: ...as an ordinary function
[    INFO]2021-04-30 08:32:46,611 nicelib.nicelib: Found NiceObjectDefs: {}
[    INFO]2021-04-30 08:32:46,611 nicelib.nicelib: Found NiceObject subclasses: {}
[    INFO]2021-04-30 08:32:46,612 nicelib.nicelib: Found root sigs: {}
[    INFO]2021-04-30 08:32:46,613 nicelib.nicelib: Found return-handlers: {'return': <RetHandler(name='ret_return')>, 'ignore': <RetHandler(name='ret_ignore')>, '_ret_return': <RetHandler(name='_ret_return')>, '_ret_ignore': <RetHandler(name='_ret_ignore')>}
WARNING: Couldn't write lextab module 'nicelib.parser.lextab'. [Errno 13] Permission denied: 'lextab.py'
WARNING: Couldn't create 'nicelib.parser.yacctab'. [Errno 13] Permission denied: 'yacctab.py'
[    INFO]2021-04-30 08:32:47,734 nicelib: Loading lib tlccs...
[    INFO]2021-04-30 08:32:47,735 nicelib: Loading ._tlccslib from instrumental.drivers.spectrometers...
[    INFO]2021-04-30 08:32:47,736 nicelib: Loading build module ._build_tlccs from instrumental.drivers.spectrometers...
[    INFO]2021-04-30 08:32:47,740 nicelib.build: Module _tlccslib does not yet exist, building it now. This may take a minute...
[    INFO]2021-04-30 08:32:47,742 nicelib.build: Searching for headers...
[    INFO]2021-04-30 08:32:47,745 nicelib.util: Looking for ('TLCCS.h',) in ('{PROGRAMFILES}\\IVI Foundation\\VISA\\Win64\\Include', '{PROGRAMFILES(X86)}\\IVI Foundation\\VISA\\Win64\\Include')
[    INFO]2021-04-30 08:32:47,749 nicelib.build: Found ['C:\\Program Files\\IVI Foundation\\VISA\\Win64\\Include\\TLCCS.h']
[    INFO]2021-04-30 08:32:47,752 nicelib.build: Parsing and cleaning headers...
Traceback (most recent call last):
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\nicelib\__init__.py", line 67, in load_lib
    lib_module = import_module(lib_name, pkg)
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'instrumental.drivers.spectrometers._tlccslib'     -------> THIS ERROR!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\instrumental\instrumental\drivers\spectrometers\thorlabs_ccs.py", line 67, in <module>
    class NiceCCSLib(NiceLib):
  File "c:\instrumental\instrumental\drivers\spectrometers\thorlabs_ccs.py", line 69, in NiceCCSLib
    _info_ = load_lib('tlccs', __package__)
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\nicelib\__init__.py", line 73, in load_lib
    build_module.build(**kwargs)
  File "c:\instrumental\instrumental\drivers\spectrometers\_build_tlccs.py", line 38, in build
    build_lib(header_info, lib_names, '_tlccslib', __file__, token_hooks=(vi_func_hook,),
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\nicelib\build.py", line 121, in build_lib
    retval = process_headers(header_paths, predef_path,
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\nicelib\process.py", line 1737, in process_headers
    return process_source(source,
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\nicelib\process.py", line 1775, in process_source
    parser.parse(update_cb=update_cb)
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\nicelib\process.py", line 444, in parse
    self.parse_next()
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\nicelib\process.py", line 466, in parse_next
    keep_line = parse_directive()
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\nicelib\process.py", line 589, in parse_if
    value = self.parse_expression(self.pop_until_newline())
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\nicelib\process.py", line 749, in parse_expression
    py_src = c_to_py_src(' '.join(token.string for token in tokens))
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\nicelib\process.py", line 1514, in c_to_py_src
    return ''.join(to_py_src(expr_node))
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\nicelib\process.py", line 1597, in to_py_src
    py_right = to_py_src(node.right)
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\nicelib\process.py", line 1597, in to_py_src
    py_right = to_py_src(node.right)
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\nicelib\process.py", line 1625, in to_py_src
    raise ConvertError("Unsupported constant type '{}'".format(node.type))
nicelib.process.ConvertError: Unsupported constant type 'long int'      -------> THIS ERROR!

The error I'm more concern atm is the ModuleNotFoundError: No module named 'instrumental.drivers.spectrometers._tlccslib', I'm not sure if something is still not installed...

Thank you again for your patience!

jondoesntgit commented 3 years ago

I think this is an option that you have to supply during installation. @rogers132 would probably know how to invoke it, since he wrote:

https://github.com/mabuchilab/Instrumental/blob/8cfc5a1f8c93a00a5b23881b170b3fb191bb2087/instrumental/drivers/spectrometers/_build_tlccs.py

If I had to guess, you need something like

pip install instrumental[spectrometers.tlcc]
jlozanol commented 3 years ago

Ok,

I think I know what happened there... Instrumental driver was called _build_tlccs.py instead of _tlccslib. I changed the name of that file and now I got this error:

Python 3.9.4 (default, Apr  9 2021, 11:43:21) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from instrumental.log import log_to_screen
>>> log_to_screen()
<RootLogger root (INFO)>
>>> from instrumental import instrument, list_instruments
>>> from instrumental.drivers.spectrometers.thorlabs_ccs import CCS
C:\Users\s3853339\Miniconda3\envs\test\Lib\site-packages\visa.py:13: FutureWarning: The visa module provided by PyVISA is being deprecated. You can replace `import visa` by `import pyvisa as visa` to achieve the same effect.

The reason for the deprecation is the possible conflict with the visa package provided by the https://github.com/visa-sdk/visa-python which can result in hard to debug situations.
  warnings.warn(
[    INFO]2021-04-30 13:03:08,416 nicelib.nicelib: Creating class NiceObject...
[    INFO]2021-04-30 13:03:08,416 nicelib.nicelib: Creating class NiceLib...
[    INFO]2021-04-30 13:03:08,417 nicelib.nicelib: Processing attr '__module__' (<class 'str'>)...
[    INFO]2021-04-30 13:03:08,417 nicelib.nicelib: ...as an ordinary class attribute
[    INFO]2021-04-30 13:03:08,417 nicelib.nicelib: Processing attr '__qualname__' (<class 'str'>)...
[    INFO]2021-04-30 13:03:08,417 nicelib.nicelib: ...as an ordinary class attribute
[    INFO]2021-04-30 13:03:08,418 nicelib.nicelib: Processing attr '__doc__' (<class 'str'>)...
[    INFO]2021-04-30 13:03:08,418 nicelib.nicelib: ...as an ordinary class attribute
[    INFO]2021-04-30 13:03:08,418 nicelib.nicelib: Processing attr '_ffi' (<class 'NoneType'>)...
[    INFO]2021-04-30 13:03:08,418 nicelib.nicelib: ...as a special NiceLib attribute
[    INFO]2021-04-30 13:03:08,418 nicelib.nicelib: Processing attr '_ffilib' (<class 'NoneType'>)...
[    INFO]2021-04-30 13:03:08,418 nicelib.nicelib: ...as a special NiceLib attribute
[    INFO]2021-04-30 13:03:08,418 nicelib.nicelib: Processing attr '_defs' (<class 'dict'>)...
[    INFO]2021-04-30 13:03:08,418 nicelib.nicelib: ...as a special NiceLib attribute
[    INFO]2021-04-30 13:03:08,418 nicelib.nicelib: Processing attr '_ret_return' (<class 'nicelib.nicelib.RetHandler'>)...
[    INFO]2021-04-30 13:03:08,419 nicelib.nicelib: ...as a RetHandler
[    INFO]2021-04-30 13:03:08,419 nicelib.nicelib: Processing attr '_ret_ignore' (<class 'nicelib.nicelib.RetHandler'>)...
[    INFO]2021-04-30 13:03:08,419 nicelib.nicelib: ...as a RetHandler
[    INFO]2021-04-30 13:03:08,419 nicelib.nicelib: Processing attr '__new__' (<class 'function'>)...
[    INFO]2021-04-30 13:03:08,419 nicelib.nicelib: ...as an ordinary function
[    INFO]2021-04-30 13:03:08,419 nicelib.nicelib: Found NiceObjectDefs: {}
[    INFO]2021-04-30 13:03:08,419 nicelib.nicelib: Found NiceObject subclasses: {}
[    INFO]2021-04-30 13:03:08,420 nicelib.nicelib: Found root sigs: {}
[    INFO]2021-04-30 13:03:08,420 nicelib.nicelib: Found return-handlers: {'return': <RetHandler(name='ret_return')>, 'ignore': <RetHandler(name='ret_ignore')>, '_ret_return': <RetHandler(name='_ret_return')>, '_ret_ignore': <RetHandler(name='_ret_ignore')>}
[    INFO]2021-04-30 13:03:09,022 nicelib: Loading lib tlccs...
[    INFO]2021-04-30 13:03:09,022 nicelib: Loading ._tlccslib from instrumental.drivers.spectrometers...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\instrumental_lib-0.6-py3.9.egg\instrumental\drivers\spectrometers\thorlabs_ccs.py", line 67, in <module>
    class NiceCCSLib(NiceLib):
  File "C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\instrumental_lib-0.6-py3.9.egg\instrumental\drivers\spectrometers\thorlabs_ccs.py", line 69, in NiceCCSLib
    _info_ = load_lib('tlccs', __package__)
  File "C:\Users\s3853339\Miniconda3\envs\test\Lib\site-packages\nicelib\__init__.py", line 76, in load_lib
    return LibInfo(lib_module)
  File "C:\Users\s3853339\Miniconda3\envs\test\Lib\site-packages\nicelib\__init__.py", line 18, in __init__
    self._ffi = lib_module.ffi
AttributeError: module 'instrumental.drivers.spectrometers._tlccslib' has no attribute 'ffi'

I imagine I'm going in the right direction?

Thanks!

jlozanol commented 3 years ago
(test) C:\Users\s3853339\Miniconda3\envs\test\Lib\site-packages>conda list cffi
# packages in environment at C:\Users\s3853339\Miniconda3\envs\test:
#
# Name                    Version                   Build  Channel
cffi                      1.14.5                   pypi_0    pypi
natezb commented 3 years ago

Hi @jlozanol, and don't worry about being new—in fact you're already formatting your messages very well!

The first error you point out (ModuleNotFoundError) is totally normal for this driver. These NiceLib-based drivers initially do not exist, and their modules are generated the first time you try to use them. What's happening here is that module generation is failing.

The "patch" that was mentioned in #120 was actually a change to NiceLib, so that's the library you need to install from GitHub, since I haven't made a new release since the bug was fixed last September. You can do the same pip install procedure as you did for Instrumental, except you can get the latest NiceLib source this way:

git clone https://github.com/mabuchilab/NiceLib.git

jlozanol commented 3 years ago

OMG! Thx so much @natezb for the clarification!

>>> list_instruments()
C:\Users\s3853339\Miniconda3\envs\test\lib\site-packages\instrumental_lib-0.6-py3.9.egg\instrumental\drivers\motion\ecc100.py:24: UserWarning: Driver 'instrumental.drivers.motion.ecc100' is out of date and incompatible with the current Instrumental core. Pull requests fixing this are welcome.
  warnings.warn(
[<ParamSet[NIDAQ] name='myDAQ1' serial=51317026 model=b'NI myDAQ'>, <ParamSet[CCS] usb='USB0::0x1313::0x8087::M00601006::RAW' serial='M00601006' model=<SpecTypes.CCS175: 32903>>]

>>> ccs175.take_data()
[array([0.00129507, 0.00017651, 0.0005573 , ..., 0.00015271, 0.00062869,
       0.00017651]), array([ 498.61413974,  498.77167515,  498.92921807, ..., 1106.38428328,
       1106.55576025, 1106.72723736])]

It's finally working!!!

Thanks a lot, this is awesome!!!