mccdaq / mcculw

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

Error running the example code #7

Closed anubok closed 2 years ago

anubok commented 6 years ago

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)
jeffreyg3 commented 6 years ago

Hi anubok, BIP5VOLTS is a valid range when you are configured for differential input mode, but if you are configured for single ended, use BIP10VOLTS exclusively (same range works for differential).

anubok commented 6 years ago

Hi,

I need one more clarification. I am using the 1208FS Plus daq and I am referring to the a_in.py example. I wanted to know if I will be able to change the input mode by giving "ul.a_chan_input_mode(board_num, channel, AnalogInputMode.SINGLE_ENDED)". I tried sending this and I get an error that "mcculw.ul.ULError: Error 41: This function can not be used with this board." Can you please point me to the correct way to change the input mode?

jeffreyg3 commented 6 years ago

Hello Anushree, You can programmatically change the front end configuration. You were close, Use this function instead: ul.a_input_mode(board_num, input_mode) Where board_num is the board number in InstaCal or created during Device Discovery() input_mode = AnalogInputMode.SINGLE_ENDED or input_mode = AnalogInputMode.DIFFERENTIAL

anubok commented 6 years ago

Hey Jeff,

Thanks for that quick help. Also one last thing I wanted to know. I am using 3 daqs in single-ended setting and every daq has a particular set of test points to read via analog channels. How do I differentiate them or basically call them? I am currently using this piece of code to add the three daqs to the UL. And I am thinking on calling them by just changing the board_num to 0,1 or 2 depending upon the daq I want to communicate with. Is this the right way?

jeffreyg3 commented 6 years ago

Yes, changing the board number is how you alternate between the different devices you have in your system/configuration.

anubok commented 6 years ago

Hi Jeff,

I need your support again. I am using the following logic to detect the three DAQs that I am using in the test setup.

image

I was thinking that changing board num will help me communicate with the daq I want to. But its not working out. Can you please point out if the above is not enough to create the three devices. I see the serial numbers of all the three devices getting printed in my output. Only issue is while reading the analog channel on daq 2 I see it still communicates with daq 1 even though I change the board_num =1 (I have assigned daq1 as board_num = 0, daq2 as board_num = 1, daq3 as board_num =2).

Well the way I was trying to read channel 3 on daq 2 i.e. board_num =1 is as follows : image

I would like to know why I can not communicate with daq 2 by changing board_num to 1.

Pasting my output too. image

You can check above.

I think the issue is with ul.create_daq_device(board_num, device). Looks like the daqs are not getting added to the UL. I am unable to understand where I am going wrong. Please help.

jeffreyg3 commented 6 years ago

Hi Anushree I believe I see where you went wrong. You are creating 1 single variable called device and then overwriting it each time with a different MCC Device.

I created a test app for this, so I could show it to you. Here are the important pieces: Instance of 3 devices:

    ul.ignore_instacal()
    self.create_widgets()
    self.discover_devices()

def discover_devices(self):
    # Get the device inventory
     self.inventory = ul.get_daq_device_inventory(InterfaceType.USB)

     for self.board_num in range (0,3):
        if len(self.inventory) > 0:
            if self.board_num == 0:
                self.device0 = self.inventory[self.board_num]

            if self.board_num == 1:
                self.device1 = self.inventory[self.board_num]

            if self.board_num == 2:
                self.device2 = self.inventory[self.board_num]

     if self.device0 != None:
        self.board_num = 0
        ul.create_daq_device(self.board_num, self.device0)
        ul.flash_led(self.board_num)
        self.device_0_id_label["text"] =  self.device0.unique_id
        self.device_0_name_label["text"] = self.device0.product_name
        ul.a_input_mode(self.board_num, AnalogInputMode.SINGLE_ENDED) 
        self.ai_props = AnalogInputProps(self.board_num) 
        self.ao_props = AnalogOutputProps(self.board_num)

     if self.device1 != None:
         self.board_num = 1
         ul.create_daq_device(self.board_num, self.device1)
         ul.flash_led(self.board_num)
         self.device_1_id_label["text"] =  self.device1.unique_id
         self.device_1_name_label["text"] = self.device1.product_name
         ul.a_input_mode(self.board_num, AnalogInputMode.SINGLE_ENDED) 
         self.ai_props = AnalogInputProps(self.board_num) 
         self.ao_props = AnalogOutputProps(self.board_num)

     if self.device2 != None:
         self.board_num = 2
         ul.create_daq_device(self.board_num, self.device2)
         ul.flash_led(self.board_num)
         self.device_2_id_label["text"] =  self.device2.unique_id
         self.device_2_name_label["text"] = self.device2.product_name
         ul.a_input_mode(self.board_num, AnalogInputMode.SINGLE_ENDED) 
         self.ai_props = AnalogInputProps(self.board_num) 
         self.ao_props = AnalogOutputProps(self.board_num)

Note I created device0, device1, and device2

to read the various voltages:

def update_value(self): try: self.board_num = 0 channel = 0
ai_range = ULRange.BIP10VOLTS
value = ul.v_in(self.board_num, channel, ai_range) self.value_0_label["text"] = '{:.4f}'.format(value)

        self.board_num = 1
        channel = 0   
        ai_range = ULRange.BIP10VOLTS    
        value = ul.v_in(self.board_num, channel, ai_range)
        self.value_1_label["text"] = '{:.4f}'.format(value)

        self.board_num = 2
        channel = 0   
        ai_range = ULRange.BIP10VOLTS    
        value = ul.v_in(self.board_num, channel, ai_range)
        self.value_2_label["text"] = '{:.4f}'.format(value)

        if self.running:
            self.after(100, self.update_value)
    except ULError as e:
        self.show_ul_error(e)

And the output: image

jackeisenbach3 commented 5 years ago

Hi,

I am using Python 2.7.14 in Cygwin on a Windows 10 machine. I don't see installation tasks for this setup. Can you point me in the right direction to get this running?

Thanks, Jack

jackeisenbach3 commented 5 years ago

Also, I am evaluating an MC USB-1208FS device. Thanks, Jack

jeffreyg3 commented 5 years ago

Hello Jack, Our drivers were never tested with Cygwin. It is not believed they are compatible. Cygwin is a virtual Linux environment running on Windows and cannot use our Windows hardware drivers. Conversely, since Cygwin is emulating Linux, it cannot use our Linux hardware drivers either since it is running on Windows. Best regards, Jeff

jackeisenbach3 commented 5 years ago

Hi Jeff,

Thanks much for your quick response!

Best regards, Jack

On Thu, Dec 27, 2018 at 9:07 AM JeffG at MCC notifications@github.com wrote:

Hello Jack, Our drivers were never tested with Cygwin. It is not believed they are compatible. Cygwin is a virtual Linux environment running on Windows and cannot use our Windows hardware drivers. Conversely, since Cygwin is emulating Linux, it cannot use our Linux hardware drivers either since it is running on Windows. Best regards, Jeff

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mccdaq/mcculw/issues/7#issuecomment-450192579, or mute the thread https://github.com/notifications/unsubscribe-auth/AeQjTChZXkVAegwt-FnqXgRR-0REDaxTks5u9P5hgaJpZM4T1wn- .