BenjaminF Posted November 28, 2023 Share Posted November 28, 2023 (edited) Hello, I have downloaded all the required softwares to make the mcculw Python library to work. Now i just need to read out the 10k 2w resistance value via channel 0 in Python. How can this be done? I get the value i want in InstaCal: Br, Benjamin Edited November 28, 2023 by BenjaminF Link to comment Share on other sites More sharing options...
0 Fausto Posted November 28, 2023 Share Posted November 28, 2023 Hello @BenjaminF. After confirming your device's configuration and measurements in InstaCal, take a look at the MCC Universal Library Help. The mcculw Python examples are saved to the 'C:\Users\Public\Documents\Measurement Computing\DAQ\Python\examples' directory on the target system. Test the attached Python UI example, which was updated for your application. ULAI15_27380_v1.py Regards, Fausto Link to comment Share on other sites More sharing options...
0 BenjaminF Posted November 29, 2023 Author Share Posted November 29, 2023 (edited) Hello @Fausto. Thanks for answering me. This was to good help, i can finally see a formatted resistance value, and not just the raw value. But what i really need is to continuously read out a value from Channel 0 on the DAQ, as fast as it can sample. Also, i need this formatted to resistance. I believe this is very easy task if you know what you are doing. Do you have an example to do this? I used your example and made this, which should print out the resistance value on python console. from __future__ import absolute_import, division, print_function from builtins import * # @UnusedWildImport from mcculw import ul from mcculw.device_info import DaqDeviceInfo from mcculw.enums import ScanOptions, ULRange, InfoType, BoardInfo, AiChanType try: from console_examples_util import config_first_detected_device except ImportError: from .console_examples_util import config_first_detected_device def get_resistance(): # By default, the example detects and displays all available devices and # selects the first device listed. Use the dev_id_list variable to filter # detected devices by device ID (see UL documentation for device IDs). # If use_device_detection is set to False, the board_num variable needs to # match the desired board number configured with Instacal. use_device_detection = True dev_id_list = [] board_num = 0 try: if use_device_detection: config_first_detected_device(board_num, dev_id_list) daq_dev_info = DaqDeviceInfo(board_num) if not daq_dev_info.supports_analog_input: raise Exception('Error: The DAQ device does not support ' 'analog input') print('\nActive DAQ device: ', daq_dev_info.product_name, ' (', daq_dev_info.unique_id, ')\n', sep='') ai_info = daq_dev_info.get_ai_info() ai_range = ai_info.supported_ranges[0] channel = 0 ul.set_config(InfoType.BOARDINFO, board_num, channel, BoardInfo.ADCHANTYPE, AiChanType.RESISTANCE_10K2W) #value2 = ul.a_chan_input_mode(board_num, channel, ai_range) # Get a value from the device if ai_info.resolution <= 16: # Use the v_in method for devices with a resolution <= 16 # (optional parameter omitted) value = ul.a_in(board_num, channel, ai_range) else: # Use the v_in_32 method for devices with a resolution > 16 # (optional parameter omitted) value = ul.a_in_32(board_num, channel, ai_range) # Display the value print('Value:', value) except Exception as e: print('\n', e) finally: if use_device_detection: ul.release_daq_device(board_num) if __name__ == '__main__': get_resistance() (This code doesn't work, I get a raw value and not a formatted resistance value on the A/D) I need to get this resistance value sampled every 0.1-1s for 30 seconds while im calibrating a sensor. BR, Benjamin Edited November 30, 2023 by BenjaminF Link to comment Share on other sites More sharing options...
0 BenjaminF Posted November 30, 2023 Author Share Posted November 30, 2023 On 11/28/2023 at 7:51 PM, Fausto said: Hello @BenjaminF. After confirming your device's configuration and measurements in InstaCal, take a look at the MCC Universal Library Help. The mcculw Python examples are saved to the 'C:\Users\Public\Documents\Measurement Computing\DAQ\Python\examples' directory on the target system. Test the attached Python UI example, which was updated for your application. ULAI15_27380_v1.py 9.1 kB · 1 download Regards, Fausto Dear @Fausto My response: Hello @Fausto. Thanks for answering me. This was to good help, i can finally see a formatted resistance value, and not just the raw value. But what i really need is to continuously read out a value from Channel 0 on the DAQ, as fast as it can sample. Also, i need this formatted to resistance. I believe this is very easy task if you know what you are doing. Do you have an example to do this? I used your example and made this, which should print out the resistance value on python console. from __future__ import absolute_import, division, print_function from builtins import * # @UnusedWildImport from mcculw import ul from mcculw.device_info import DaqDeviceInfo from mcculw.enums import ScanOptions, ULRange, InfoType, BoardInfo, AiChanType try: from console_examples_util import config_first_detected_device except ImportError: from .console_examples_util import config_first_detected_device def get_resistance(): # By default, the example detects and displays all available devices and # selects the first device listed. Use the dev_id_list variable to filter # detected devices by device ID (see UL documentation for device IDs). # If use_device_detection is set to False, the board_num variable needs to # match the desired board number configured with Instacal. use_device_detection = True dev_id_list = [] board_num = 0 try: if use_device_detection: config_first_detected_device(board_num, dev_id_list) daq_dev_info = DaqDeviceInfo(board_num) if not daq_dev_info.supports_analog_input: raise Exception('Error: The DAQ device does not support ' 'analog input') print('\nActive DAQ device: ', daq_dev_info.product_name, ' (', daq_dev_info.unique_id, ')\n', sep='') ai_info = daq_dev_info.get_ai_info() ai_range = ai_info.supported_ranges[0] channel = 0 ul.set_config(InfoType.BOARDINFO, board_num, channel, BoardInfo.ADCHANTYPE, AiChanType.RESISTANCE_10K2W) #value2 = ul.a_chan_input_mode(board_num, channel, ai_range) # Get a value from the device if ai_info.resolution <= 16: # Use the v_in method for devices with a resolution <= 16 # (optional parameter omitted) value = ul.a_in(board_num, channel, ai_range) else: # Use the v_in_32 method for devices with a resolution > 16 # (optional parameter omitted) value = ul.a_in_32(board_num, channel, ai_range) # Display the value print('Value:', value) except Exception as e: print('\n', e) finally: if use_device_detection: ul.release_daq_device(board_num) if __name__ == '__main__': get_resistance() (This code doesn't work, I get a raw value and not a formatted resistance value on the A/D) I need to get this resistance value sampled every 0.1-1s for 30 seconds while im calibrating a sensor. BR, Benjamin Link to comment Share on other sites More sharing options...
0 Fausto Posted November 30, 2023 Share Posted November 30, 2023 Hello @BenjaminF. Please test the attached a_in_scan_background_27380_v1a.py example with your USB-2404-UI. a_in_scan_background_27380_v1a.py Regards, Fausto Link to comment Share on other sites More sharing options...
0 BenjaminF Posted December 1, 2023 Author Share Posted December 1, 2023 (edited) Hi @Fausto, I tried the code and it works. But I really just want something even more simpler than this. As mentioned im doing a calibration and need to get a live resistance reading while moving a stepper motor. My only goal is: 1. Continuously read A/D value on channel 0 as fast as the serial communication can do 2. Format this to resistance and not this raw value. 3. Get this value when im asking for it to put it in the list when stepper motor is running I'm actually confused to why this is'nt the 1st example on the GitHub: imports..... def read_ch0_value(): - Continuously read A/D value on channel 0 - Convert to resistance def set_channel_settings(board_num): - set it to resistance and use in read_a_value def get_ch0_value(): - get the formatted resistance value when im asking for it This is all i need. Do i really have to use scan to get this simple value? Edited December 1, 2023 by BenjaminF Typo Link to comment Share on other sites More sharing options...
0 BenjaminF Posted December 5, 2023 Author Share Posted December 5, 2023 (edited) Hi @Fausto, Is the solution i mentioned above possible? I tried here, but the value that comes back to me is 0.00 and not the measured resistance. Why? from mcculw import ul from mcculw.enums import ScanOptions, FunctionType, Status, ULRange, InfoType, BoardInfo, AiChanType from mcculw.ul import ULError from mcculw.device_info import DaqDeviceInfo board_num = 0 channel = 0 daq_dev_info = DaqDeviceInfo(board_num) ai_info = daq_dev_info.get_ai_info() ai_range = ai_info.supported_ranges[0] def get_ohm_value(): try: set_channel_settings(board_num) # Get a value from the device value = ul.a_in_32(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)) print(eng_units_value) except ULError as e: # Display the error print("A UL error occurred. Code: " + str(e.errorcode) + " Message: " + e.message) def set_channel_settings(board_num): channel = 0 # Set channel type to 10K 2W Resistance ul.set_config(InfoType.BOARDINFO, board_num, channel, BoardInfo.ADCHANTYPE, AiChanType.RESISTANCE_10K2W) get_ohm_value() Edited December 5, 2023 by BenjaminF Link to comment Share on other sites More sharing options...
0 Fausto Posted December 7, 2023 Share Posted December 7, 2023 Hello @BenjaminF. You need to use the a_in_scan() function, as I did in my previously attached example. You can customize the code for your own application. If you increase the sleep(), then you can slow the data display output. Regards, Fausto Link to comment Share on other sites More sharing options...
Question
BenjaminF
Hello,
I have downloaded all the required softwares to make the mcculw Python library to work.
Now i just need to read out the 10k 2w resistance value via channel 0 in Python.
How can this be done?
I get the value i want in InstaCal:
Br,
Benjamin
Edited by BenjaminFLink to comment
Share on other sites
7 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now