Giter Site home page Giter Site logo

mcculw's Introduction

Info Contains a Python API for interacting with Measurement Computing's Universal Library in Windows. See GitHub for the latest source.
Author Measurement Computing

About

The mcculw package contains an API (Application Programming Interface) for interacting with the I/O Library for Measurement Computing Data Acquisition products, Universal Library. This package was created and is supported by MCC. The package is implemented in Python as a wrapper around the Universal Library C API using the ctypes Python Library.

Note: The mcculw examples included in version 1.0.0 and later are not backward compatible with pre-release versions of the mcculw Python package. See the Examples section for more details.

mcculw is supported for Universal Library 6.55 and later. Some functions in the mcculw package may be unavailable with earlier versions of Universal Library. Visit http://www.mccdaq.com/Software-Downloads.aspx to upgrade your version of UL.

mcculw supports only the Windows operating system.

mcculw supports CPython 2.7 and 3.4+.

The mcculw package is available on GitHub and PyPI.

Installation

  1. Install Python version 2.7, 3.4, or later from https://www.python.org/downloads/ .

  2. Install the latest version of InstaCal from http://www.mccdaq.com/Software-Downloads.aspx .

  3. Install the the MCC UL Python API for Windows (mcculw) and any dependencies using pip:

    1. Open the Windows command prompt: press Win+R, type cmd.exe and press Enter.

    2. Upgrade pip to the latest version by entering the following command:

      pip install --upgrade pip
      
    3. Install the mcculw library by entering the following command:

      pip install mcculw
      

    Note: If you get a message like "pip is not recognized as an internal or external command...", or if you have multiple Python installations, enter the full path to the pip executable, such as C:\Python27\Scripts\pip install --upgrade pip or C:\Python27\Scripts\pip install mcculw. The pip command is in the Scripts subdirectory of your Python install location.

Examples

Download the examples zip file from the mcculw GitHub repository.

Unzip the examples to a known location, such as:

C:\Users\Public\Documents\Measurement Computing\DAQ\Python

Refer to the knowledgebase article Importing Python for Windows example programs into an IDE for detailed instructions on how to import examples into popular IDEs such as Eclipse and Visual Studio.

Note: The latest examples take advantage of the mcculw.device_info subpackage added in version 1.0.0. Software developed using the props subpackage included in the examples folder of pre-release versions will continue to work with version 1.0.0 and later of the mcculw Python package, but requires the inclusion of the props subdirectory. See the mcculw GitHub Releases page for a complete archive of previous releases.

Usage

The following is a basic example of using the Universal Library to perform analog input. Further examples may be found on GitHub.

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)

Support/Feedback

The mcculw package is supported by MCC. For support for mcculw, contact technical support through http://www.mccdaq.com/Support.aspx . Please include version information for Python, Universal Library and the mcculw packages used as well as detailed steps on how to reproduce the problem in your request.

Bugs/Feature Requests

To report a bug or submit a feature request, please use the mcculw GitHub Issues page.

Documentation

Documentation is available in the Universal Library Help.

mcculw's People

Contributors

dfraskamcc avatar jeffreyg3 avatar jon-perreault avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mcculw's Issues

mcculw.ul.ULError: Error 1 - Acquisition with DT9804

I am trying to test some of the examples provided using a DT9804-EC-I-BNC-8DI device, but all of them result in mcculw.ul.ULError: Error 1: Invalid board number.

All drivers are correctly installed as I am able to acquire signals using other software (e.g. QuickDAQ), although no board appears in the InstaCal app.

What can be the issue?

Thanks for your support

TC32

Is there an example for getting thermocouple temp data from a TC32 without expansion board?

-10.7 V dip before analog output starts

I am using your mcculw library with Python 3.6.6 on Windows 10 64 bit to connect to a USB-3101FS D/A converter.

I am able to generate the waveforms without issue but when looking at them on a scope, I am noticing there is a -10.7V glitch that occurs approximately 20 ms before waveform generation starts. My waveform starts and finishes at 0V corresponding to a DAC value of 32768.

Is there any way to prevent this? That sort of a spike could potentially be dangerous when amplified...

TEK0000
TEK0001

I have attached my code. I had to rename it to .txt for GitHub to allow it.
a_out_scan.txt

Access violation when calling ul.stop_background

Hi,

I am trying to use a continuous background scan with a USB2404-UI board to read temperature from a type-K thermocouple. I run a loop where I call ul.get_status and read the data from a buffer that I allocated. The program does this in a loop. But after a few iterations (1 to 100 it is rather non deterministic) the call to ul.stop_background makes the program crash. I put up an example program that reproduces this behavior. It functions as follows:

  1. a background scan is started
  2. a polling loop reads the allocated buffer
  3. terminate the background scan with ul.stop_background
  4. free the allocated buffer
  5. Repeat step 1 to 4 until the program crashes.

I opened a support ticket with Measurement Computing but thought I would ask here too in case there is something obvious in my code that could cause this error. Attached is an example script that reproduces the error. When the script is run the program will always end before getting to the 'Program exited normally' at line 172.

Attaching to the python process with Visual Studio reveals that the code crashes with an access violation coming from the cbw64.dll or daqlib64.dll.

Questions I have:

  • Can we call a_in_scan and stop_background many times in a process? If not, why?
  • What could be happening here, is there some race condition inside the background function?
  • Is there some sort of logging that could be activated to debug this issue?

I never had this behavior with a USB-2416 board so I suspect that this could be specific to the USB2404-UI. The only workaround I found is to start a new process each time, but this is suboptimal since I also noticed that the mcculw libraries do not like to be loaded in different processes at the same time so we must be careful to avoid this.

Here is the code of my example program. Only numpy and mcculw are required to run it. I tested with Python 3.7.0 and Python 3.8.2.

"""
Example script to demonstrate that a background continuous scan
cannot be started and stopped and restarted over and over with the USB2404UI
without crashing the process. The only way this can be achieved is by
starting a new process every time we wish to start a background and continuous
scan.
"""

import time
import random
import traceback
from ctypes import POINTER, c_double, cast

import numpy as np
from mcculw import ul
from mcculw.enums import (AdTimingMode, AiChanType, BoardInfo, ExpansionInfo,
                          FunctionType, InfoType, ScanOptions, TcType,
                          TempScale, TInOptions, ULRange, InterfaceType)

def config(board_num: int, n_channels: int):
    for ch in range(n_channels):
        ul.set_config(
            InfoType.BOARDINFO, board_num, ch,
            BoardInfo.ADTIMINGMODE, AdTimingMode.HIGH_SPEED
        )
        ul.set_config(
            InfoType.BOARDINFO, board_num, ch,
            BoardInfo.ADCHANTYPE, AiChanType.TC
        )
        ul.set_config(
            InfoType.BOARDINFO, board_num, ch,
            BoardInfo.CHANTCTYPE, TcType.K
        )
        # Not sure this is required
        ul.set_config(
            InfoType.BOARDINFO, board_num, ch,
            BoardInfo.RANGE, ULRange.BIPPT125VOLTS
        )

def allocate_data_buffer(n_channels: int, rate: int=50):
    num_points = rate
    total_points = n_channels * num_points
    buffer_size = 2 * total_points
    handle = ul.scaled_win_buf_alloc(buffer_size)
    return handle, buffer_size, total_points

def poll(board_num: int, n_channels: int, rate: int=50, period: float=0.1,
         duration: float=60.0, count: int=0, sleep_before_stop: float=0.0):
    """
    Configure a USB2404UI board for K-type thermocouple acquisition, start a
    background function and poll the universal library for new data.

    Args:
        board_num (int): The board number
        n_channels (int): The number of channels
        rate (int, optional): The sampling rate. Defaults to 50.
        period (float, optional): The polling period. Defaults to 0.1.
        duration (float, optional): The duration of the polling. Defaults to 60.0.
        count (int, optional): The iteration count. Defaults to 0.
        sleep_before_stop (float, optional): Sleep duration before calling
        ul.stop_background. Defaults to 0.0.

    Raises:
        RuntimeError: If the status returned by ul.get_status turns to 0 during
                      the polling.
    """
    handle = None
    try:
        print('Configuring channels...')
        config(board_num, n_channels)
        handle, buffer_size, total_points = allocate_data_buffer(n_channels, rate)
        ctypes_array = cast(handle, POINTER(c_double))

        scan_options = (ScanOptions.BACKGROUND | ScanOptions.CONTINUOUS |
                        ScanOptions.SCALEDATA)
        low_channel = 0
        high_channel = n_channels-1
        print('Starting background function...')
        actual_rate = ul.a_in_scan(
            board_num,
            low_channel, high_channel, buffer_size, rate,
            ULRange.BIPPT125VOLTS, handle, scan_options
        )
        print(f'Background function started with rate {actual_rate}')
        print(f'Polling for {duration} secs...')

        start_time = time.time()
        now_time = start_time
        end_time = start_time + duration
        while now_time < end_time:
            status, curr_count, curr_index = ul.get_status(
                board_num, FunctionType.AIFUNCTION
            )
            if not status:
                raise RuntimeError('Background function failed to start properly')
            arr = np.ctypeslib.as_array(
                ctypes_array,
                shape=(buffer_size,)
            ).copy()
            start = curr_index*n_channels
            end = start + n_channels
            print(f'{count}|{end_time-now_time:5.2f}: status = {status}, curr_count = {curr_count:05d}, curr_index = {curr_index:03d},  arr[{start:03d}:{end:03d}] = {arr[start:end]}')
            time.sleep(period)
            now_time = time.time()

    finally:
        print(f'Sleeping for {sleep_before_stop} secs before stop', flush=True)
        time.sleep(sleep_before_stop)
        status, _, _ = ul.get_status(board_num, FunctionType.AIFUNCTION)
        if status:
            print(f'Stopping background function, status was {status}', flush=True)
            # ******************************************************************
            # A silent crash always happens at some point here after a few calls
            # to the ul.stop_background function. The only way to work around
            # this is to start a fresh process everytime.
            # ******************************************************************
            ul.stop_background(board_num, FunctionType.AIFUNCTION)
            print(f'Background function stopped', flush=True)
        if handle is not None:
            print(f'Freeing handle {handle}', flush=True)
            ul.win_buf_free(handle)
            print(f'Handle freed', flush=True)
        print('Polling done.', flush=True)

def random_duration(min_duration: float=0.01, max_duration: float=1.0) -> float:
    d = max_duration - min_duration
    return random.random()*d + min_duration

def poll_with_random_restarts(board_num: int, n_channels: int, rate: int=50,
                              min_duration: float=0.0, max_duration: float=2.0,
                              sleep: float=0.0, iterations: int=1000):
    """
    Start a USB2404UI polling loop for random durations for up to `iterations`
    iterations.

    Args:
        board_num (int): The board number
        n_channels (int): The number of channels
        rate (int, optional): The sampling rate. Defaults to 50.
        period (float, optional): The polling period. Defaults to 0.1.
        duration (float, optional): The duration of the polling. Defaults to 60.0.
        count (int, optional): The iteration count. Defaults to 0.
        sleep (float, optional): Sleep duration before calling
                                 ul.stop_background. Defaults to 0.0.
    """
    count = 0
    while count < iterations:
        duration = random_duration(min_duration, max_duration)
        poll(board_num, n_channels, rate, duration=duration, count=count, sleep_before_stop=sleep)
        count += 1

def main(n_channels: int=1, min_duration: float=0.0, max_duration: float=2.0,
         sleep: float=0.0, iterations: int=1000):
    min_duration = max(0.0, min_duration)
    max_duration = max(min_duration, max_duration)
    try:
        ul.ignore_instacal()
        usb_devices = ul.get_daq_device_inventory(InterfaceType.USB)
        print(f'Found {len(usb_devices)} devices')
        for board_num, device in enumerate(usb_devices):
            ul.create_daq_device(board_num, device)

        if not usb_devices:
            raise RuntimeError('No device found')

        board_num = 0
        poll_with_random_restarts(
            board_num, n_channels,
            min_duration=min_duration, max_duration=max_duration,
            sleep=sleep, iterations=iterations
        )
        print('Program exited normally.')
    except KeyboardInterrupt:
        pass
    except Exception as ex:
        print(traceback.format_exc())


if __name__ == '__main__':
    import argparse
    import os
    parser = argparse.ArgumentParser()
    parser.add_argument('--num', type=int, default=1)
    parser.add_argument('--min', type=float, default=0.0)
    parser.add_argument('--max', type=float, default=2.0)
    parser.add_argument('--sleep', type=float, default=0.0)
    parser.add_argument('--iter', type=int, default=1000)
    args = parser.parse_args()

    # inp = input(f'Press enter to start the test {os.getpid()}...')
    main(args.num, args.min, args.max, args.sleep, args.iter)

crash_usb2404ui.py.txt

Abort/cancel analog trigger

If one configures an analog trigger, e.g. a_trig(board_num, channel, TrigType.TRIG_ABOVE, trig_value, ULRange.BIP10VOLTS), is there any way to cancel or abort the call if the trigger event does not take place?

a_out_scan example doesn't work -> error: 17 invalid count

Hello,
I'm trying to get the a_out_scan.py example running but I keep getting the Error 17: Invalid count. I tried to change the arguments of the function but I didn't find the problem..
Would be great if someone could point me in the right direction

Lukas

Invaild board number

I'm using MC USB-1608G device. When running examples files, some files **.py works while others don't work and showing Exception has occurred, Error: invaild board number, I hve no idea which part i should set. Now i have an experiment, i have 4 tension and compression sensors and i wanna use MC device to collect data and show data. The problem is that DAQami software shows voltage signals but i wanna it shows force data in the interface, so is there any way to realize this function?

a_in / v_in functions fail

Whenever I try to use the functions a_in / v_in the code just runs endlessly without outputting a result. Here I provide an example in which I re-wrote the function supported_ranges and it gets stuck when getting to a_in for the valid input voltage channels.

Days ago I was able to send a voltage through an output channel and read it through an input one, but now I can't even read. If I run the file v_in.py it will run endlessly without getting to the end, being stuck in a_in

function_supported_ranges
Result

Error running the example code

I am new to python and trying to work with MCC daq 1208FS PLUS. I am done installing the mcculw and was trying to run the basic example of using the Universal Library to perform analog input given in the README section. But I am getting a traceback 'A UL error occurred. Code: 30 Message: Invalid voltage (or current) range.' Can you please help me troubleshoot this? I have connected the pin1 to the positive of my powersupply and pin3 to the negative of the powersupply. Powersupply is set to 6V.

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)

mcculw cannot find the dlls on python 3.8

"Could not find module 'cbw32.dll'. Try using the full path with constructor syntax."

Different version of Instacal makes no difference.
I have a Win10 64bit that works, but this is really annoying. Either the discovery should be better implemented or the Instacal installation changed.

I should not need to modify the package source or manually change the path on some computer.

FYI: 2 other tickets have been raised about this issue before, but closed without any action.

Issues with mcculw import ul

Hello;

I'm trying to run the example code using Python and the mcculw. The very first line

from mcculw import ul throws an error which last line says " AtributeError: function 'cbAChanInputMode' not found. " The PC has windows 7 Home Premium SP1 64 bits (Iddle 32 bits)

This same example runs OK in another PC with windows 7 Professional SP1 32bits. The board used is MCC USB-7202.

I need to know what am I doing wrong. Both systems have the same Python 3.7-32 bits and the same mcculw installed. I want the programs to run in any PC to implement test stations.

Any help will be appreciated.

Error 126: Cannot find CB.CFG file

I try to run this code on : https://github.com/mccdaq/mcculw
But it sends me this error.
Can somebody tell me what's wrong or provide the file?

value = ul.a_in(board_num, channel, ai_range)
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\ROBOT\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mcculw\ul.py", line 84, in a_in
_check_err(_cbw.cbAIn(
File "C:\Users\ROBOT\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mcculw\ul.py", line 5877, in _check_err
raise ULError(errcode)
mcculw.ul.ULError: Error 126: Cannot find CB.CFG file.

Analog out default

I'm running the analog out example. I'm using Jupyter to write my python code.

I've notice if I interrupt the kernel (suppose to be the same as Ctrl + C), it quits, but the voltage jumps to the max voltage. Is there any way to prevent this happening? It's actually a safety issue for me.

Acqknowledge does not detect digital signal

I'm trying to send digital signal from "Psychopy" to "Acqknowledge", to check timing.
Before implementing, I checked if example codes worked well.
I used "USB-1280FS-Plus" module with "InstaCal". When I run examples, there was no error. It showed me message such as "Setting FIRSTPORTA to 255" and "Setting FIRSTPORTA bit 0 to 0" in digital_out.py example. However, in acqknowledge, nothing happened.
I'm using MP150 and STP100C to receive digital signal. "USB-1280FS-PLUS" module is connected with STP100C by printer port. 5V, GND, A0 port, B0 port is connected to printer port.
I could check digital channel 8 and 15 are connected because only they are read as 0V. But their values never changed to 5 (high) whatever I run the example or not.

I thought that A0 port and B0 port in "USB-1280FS-PLUS" are corresponded to 8 and 15 channel in Acqknowledge. So When I run the example code, at least one value of those channels (8, 15) should be changed since I got "Setting FIRSTPORTA to 255" message back.

I'm wondering what is the problem and can I solve the problem by fixing the code, or is it the hardware problem.
Thank you in advance.

  • Examples which I run to check it was worked are as follows: digital_out.py, v_out.py, ULDO01.py, ULDO02.py, and VOut01.py

Reading analog inputs in different processes

It looks like it is not possible to read the different channels in different processes, the configuration is somehow only known in the main process memory space. Is there some sort of limitation on this?

USB interface crashes (USB-ERB24)

I am using the mcculw library to switch a power source to a row of outputs with the "USB-ERB24" relais board.
The script is based on the "digital_out.py" example and simply switches the power source from relais 1 to relais 6.
This works for about 2 cycles and then the "USB-ERB24" disconnects from the windows machine. The onboard LED "USB" turns off and the device is not recognized by the windows machine anymore. Only a power cycle of the "USB-ERB24" brings it back again.

I get a range of errors:
First error is "Error 2: Digital device is not responding."
Then on the retries I get "Error 1: Invalid board number."
After couple of retries the interface finally crashes and I get "Error: The DAQ device does not support digital I/O"

Any ideas what the problem might be?

Edit:
I've implemented a wait between calling ul.d_bit_out(). Seems to run way more stable now. Still get occasional "Error 1: Invalid board number" though. No idea where that comes from.
Is there communication timing implemented in the library?
Is there a way to check if the device is busy?

ScanOptions.BACKGROUND not working with USB-3101FS

I am using a USB-3101FS and copying the a_out_scan example.

I don't think the ScanOptions.BACKGROUND mode is working properly because after executing ul.a_out_scan there is a long pause and then "Waiting for output scan to complete..." appears immediately followed by "Scan completed successfully".

I am running Python 3.6.6 on Windows 10 64-bit

Raw Data Array

Hello,
Example used: ULAIO1 (from ui)
I am trying to write data from an analog input into another file at 1000 Herz.
Right now my solution is using the variable eng_value to write. I tried finding out what the original array is where all the raw analog input data is being saved but cannot find it.
I know the a_in function is involved, but can't find where it draws the values from.

Thanks in advance,
Max

Problems with MCC DAQ Universal Library

I need to use an MCC DAQ USB-2408-2AO to make temperature measurements from 8 thermocouples. I'm using the Universal Library and Python to be able to eventually synchronize the data acquisition with other processes, but every time that I run my code, I get the error:

mcculw.ul.ULError: Error 30: Invalid voltage (or current) range.

Here is my Python Script so far:

from mcculw import ul
from mcculw.enums import ULRange

inventory = ul.get_daq_device_inventory(1, number_of_devices=1)
print(inventory)
ul.ignore_instacal()
ul.create_daq_device(1,inventory[0])

ULRange.BIPPT078VOLTS
ul.a_input_mode(1,0)

temps = ul.t_in_scan(1,0,7,0)
print(temps)

The DAQ and thermocouples already work with the software that they came with (DAQami), so I'm pretty sure this is not a hardware problem. Does anyone know what I am doing wrong? Is there some configuration that I have overlooked?

As a side note, I have already read the post at #7. It hasn't been helpful for my case.

Thanks for you time!

Cannot run example code with USB-TC-AI 2.xxx

I have three USB-TC-AI devices. The oldest one (v1.2) works fine with v_in.py example, but two newer ones cause the test script to hang indefinitely.

python .\v_in.py
Found 1 DAQ device(s):
  USB-TC-AI (2154A57) - Device ID = 187

Active DAQ device: USB-TC-AI (2154A57)

Value: -0.022411394864320755`

After connecting another device:

python .\v_in.py
Found 1 DAQ device(s):
  USB-TC-AI (212BCD8) - Device ID = 187

<no other output>

The product number on non-working device is 158042B-01L

Problem with ulw in Python no module named examples.console

Nub here. I downloaded 2.7 Python and Instacal and we install the MCC UL Python API for Windows (mcculw) and did the upgrade. We got the script "a_in_scan_file.py" and ran it and we keep getting "ImportError: No module named examples.console"

I asked someone familiar with MCC and he told me to add "mcculw" to line 11.

We did it and it still wont run. We only need to write to a file on the machine.

Can you help so we can start the python code?

a_in_scan_file_pyNOTE.txt

A UL error occured. Code: 126 Message: Cannot find CB.CFG file.

I have followed the steps within the Installation, and tried running the basic example from the Usage section and I am getting the following error:

A UL error occured. Code: 126 Message: Cannot find CB.CFG file.

I am running python2.7 on Windows 10.

I was getting the same error code when trying to run the depreciated PyUniversalLibrary module.

Module cbw64.dll not found

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.

Invalid Board Number

I get an error when running a simple test:

Environment:

  • Model = USB-2533
  • Windows 10
  • Python version = 3.10.9
  • MccDaq.dll version = 3.73
  • mcculw version = 1.0.0
from mcculw import ul

value = ul.a_in(0, 6, 1)
print("Raw Value: " + str(value))

Returns the following:

Traceback (most recent call last):
  File "C:\Users\mtaylor\Documents\dev\mcc_test2.py", line 3, in <module>
    value = ul.a_in(0, 6, 1)
  File "C:\Users\mtaylor\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mcculw\ul.py", line 85, in a_in
    _check_err(_cbw.cbAIn(
  File "C:\Users\mtaylor\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\mcculw\ul.py", line 6128, in _check_err
    raise ULError(errcode)
mcculw.ul.ULError: Error 1: Invalid board number.

It is working in C#:

using MccDaq;

MccDaq.MccBoard DaqBoard = new MccDaq.MccBoard(0);

MccDaq.ErrorInfo ULStat;
System.UInt16 DataValue;

ULStat = DaqBoard.AIn(6, MccDaq.Range.Bip10Volts, out DataValue);
Console.WriteLine("Value=" + DataValue.ToString());

Returns the following:
Value=32766

USB-1808 not detected on Win11

My MCC device (USB-1808) is not detected using either the instacal or the mcculw function: ul.get_daq_device_inventory(InterfaceType.ANY). I'm using the usb cable that came with the device, with not USB adapters, and I have tried multiple USB ports. I have tried running the same python scripts, in the same conda environment on two different computers. The computer running Windows 10 works perfectly. The computer running Windows 11, does not detect.

I know Win11 is fairly new and these issues are bound to happen (thus the reason my work laptop is still running Win10), but is there any work around? Or is there any timeline to integrating Win11.

Note: I'm reporting this as an Issue because I haven't seen anywhere in the documentation that specifies Win11 non-compatibility.

Thanks

pip install problem

Running pip with Python 3.6.1, I get:

Collecting mcculw
Using cached mcculw-0.9.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\ROBERT~1.KRU\AppData\Local\Temp\pip-build-3p64eldz\mcculw\setup.py", line 7, in
from version import version
ModuleNotFoundError: No module named 'version'

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in C:\Users\ROBERT~1.KRU\AppData\Local\Temp\pip-build-3p64eldz\mcculw\

Any ideas?

simultaneous analog output update with USB-3103

Hi, I have got an issue using a USB-3103 when trying to update simutaneously several analog channels.

I am using :

  • win10
  • python 3.9
  • mcculw 1.0.0

The code I am using is derived from the suggestion in the issue #31.
I update 2 analog outputs (2 and 3) and monitor them on an oscillope. I use the function a_out_scan with scan_options = 0 and I detect a change of voltages with the good amplitude and a delay of about 1 ms between the 2 channels (this delay increases if I use non consecutive channels). If I repeat with scan_options = ScanOptions.SIMULTANEOUS to get both transitions at the same time then it does not work. The voltages change by a small negative value.

Can you help me understand what I am doing wrong or I do not get?

Thanks,
Rudy

Unable to pip install mcculw

I am new to python and not able to install mcculw. I am getting an error message : error in mcculw setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers

image

Please let me know where am I going wrong. TIA.

Examples.console

Have to place the examples files in the root files before they will run. Seems like there should be a simpler way.

Help with write data to file/live plot data

Hello.
I'm using USB-2408 from MCC and I wanted to modify some examples (ULAI06 exactly) to also live plot gathered data, not only print them in window. I'm new with python and I can't deal with this problem. What I wanted to do is to write measurements to file and then plot them. So i modified the code from row 172 like this:

    f=open("abcde.txt","w+")
    # Update the labels for each channel
    for chan_num in range(low_chan, high_chan + 1):
        chan_index = chan_num - low_chan
        self.chan_labels[chan_index]["text"] = channel_text[chan_index]
        f.write(unicode(channel_text[chan_index]))
    f.close()

but then I got the file in which I receive only 10 measurements which are overrided with the data from app window. Also, all measurements are in list, like that:

Channel 0
-0.078
...
Channel 1
-0.078
...
etc

Could anyone help me modify this example?

Changing analog output 1 affects analog output 0

I'm trying to set the two analog output channels of a USB-231 using the function "a_out" from the mcculw library for python.
Calling this function with the parameter "channel" set to 1 sets the output channel "AOut1" to the desired value, as expected. At the same time, the output channel "AOut0" also changes. I've observed, that it has been set to -10V.
On the other hand, changing the value of "AOut0" does not seem to have any effect on "AOut1".
I was able to reproduce this behavior using the example program ULAO01.py

I think, this behavior is not like it's supposed to be. Or did i overlook anything?

How to read the CJC sensor temperature?

EDIT: This question was initialy about the functions to use to obtain voltage and temperature measurements from the 2404-UI. But the only remaining question is about the CJC temperature. Hence, the issue name change.

I am trying to read the voltage value of a USB 2404-UI board connected to a thermocouple.

from mcculw import ul
from mcculw.enums import ULRange, TempScale, BoardInfo, AiChanType, InfoType,TcType

ul.set_config(InfoType.BOARDINFO, 0, 0, BoardInfo.ADCHANTYPE, AiChanType.TC)
ul.set_config(InfoType.BOARDINFO, 0, 0, BoardInfo.CHANTCTYPE, TcType.S)
t = ul.t_in(0, 0, TempScale.CELSIUS, 0)
print(t)
t = ul.t_in(0, 0, TempScale.NOSCALE, 0)
print(t)
ul.set_config(InfoType.BOARDINFO, 0, 0, BoardInfo.ADCHANTYPE, AiChanType.VOLTAGE)
t = ul.a_in(0, 0, ULRange.BIPPT05VOLTS)
print(t)

The two first calls to ul.t_in work but the call to ul.a_in generates the following error

This function can not be used with this board.

How can I read the voltage generated by the thermocouple? I also tried using:

t = ul.t_in(0, 0, TempScale.VOLTS, 0)

But I get:

Error 74: Invalid temperature scale specified.

Side question: Is it possible to read the value of the CJC sensor on this board?

Not able to set bit wise on port FIRSTPORTB/C/CH with ul.d_bit_out()

I have a USB-DIO24/37 and tried out the example code mcculw/examples/console/digital_out.py. It works fine and values are set on pins of FIRSTPORTA. The example code automatically chooses FIRSTPORTA. If I now choose FIRSTPORTB or C (or CH) and try to set a specific bit with the function ul.d_bit_out(), I get the following error:

Traceback (most recent call last):
  File "e:/test_digitalIO_MCC/digital_out_test.py", line 169, in <module>
    TTL_devices[0].on(8)
  File "e:/test_digitalIO_MCC/digital_out_test.py", line 146, in on
    return self.set(channel, 1)
  File "e:/test_digitalIO_MCC/digital_out_test.py", line 132, in set
    ul.d_bit_out(self.board_number, port_obj.type, bit_num, bit_value)
  File "C:\Program Files\Python37\lib\site-packages\mcculw\ul.py", line 2546, in d_bit_out
    _check_err(_cbw.cbDBitOut(board_num, port_type, bit_num, bit_value))
  File "C:\Program Files\Python37\lib\site-packages\mcculw\ul.py", line 6128, in _check_err
    raise ULError(errcode)
mcculw.ul.ULError: Error 11: Invalid digital port number.

Supprisingly, if I use the ul.d_out() function to set the whole byte-array of a port, it works fine for all ports and I measured the pin-values and everything is fine. The ul.d_bit_out() function would be far more convinient though...

Sync Analog Output on Multiple Channels for USB-3114

Hello everyone,

I recently purchased a USB-3114 board and I am planning to use the synchronized analog output capability in a setup.

I am running on a Python 3.9.5 installed via Miniconda on WIndows 10. I installed the Universal Library for Windows library via pip.

According to the documentation, the the USB 3114 should support this feature calling a_out_scan.
I modified the a_out_scan example to demonstrate the ability to output different voltages on the 16 different channels.
The desired output is the one shown by the program ouput:

Found 1 DAQ device(s):
  USB-3114 (1D6B589) - Device ID = 164

Active DAQ device: USB-3114 (1D6B589)

Channel 0 Output Signal: 5.01
Channel 1 Output Signal: 5.02
Channel 2 Output Signal: 5.03
Channel 3 Output Signal: 5.04
Channel 4 Output Signal: 5.05
Channel 5 Output Signal: 5.06
Channel 6 Output Signal: 5.07
Channel 7 Output Signal: 5.08
Channel 8 Output Signal: 5.09
Channel 9 Output Signal: 5.10
Channel 10 Output Signal: 5.11
Channel 11 Output Signal: 5.12
Channel 12 Output Signal: 5.13
Channel 13 Output Signal: 5.14
Channel 14 Output Signal: 5.15
Channel 15 Output Signal: 5.16

Waiting for output scan to complete....
Scan completed **successfully**

Unfortunately, the output value is not updated in the voltage of the channels. Can you tell where the mistake is?

I also tried to use the single-channel function call a_out to control each channel in a loop. Unfortunately, this function call updates the value of the next channel and at the same time returs the voltage of the previous channel to zero. This makes its use to control multiple channels not viable.

Would appreciate any support in the development of this capability.
Thank you for your help: much appreciated.
Kind regards,

Giorgio

E-1608 a_out_scan

Hi,

I am using E-1608 daq to make a sinusoidal analog output, and meanwhile read the input values. I am using the a_out_scan sample code you provided, but I am getting this error: " [a number] is not a valid Status". The number is changing after running the code multiple times. Here is the example:
Found 1 DAQ device(s):
E-1608 (#####) - Device ID = ###

Active DAQ device: E-1608 (#####)

Channel 0 Output Signal Frequency: 1
Channel 1 Output Signal Frequency: 3
Waiting for output scan to complete....
-6075 is not a valid Status

Could you please assist me with this issue?

Thanks

Problem with analog output

โš™๏ธ Hardware details

I am using the USB-231 USB data acquisition (DAQ).

๐Ÿ’ป Software details

PC details:

  • OS: Windows 10 Home, Version 21H2
  • 64-bit operating system, x64-based processor
  • Python version: 3.9.10
  • Python library concerned : mcculw

๐Ÿค” What am I trying to do ?

The USB 231 has two analog output channels.
I am storing voltages to be outputted in python lists. For example :

array1 = [1,2,3]
array2 = [4,5,6]

array1 in intended for channel number 0 and array2 is intended for channel number 1. I wish to send each voltage as a square wave of 200 Hz (the square wave oscillates between +voltage and -voltage ). Going ahead with the above example, I wish to send :

1V to channel 0 at 200 Hz,
4V to channel 1 at 200 Hz,
2V to channel 0 at 200 Hz,
5V to channel 1 at 200 Hz

so on and so forth.

๐Ÿ˜” What exactly is the problem ?

The voltages appear in each channel but the sign of voltage doesn't match. So, if my array contains -1V , I see it as 1V. If my array contains 2V, I see it as 2V in the output. Sometimes one channel outputs only positive voltages and other only negative voltages.

๐Ÿ‘จโ€๐Ÿ’ป What have I done till now ?

Created a script based on the a_out_scan.py example script to achieve the goal.

Since I didn't get the expected output, I have tried the following:

  • Changing ul.win_buf_alloc to ul.scaled_win_buf_alloc
  • Changing the ctype array from u_short to other types.

But I had no success with these.

๐Ÿ”Ž Script/code ?

Here is a link to my script.

๐Ÿ“ Any specific note ?

I prefer to use the ul.a_out_scan method instead of ul.a_out method, since I can specify the rate as a parameter in ul.a_out_scan method.

๐Ÿ”ฌ Any other observations ?

I have observed that the sign of output voltage varies when I change the rate parameter of ul.a_out_scan. I don't think this is an expected behavior.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.