Jump to content

Sid_1

Members
  • Posts

    9
  • Joined

  • Last visited

Posts posted by Sid_1

  1. On 11/1/2022 at 12:22 AM, Jeffrey said:

    Threading is not recommended when using MCC devices

    Hi @Jeffrey thanks for your response. I observe that while using scanoptions.background in a Tkinter environment, the screens freezes during the background scan. Obviously I want to avoid such things which harm the user experience. I learnt that, the freezing is due to the fact that Tkinter GUI itself runs on a thread. So, when one runs some code on the same thread that Tkinter is on, then nothing else is going to perform until that section of code is done.

    So, it seems intuitive to run background scans in a separate thread.

    In fact, I have been able to solve the freezing problem in this manner.

    Do you still recommend not using threading with MCC devices ?

  2. Hi @Jeffrey

    Thanks for your response.

    2 hours ago, Jeffrey said:

    But why do you need "...to have a feature in my software which can show whether the connection to DAQ is alive or not."?

    I have one reason behind this: to let the user of my software know whether the DAQ is connected. So, it's just for information purposes. At an initial stage, I feel get_daq_device_inventory() can be used. But for prolonged usage I don't know what to use. I have a doubt regarding a_in(). The documentation says that a_in "The raw A/D value is converted to an A/D value and returned". So, how do I use a_in() to get return code ?

    2 hours ago, Jeffrey said:

    Have you seen instance(s) where the USB-231 drops off line?

    No, I have not seen anything of this sort. But very rarely I get the 'FIFO went empty...' error.

    2 hours ago, Jeffrey said:

    The USB-231 is capable of concurrent operations

    Can you please tell how to do this ? Is it using scanoptions.background ?

    2 hours ago, Jeffrey said:

    You don't need a separate thread

    Is it unsafe to launch multiple threads (for other use cases maybe)? I have observed that ul.a_in() stops when I run ul.a_out(). I think my previous question (concurrent operations) is related to this question.

  3. Hi there, I am using the Python library mcculw on a Windows 10 mcahine. I am using the USB 231 DAQ.

    I want to have a feature in my software which can show whether the connection to DAQ is alive or not.

    So, I thought of a polling method like this:

        def get_daq_status_str(self):
            '''
            Print status of daq every 1 second
            '''
            while True:
                status = ul.get_status(self.board_num)
                if status == Status.IDLE:
                    print('Status: Idle')
                elif status == Status.RUNNING:
                    print('Status: Running')
                else:
                    print('Status: Error')
                time.sleep(1)

    But from the docs I read that, all that ul.get_status() does is "Returns the status about the background operation currently running". So, I don't think it will work for my use case (since I am not transferring any data).

    So, what function can I use for this purpose?

    Apart from this, my application has to do usual a_out_scan() to send out voltages. So, as far as I can see, I must run this status check (polling method) in a separate thread, so that any other DAQ operation remains unaffected.

  4. Hi there, I am using the Python library mcculw on a Windows 10 mcahine. I am using the USB 231 DAQ.

    When I send voltages for the first time (using a_out_scan() method) everything works fine. When I send it for the second time, I get this error:

    daq_device_info.py, line 37, in __init__
        raise ULError(ErrorCode.BADBOARD)
    mcculw.ul.ULError: Error ErrorCode.BADBOARD: Invalid board number.

    Notes:

    1. I have stored the board number in a variable board_num=0. I am not changing it at all during program execution. So, I don't know how it changes and how I get the error.
    2. I initialize the device using the following code each time I try to send voltage. The following is an excerpt from my code:
      class DaqLogic:
          '''
          This class has various methods to interact with the DAQ
          '''
          def __init__(self):
              self.board_num = 0
              self.daq_info = DaqDeviceInfo(self.board_num)
              self.ao_info = self.daq_info.get_ao_info()
      
              #Useful constants for the DAQ
              self.low_chan = 0
              self.high_chan = 1
              self.num_chans = self.high_chan - self.low_chan + 1
              self.ao_range = ULRange.BIP10VOLTS
              self.use_device_detection = True
              self.dev_id_list = []
              self.calibrationFactor = 1
              self.lcdFreq = 200 # in Hz
      
          def configure_first_detected_device(self):
              '''
              Configures the first detected device. Ingores Instacl config.
              '''
              ul.ignore_instacal()
              devices = ul.get_daq_device_inventory(InterfaceType.ANY)
              if not devices:
                  raise Exception('Error: No DAQ devices found')
      
              print('Found', len(devices), 'DAQ device(s):')
              for device in devices:
                  print('  ', device.product_name, ' (', device.unique_id, ') - ',
                      'Device ID = ', device.product_id, sep='')
      
              # Add the first DAQ device to the UL with the specified board number
              ul.create_daq_device(self.board_num, devices[0])
      
          def intialize_daq(self):
              '''
              Initializes the DAQ
              '''
              try:
                  self.configure_first_detected_device()
                  daq_dev_info = DaqDeviceInfo(self.board_num)
                  if not daq_dev_info.supports_analog_output:
                      raise Exception('Error: The DAQ device does not support '
                                      'analog output')
              except ULError as e:
                  # Todo: Create alert window
                  print("Error: ", e)

       

    Is it that I should not initialize the device each time I wish to send voltage ?
    I guess, I must initialize only once and then store some reference to the device for further use, like sending voltages for 2nd time.

  5. Hi JRys. Thanks for the solution. I really appreciate that.

    The rate parameter seems to be not working in your program.

    For example, this is what I had in my previous program:

    Let's say rate = 200, points_per_channel = 2000. Then the scan used to get over in 10 seconds.

    But in your program, the scan doesn't seem to end. I have to end it manually using Ctrl+C.

  6. ⚙️ Hardware details

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

    💻 Software details

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

    🤔 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 ?

    Voltages appear in each channel, but the voltage sign is not consistent. So, if my array contains 1V, I can see only +1V and I can't see -1V at all. I have done the interleaving of voltages to output each array for the corresponding channel. So, the final interleaved array has +1V and -1V repeated 200 times. But the -1V is not outputted by the DAQ at all. 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. Using ul.a_out_scan is a better way to generate precise signals than using the ul.a_out along with something like Python's time.sleep() 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.

×
×
  • Create New...