Hi everyone,
I have a U3 device and I would like to build Python code which reads AI for example based on event. If this is not possible, what is the best way to make a funcion for example which continuosly read the inputs?
Hi everyone,
I have a U3 device and I would like to build Python code which reads AI for example based on event. If this is not possible, what is the best way to make a funcion for example which continuosly read the inputs?
I am playing with the streamTest.py Python example and I think this is the best way to achieve something similar to an Event based call function. Is that true? Any documentation on this stream example?
Event based programming should not be dependent on any particular LabJack functionality, it is a Python program design consideration, and we do not have any examples showing event based programs. The following stackoverflow topic has a list of some event processing libraries you could use:
https://stackoverflow.com/questions/1092531/event-system-in-python
Command response communications using getAIN or the AIN feedback commands could be used in a callback function. The stream test example demonstrates how to continuously stream data:
https://github.com/labjack/LabJackPython/blob/master/src/u3.py#L585
https://labjack.com/support/datasheets/u3/operation
If you are trying to start acquisition based on a hardware trigger, the U3 does not have any hardware/firmware triggered acquisition mode. You would need to catch the trigger using a counter and watch for the trigger by using a polling loop that reads the counter in software. This would not be particularly quick, it would likely take at least 0.5ms to see the trigger and get back the first AIN reading due to communication overhead:
https://github.com/labjack/LabJackPython/blob/master/src/u3.py#L2780
Thanks for the answers, I will go over all the examples you shared. In the meantime I have another couple of questions which can be useful for everyone:
Thanks a lot
For your first question, are you trying to trigger based on some threshold voltage at the AIN? In that case, the fastest way to catch a trigger is to run a polling loop as fast as possible that only reads the AIN and breaks out to your function. The fastest way to read the AIN would be to use stream mode with samplesPerPacket set to 1. This would require that your loop can run as fast as the stream sample interval, or else you would get a backlog of stream samples and eventually overflow the stream buffer and error out.
The time between the trigger occurring and a software event would be limited (and controlled) by the USB communication overhead, which can vary. The following page was generated with a T-series device, but the USB times should be similar to what could be expected from a U3:
https://labjack.com/support/app-notes/maximum-command-response
I have attached my working example which calls a simple call back funtion when a voltage > X Volt is found. This script is just a continuation of the example I found in the library which uses the STREAM.