Clearing values in widget

Hello all!

Currently I am doing a program which constantly reads and displays values captured by a device, which is connected thru the serial port. The values are displayed in my 3 text widgets(base_text1, base_text2, base_text3). I want to clear the contents in the 3 text widgets when a button is pressed. So I created a button and attached a callback called “reset” to it. Do I use the command PtFlush to clear the contents in my 3 text widgets? If so how do I use it? Attached is my callback function.

Thanks in advance!

int reset (PtWidget_t *widget, Apinfo_t *apinfo, PtCallbackInfo_t *cbinfo)
{
PtFlush();

//eliminate unreferenced warnings
widget=widget, apinfo=apinfo, cbinfo=cbinfo;

return (Pt_CONTINUE);
}

I believe that you just need something like this:

#define EMPTY_TEXT “”

int reset (PtWidget_t *widget, Apinfo_t *apinfo, PtCallbackInfo_t *cbinfo)
{
PtSetResource(base_text1, Pt_ARG_TEXT_STRING, EMPTY_TEXT, 0);
PtSetResource(base_text2, Pt_ARG_TEXT_STRING, EMPTY_TEXT, 0);
PtSetResource(base_text3, Pt_ARG_TEXT_STRING, EMPTY_TEXT, 0);
return Pt_CONTINUE;
}

Function PtFlush() do not provide that functionality.

Hello, Mezek!

The code you provided me, didn’t really work. When the reset button is pressed, the values in the text widgets flashed 0.0(empty_text was set as 0.0) and immediately restored back to the value they were previously displaying. What I intend to do is that the values 0.0 are permanently displayed on the text widget. Only when another start button is pressed then will the serial port open and continue to read and display the values.

I tried another way which was to close the comm port and then display 0.0 which didn’t work. What is wrong with it? Could anyone help?

#define EMPTY_TEXT “0.0”
int reset (PtWidget_t *widget, Apinfo_t *apinfo, PtCallbackInfo_t *cbinfo)
{
int iFileDescriptor;
close(iFileDescriptor);
PtSetResource(ABW_base_text1, Pt_ARG_TEXT_STRING, EMPTY_TEXT, 0);
PtSetResource(ABW_base_text2, Pt_ARG_TEXT_STRING, EMPTY_TEXT, 0);
PtSetResource(ABW_base_text3, Pt_ARG_TEXT_STRING, EMPTY_TEXT, 0);

//eliminate unreferenced warnings
widget=widget, apinfo=apinfo, cbinfo=cbinfo;

return (Pt_CONTINUE);
}

Ok. Then you need to change your display(), reset() and continue() functions to use a variable which control display.

eg:

int paused = 0;

void display ()
{
if (paused == 0)
{
// set values in text boxes
}
}

int reset (PtWidget_t *, Apinfo_t *, PtCallbackInfo_t *)
{
paused = 1;
PtSetResource(ABW_base_text1, Pt_ARG_TEXT_STRING, EMPTY_TEXT, 0);
return Pt_CONTINUE;
}

int continue (PtWidget_t *, Apinfo_t *, PtCallbackInfo_t *)
{
paused = 0;
return Pt_CONTINUE;
}