Forum Index > Comm64 and async / await

By: Guest Posted on: Dec 13 2012 at 02:36:31 AM

Just some information that may be of use!
I've been developing communications to an instrument using Comm64 (it handles all required comms like a dream!). Anyway, I have used the non-event methods because MOST operations are short lived bursts of back and forth comms.
However, I did need to be able to update information on the screen as individual comms processes completed. Obviously, this did not work as the comms processes held on to the thread.

BUT: In VS2012/C#5/.NET 4.5 the async / await commands (coupled with tasks) provide a fairly elegant and quickly implemented solution. I now have screen status updates firing exactly when needed.

If anyone is interested please comment to this and I'll supply an example of the code.

By: Guest2 Posted on: Dec 13 2012 at 03:05:28 AM
I don't know 'exactly' what you're doing but it sounds a little like the problem I was faced with although I chose the Comm64 component for an entirely different reason.

In the 'old days' of VB3 I'd simply output some data and then go into a loop waiting for a reply. Only a couple of ms so it didn't seem so bad. If there was a lot of chatter back and forth then, as you say, the display couldn't be updated. But calling DoEvents fixed that. I really can't recommend using DoEvents but if you're codeing the 'old way' then calling Application.DoEvents after sending data to the display would allow the display to update.

But really, we ought to be using the OnComm event. Even if the reply is expected very quickly I still prefer to handle the receive event in the OnComm event. Doing it like that just allows the display and UI to remain responsive.

But if you really want to do it in a non-event-driven way then just write your own thread. I suppose that's what your Async/Wait is doing (I never looked at 4.5) but threads are very easy in all versions of the .net framework.

By the way, my main reason for using Comm64 rather than .Net's built-in serialport component:- The .Net SerialPort component receive and line status change events occur on the comms thread so can't update the UI unless you use Invoke you own events. But the Comm64 comms events occur on the UI thread so can directly write to the UI so no need for any Invoking.


Reply - add comment to this topic
You may enter letters, numbers and standard punctuation only. HTML and other scripts/tags will be rejected
  Topic:- Comm64 and async / await

Your Name


Forum scripts and databases - Copyright (c) 2009 - 2012