08-20-2021 08:32 AM - edited 08-20-2021 08:41 AM
I have implemented a Test with CVI and through typing Data (like order data and article number).
I just have a problem with the Timer I added, which should check every 0.2 second if there is a Chip on an Antenna.
After typing the order data and clicking on a button "start order", the timer starts to detect if there is a chip:
if(event == EVENT_COMMIT)
{
switch(control)
{
case P_MAIN_START_ORDER: Order_Handling_Start_Order ();
if (cOrdnernumber != 0 && (strlen(cOrdnernumber ) == 8))
{
iTimer_Handle = NewAsyncTimer (0.2, -1, 1, CALLBACK_MAIN_Find_Chip, 0);
}
else
{
Main_ERROR(OrderNumtooshort, Error);
}
....
break;
The Timer starts the test which is in the funktion "CALLBACK_MAIN_Find_Chip".
As soon as the test ends, a button appears to confirm the result of the test.
This is when the following callback function compiles whats inside to empty the return to the default panel before the test. And the CALLBACK_MAIN_Find_Chip function should be executed again to start the detection, which does not and stays at the second function (Timer_CALLBACK_PSE) below:
int CVICALLBACK Main_CALLBACK_button_check (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
int iValue = 0;
char Artikel_Index_alt[20] = {0};
char Artikel_Index_neu[20] = {0};
int iRing_index;
if(event == EVENT_COMMIT)
{
switch(control)
{
case P_MAIN_CONFIRM_RESULT:
memset(cAnswer,0,sizeof(cAnswer));
memset(GET_UID,0,sizeof(GET_UID));
memset(GTIN,0,sizeof(GTIN));
GetCtrlIndex();
GetLabelFromIndex();
ResumeAsyncTimerCallbacks();
//iTimer_Handle = NewAsyncTimer (0.2, -1, 1, CALLBACK_MAIN_Find_Chip, 0);
break;
}
}
return 0;
}
int CVICALLBACK Timer_CALLBACK_PSE (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
int iValue = 0;
if(event == EVENT_TIMER_TICK)
{
GetCtrlAttribute (sPanels.P_Hauptmenue, P_MAIN_STOP_TEST, ATTR_CTRL_VAL, &iValue);
if(iValue == TRUE)
{
stop_the_test= TRUE;
SetCtrlAttribute (sPanels.P_Hauptmenue, P_MAIN_STOP_TEST, ATTR_DIMMED, TRUE);
SetCtrlAttribute (sPanels.P_Hauptmenue, P_MAIN_STOP_TEST, ATTR_CTRL_VAL, 0);
}
ProcessSystemEvents();
}
return 0;
}
Is there any way to let control when and when not should the callback of the chip detection run?
Thanks a lot for the help in advance.
Solved! Go to Solution.
08-23-2021 12:21 PM
Determining the program it's a programmer task: you are responsible for starting and stopping the timers and handling all the resources you need for your goal.
From your description and the code you published it's not clear how you designed the workflow: I see the timer created to test for chip presence, but I don't see when the timer is stopped (if it is) or suspended (if it's not, why resuming the timer events?).
The same for the second timer.
It' important to define the states when each timer must be running, suspended or discarded to avoid conflicts among them if they are running concurrently. And if the timers are expected to run concurrently at some moment you must be careful in handling shared resources in order to avoid possible conflicts, timeouts and so on.
Additionally, you must be sure that the timer callbacks take less than the timer interval to complete, otherwise there will be no room to handle other events, and this applies to both timer callbacks.