I have a supplemental question to a question I asked earlier, which you can refer to if necessary:
Long term instrument data acquisition with Python – Using "While" loops and threaded processes
I’ve gone through a bunch of SO questions and other reading, and came up with a block of code that works fine, though it is very rudimentary:
import ue9
import LJ_Util
import DAQ_Util
import threading
import Queue
queue = Queue.Queue()
def ljThread(ue9ipAddr):
print '\nExecuting in ljThread...'
a = ue9.UE9(ethernet=True, ipAddress=ue9ipAddr)
reading = a.feedback()
queue.put(reading)
print "Opening device...\n",
# Opens a UE9 at IP Address 192.168.1.127
ipAdd = '192.168.1.127'
feedbackThread = threading.Thread(target=ljThread, args=(ipAdd,))
feedbackThread.start()
outcome = queue.get()
print outcome
print "\nDone"
My question is, I want to use individual threads to access information from different instances of the object ue9.UE9, which is tied to a data acquisition unit. I anticpate each unit will return different data, but I need to associate the right data with the right unit. Can anyone point me to the right way to track back sources through the queue object being used to pass data back to the calling thread?
Thanks, folks, in advance, for any help!
It should be pretty easy to modify your
ljThreadfunction to return identifying information (such as the IP address it was checking) along with the data it reads. Just replace the last line with:Then when you grab the results from the queue, do:
You can then use the IP to do whatever you need to do.