08-12-2008 06:01 AM
08-14-2008 08:56 AM
08-14-2008 09:13 AM
Hello CAS,
I would think that the DAQmx read function is architectured in a way that it will just send data to the user interface once it has enough or that the user interface is requesting the data to display when it needs to. With the callback this would be possible using event-based architecture.
In regards to your error though, could you give me a little bit more information on what exactly you are seeing? It might be that as you are expecting to trigger the reading of your data after the acquisition is over, your code is completely missing the trigger itself. If you want to be able to start the reading of the data in such a way, you might actually have to explicitly start this task before the end of the acquisition. This is because the call to BeginRead* function starts a new thread to retrieve the data asynchronously, and because of this there is a race condition between the two tasks as to which one will be started first--the operating system can schedule threads in any order. So, if you can start the read task and then just call it, you might be able to acheive what you set out to initially.
I hope this helps in a way,
Please do let me know how you get on,
Kind Regards,
Michael S.
Applications Engineer
NI UK & Ireland
08-14-2008 09:17 AM
CAS!
It seems we pretty much replied at the same time!
I am glad you found this information, and I was going to mention in my reply how this would go in a single thread but forgot!
In any case, still let me know if there is anything else I might be able to help with.
Kind Regards,
Michael S.
Applications Engineer
NI UK & Ireland
08-14-2008 09:39 AM
Hi Michael
Thanks for your reply. I am all sorted now. I understood why the callback from my serial reader threw an error when trying to update the UI - this is because my callback was operating on the thread performing my read serial operation rather than on the UI thread itself. I also know how to get around that with a couple of extra lines of code.
What I couldn't understand was how the DAQmx callback got around this so neatly but now I know that it's because it's using the SynchronizationContext class to post the callback to occur back on the original thread on which the UI is running. I think that, with a bit more research, I could work out how to use this myself and implement it in my asynchronous serial reader.
They're pretty involved these threads aren't they?!
Thanks again.
CAS