03-04-2012 09:56 AM
I (will) have measurement applications that on changes sends a bitmap from its panel to a Network Variable.
I have a reader that connects to the network variable. It has a callback that fires on an update of the value or status. Because the size of the bitmap is variable, the callback retrieves the size of the bitmap, adapts the size of the panel and its single picture control, and copies the bitmap to the picture control.
It seems as if the callback runs in thread that is different from the main. The panel with picture control is build (using NewPanel) from the same update callback when its fired the first time. It is a toplevel panel with Windows minimize/maximize/close. A hidden control is used to attach a callback to the Windows close. The resize and display after and update of the network variable works fine. However I am not able to move the panel by picking it up with the mouse. (When retrieving in debug-mode the parameters, GetPanelAttribute reports that it is movable.) I am not able to close the panel with the Windows close.
I have not build extra features (such as handling Windows messages) for this panel. I need it only as indicator for displaying a bitmap.
What must I do to make it a movable and/or able to close ?
Solved! Go to Solution.
03-04-2012 03:10 PM
Depending on the way you connect to the network variable, the function is effectively called in a separate thread: this document examines all available methods to read from a NV and lists all characteristics fro each of them, includng thread execution.
To solve the problem you could modify your application so that the panel is created in the main thread or in an explicit therad that calls ProcessSystemEvents () so that user interaction is properly handled. The reader function could then retrieve informations from the NV, decode them and send all data to that thread via a thread safe queue or some other method.
03-04-2012 04:59 PM
Thanks Roberto for your efforts.
I have to read the document carefully. A quicklook (and my insight) is not sufficient for selecting the best approach.
From your proposed solution, I get the idea the moving the toplevel panel is only possible if its SystemEvents are processed. Something like its own 'RunUserInterface'. Maybe a single 'ProcessSystemEvents' in the network variable update callback is sufficient. Or a timer-control that executes ProcessSystemEvents with a few Hz. Soon I will give this a try.
Meanwhile, I have used a variation on your proposed solution. Because the data update is low (typical less than once per 5 seconds) I have inserted in the reader a PostDeferredCall in the network variable update callback. This deferred callback runs in the main thread.
In the deferred callback, I create the display panel and retrieve the newest data from the network variable engine. I am not sure yet which of the two functions is the better choice: CNVGetConnectionAttribute (nvhandle, CNVMostRecentDataAttribute, &nvdata) or CNVRead (nvhandle, 2000, &nvdata).
I just build a test where the publisher is a BufferedWriter and where I use CNVGetConnectionAttribute (nvhandle, CNVMostRecentDataAttribute, &nvdata) to retrieve data. I seems to work.
Of course I have to read in detail the document you referred to. And of course I do not know what will happen when I read the data much later, just when the writer sends a new update. But meanwhile, I have a working version.
Regards, Jos