torfbolt / PyDAQFlex

Python implementation of Measurement Computing's DAQFlex command framework
15 stars 14 forks source link

Erro --> read_scan_data #12

Open joaojcsq opened 4 years ago

joaojcsq commented 4 years ago

Hi, thanks for the library. I have USB 204 and I'm a Python beginner. I'm trying to capture signals using a rasberry pi3 and USB 204. But when I write the code:

import daqflex
dev = daqflex.USB_204
dev.read_scan_data (512,1000,50000)

this error appears:

Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/home/pi/Desktop/Conversor/venv/lib/python3.7/site-packages/daqflex/devices.py", line 132, in read_scan_data
     timeout = int (self._bulk_packet_size * 1e3 / 2 / rate) + 10
AttributeError: 'int' object has no attribute '_bulk_packet_size'

Does anyone know what I can do?

ixjlyons commented 4 years ago

daqflex.USB_204 gives you the class USB_204. You want to create an instance of the class: dev = daqflex.USB_204().

By the way, read_scan_data should only take 2 arguments - you were likely seeing something like "takes 3 arguments (2 given)" because you were calling it like a static method (directly from the class rather than an instance of the class). self is the extra argument, referring to the the instance itself, which is passed implicitly for you when you call an instance method.

joaojcsq commented 4 years ago

@ixjlyons , thanks for your explanation! I moved forward with your answer. But I still can't read the data from the analog channel, can you help me?

I tried this code but the answer is: array ('H')

import daqflex
dev = daqflex.USB_204()

R = dev.read_scan_data(3000,500000)

with open('P','w') as f:
    f.write(str(R))
f.close()

I also tried to use these commands in another code:

import daqflex
dev = daqflex.USB_204()

print("####")

print(dev.send_message("AISCAN:RATE=500000"))
print(dev.send_message("AISCAN:SAMPLES=30000"))
print(dev.send_message("AISCAN:TRIG=ENABLE"))

print("####")

print(dev.send_message("?AI{0}:RANGE"))
print(dev.send_message("?AISCAN:RATE"))
print(dev.send_message("?AISCAN:SAMPLES"))
print(dev.send_message("?AISCAN:STATUS"))
print(dev.send_message("?AISCAN:TRIG"))

print("####")

dev.send_message("AISCAN:START")
print(dev.send_message("?AISCAN:STATUS"))
R = dev.send_message("?AI{0}:VALUE")

print("####")

dev.send_message("AISCAN:STOP")
print(dev.send_message("?AISCAN:STATUS"))

with open('P','w') as f:
    f.write(str(R))
f.close()

and the answer to that last code was:

####
AISCAN:RATE
AISCAN:SAMPLES
AISCAN:TRIG
####
AI{0}:RANGE=BIP10V
AISCAN:RATE=500000.000
AISCAN:SAMPLES=30000
AISCAN:STATUS=IDLE
AISCAN:TRIG=ENABLE
####
AISCAN:STATUS=RUNNING
####
AISCAN:STATUS=IDLE

and the "R" file was: AI {0}: VALUE = 0

ixjlyons commented 4 years ago

I'm not sure I can help much more since I don't have access to any hardware at the moment. It seems like you might want to replace the R = dev.send_message... in your second script with R = dev.read_scan_data... to get multiple samples. "?AI{0}:VALUE" would read a single analog input channel value if I remember correctly, which it looks like it's doing.

joaojcsq commented 4 years ago

@ixjlyons thanks for your tips. I did what you told me, but now I only get 2042 for the data. I'll keep trying, if I can, I'll come back here and leave feedback.

WhatsApp Image 2020-07-16 at 20 37 42