How to refresh the GUI automatically periodic?

Hi all,

I´m working with the IDE 6.3 and have problems with a Photon Appbuilder Project.
I have two computers and the one sends (sender) new data to the other (receiver) in a periodic intervall (all 250 ms) via CAN.
There is a thread on the sender sending the data (simple integer-number) and one on the receiver receiving the data. The receiving thread stores the data in a global variable. Both threads are started with the application and run forever, so the receiver has all 250 ms a new value.
So far it works and i´m able to refresh the GUI when i press a button, and start a callback, where i set the last received value (the global Variable) with PtSetResource().

But now i want the GUI to refresh automatically, lets say every second, without pressing the button.

I tried few things, but didn´t find a solution.
When i tried to refresh the GUI from within a thread, the application crashed.
Next shot was, to start a loop in a callback, that runs forever and refreshes the GUI.
for(;:wink:
{
delay (1000);
PtSetResource();
}
The GUI refreshed, but also it was blocked after starting the callback and i wasn´t able to press any other button, so this solution is bad, too.

Did i make some mistake in my trials? Should one of them work?
if not, has anyone any other ideas how to solve this problem?

Thanks

I solved the problem with a timer.

Thanks a lot to Peng.

Greets

I’ll add my reply here so that anyone who find this thread later doesn’t have to PM me ;-)


Hello,

unfortunately I don’t have access anymore to the QNX machine so I don’t know if I can help you a lot.
Here is some code involving a timer:

Code:
int
collect_frames( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )

{

[…]
long flags;

/* eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

[…]
flags = PtWidgetFlags(widget); // verifying a checkbox to see wether we want the timer on or off

if (flags & Pt_SET) // we want the timer on
{
[…]
PtSetResource(ABW_2D_view_timer, Pt_ARG_TIMER_INITIAL, 200, 0); // this is setting the timer to happen every 200ms.
}
else
{
[…]
PtSetResource(ABW_2D_view_timer, Pt_ARG_TIMER_INITIAL, 0, 0); // this disables the timer.
[…]
}
return( Pt_CONTINUE );
}

The timer itself would trigger a function such as this one:

Code:
int update_2d_view(PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo)
{
PtDamageWidget(ABW_PtGraphic1);
PtDamageWidget(ABW_PtGraphic2);
return(Pt_CONTINUE);
}

Once the display widgets are damaged (those are Raw widgets), they will automatically redraw using their specified drawing function.

I hope that it will help you Wink

How to specify the drawing function? Thanks a lot.

See the Raw Drawing and Animation chapter of the Photon Programmer’s Guide. It has a section on using PtRaw widgets.