Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some issues with continuous.read #35

Open
piotx opened this issue Aug 21, 2016 · 4 comments
Open

some issues with continuous.read #35

piotx opened this issue Aug 21, 2016 · 4 comments

Comments

@piotx
Copy link

piotx commented Aug 21, 2016

thanks for sharing the api!

I would like to gather data for a longer period of time. I've played around with the continuous read script, and have some questions.

sample_rate_index = 0x1E
What does 0x1E stand for? I couldn't find it in the dictionary of SAMPLE_RATES in LubUsbScope.py; The oscilloscope gathers 12 Million data entries within one second, so I suppose that it's a sampling rate of 12 MS.

It doesn't seem to be possible to change the sample_rate, when using the read_async method. The data has always a length of 12288000 (within one sec), regardless of chosen sample rate and the data looks strange (gaps between measured samples). Is this a limitation, or am I not understanding something?

'Also the data_points doesn't seem to change anything. I'm a little bit confused about that.

It would be great, if you could clarify these points. thanks

piotr

@piotx piotx changed the title huge data size when using continuous.read some issues with continuous.read Aug 21, 2016
@jhoenicke
Copy link
Collaborator

jhoenicke commented Apr 16, 2017

sample_rate_index = 0x1E

0x1E is 30 in decimal and stands for 30 MHz. The modded firmware and custom firmware support some new sample rates. It is not supported by the stock firmware. The list of sample rates is: 10,20,50=100/200/500kHz, 1,2,4,8,12,16,24,30,48 = samplerate in MHz. 48 MHz doesn't really work, since USB 2.0 is too slow.

It doesn't seem to be possible to change the sample_rate, when using the read_async method. The data has always a length of 12288000 (within one sec), regardless of chosen sample rate and the data looks strange (gaps between measured samples). Is this a limitation, or am I not understanding something?

This is not what happens for me. Did you install the modded firmware, or the custom firmware? Also try a different USB port/hub. If you can only read up to 12 MB/s, there may be some other USB device on the same bus that needs some bandwidth. This also explains the gaps you see. I can sample up to 30 MB/s with very few gaps.

You can also choose 8MB/s by setting the sample_rate_index to 8.

@jhoenicke
Copy link
Collaborator

I finally got around playing with my Oscilloscope again. Please try this patch: jhoenicke@6dfbf52

  1. The sample rate 0x1e = 30 was too high for isochronous transfers.
  2. The firmware wasn't reflashed and this leads to the python library not supporting the single channel mode (maybe I can change the python library to autodetect single channel support). Single channel is important to get 24Msamples/s, and explains why you only got 12288000 samples/s (3072 bytes per 1/8 ms divided by number of channels).

@piotx
Copy link
Author

piotx commented Apr 25, 2017 via email

@holgerschillack
Copy link

holgerschillack commented May 22, 2017

Hey @jhoenicke, thank you for helping.
I'm a colleague of piotx and I've had the time to do some more testing on the oscilloscope.
When I tried to apply your patch, I got an error at line 69:

Traceback (most recent call last):
  File "example_linux_continous_read2.py", line 69, in <module>
    scaled_data = scope.scale_read_data(data, voltage_range)
  File "/usr/local/lib/python2.7/dist-packages/Python_Hantek_6022BE_Wrapper-0.0.2-py2.7.egg/PyHT6022/LibUsbScope.py", line 490, in scale_read_data
    return [(datum - 128)*scale_factor for datum in read_data]
TypeError: unsupported operand type(s) for -: 'str' and 'int'

I've also come to the conclusion, that the sample_rate or better the data-point-creation-rate is always 24*10⁶ data points per second.
When I change the sample rate to 0x14 (equals "200 KS/s") and record 2 seconds, I've got 48M datapoints. I've noticed, that in my case (Voltrage range -2.5V to +2.5V) the actual sample rate is 200kS, but there are added useless data points with value "-2.5".
So when I apply a work-around to delete these values, I'm left with a fine recording. The other problem is, that every second the deque is filled with 24 millions of points, so when I#m recording 10 seconds, 240 million datapoints need to be processed, although I just need e.g. with 200Ks only 400.000 data points.
So the limit on my computer is around 15 seconds - he needs like a minute to save the data. Any longer time period results in a program crash.
Generally I just want to record data for about 2 minutes with a sample rate of 200-500Ks for both channels simultaneously and write the values into a file. Plotting and calculating then is done with R.
Do you think, that would be possible?
I would be very glad, if you could take a look on that problem :)

And here my current code for deleting the useless values:

print '\n', "Points in buffer:", len(data), '\n'
scaled_data = scope.scale_read_data(data, voltage_range)

print("Deleting useless data points...")

scaled_data= [x for x in scaled_data if x != -2.5]

print '\n', "Real data:", len(scaled_data),'\n'

with open('/home/h/Downloads/Hantek6022API/examples/continuous_read2.out','wt') as ouf:
   ouf.write(str(scaled_data)[1:-1].replace(', ',chr(10)))

with open("continuous_read2.out","r") as f, open("outfile.txt","w") as outfile:
 for i in f.readlines():
       if not i.strip():
           continue
       if i:
           outfile.write(i)  

100.0*bad_pulse_count/len(stab)))
print("Finished! :)")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants