Jump to content
  • 0

MCC USB-1808x Analog input


darksied_9

Question

I have been working on the MCC USB-1808x and using the uldaq library with python as programming language, as mentioned we can get up to 200k samples/sec, I need 100k samples /sec and I am using example “a_in_scan.py” from the library and using differential mode and setting the “samples per second” and “rate” mentioned in the code and saving data in CSV file for now, but I am not getting the desired sample rate it is only saving 1000 samples/sec and even if I lower the “Samples per second” and “rate” to 100hz it is still storing data at 1000 samples/ sec.

What might be the issue.

Edited by darksied_9
Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

The a_in_scan.py example does not check to see if new data has arrived and if the sample rate is set lower, it can prints duplicate readings to the console. This is because it does not check transfer_status.current_index to see if more data arrived, and why you get 1000 S/s when rate=100. My recommendation is to write data in chunks. For instance, when current_index passes the buffer's midpoint, the lower buffer half is available to be written all at once. When current_index rolls over pass zero, the upper buffer half is available. Use a boolean flag that you set and clear so that the buffer halfs are written only once. Also, printing values to console will slow the operation so test with minimal console prints.

Link to comment
Share on other sites

  • 0

@JRys Now my data rate is set at 100k samples/sec, as I am storing this in my csv it is working fine for one channel as I try to increase the channel the data buffer size also increases and it is reducing the data write process. Every increase in channel delays the process for 4 channel if I run this for 10 sec there should be 1 million data points for each channel but I got only 600k each channel. 
How to resolve this. 

Edited by darksied_9
Link to comment
Share on other sites

  • 0

You could upgrade your computer to something really really fast, or take a different approach. The attached Python script records data to a binary file and after the data collection is finished, reopens the file for reading. Writing a binary file is much faster. So, I'm suggesting that you record to binary and after it is done, make the CSV when time is less critical. If you capture more than one million scans, you could make series of CSV files instead of one big one.

a_in_scan_file.py

Link to comment
Share on other sites

  • 0

I got a little carried away and enhanced the script I sent - attached. It will now do the conversion to csv after storing the data in a bin file. The first column is the scan number. If you multiply it by 1 / rate, you get elapsed time. Absolute time requires that you record the start time. Then during the conversion to csv, time = start_time + scan * 1 / rate. There's probably a little more to it than that because you're dealing with time, but you get the picture.

a_in_scan_file.py

Link to comment
Share on other sites

  • 0

@JRys I am using the MCC 1808x Daq on Raspberry pi for a while now and it was working fine, now it was disconnected for few days and now I am running the code it is throwing this error

"Active DAQ device: USB-1808X (0224DCFA)

Traceback (most recent call last):
  File "/home/pi/Downloads/uldaq-1.2.3/examples/a_in.py", line 146, in <module>
    main()
  File "/home/pi/Downloads/uldaq-1.2.3/examples/a_in.py", line 118, in main
    data = ai_device.a_in(channel, input_mode,
  File "/home/pi/.local/lib/python3.9/site-packages/uldaq/ai_device.py", line 87, in a_in
    raise ULException(err)
uldaq.ul_exception.ULException: ULError.DEV_NOT_CONNECTED: Device not connected or connection lost


------------------
(program exited with code: 1)
Press return to continue
"

 

It is reading the device and its configuration but when running the same code this error, what might be the issue, I have changed the cable, pi and power supply as well, it is working well on the Window DAQami software.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...