LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Animate control can not play in a callback function

Hello,

 

I'v programmed a code:

 

static int panelHandle;
static int flag = 0;
static int picID;  
int CVICALLBACK ProcAnimate (int panelHandle, int controlID, int event, void *callbackData, int eventData1, int eventData2);

int main (int argc, char *argv[])
{
    
    
    if (InitCVIRTE (0, argv, 0) == 0)
        return -1;    /* out of memory */
    if ((panelHandle = LoadPanel (0, "testanimate.uir", PANEL)) < 0)
        return -1;
    
    
    picID = AnimateCtrl_ConvertFromPictRing(panelHandle, PANEL_PICTURERING);
    InstallCtrlCallback(panelHandle, PANEL_PICTURERING, ProcAnimate, NULL);
    
    DisplayPanel (panelHandle);
    RunUserInterface ();
    DiscardPanel (panelHandle);
    return 0;
}

int CVICALLBACK ProcAnimate (int panelHandle, int controlID, int event,

                                                 void *callbackData, int eventData1, int eventData2)
{
    int res ;
    
    
    if (event == EVENT_LEFT_DOUBLE_CLICK)
    {
        if (flag == 0)
        {
            res = AnimateCtrl_SetAttribute(panelHandle, picID, ATTR_ANIMATE_FRAME_INTERVAL, 0.4);
            res = AnimateCtrl_SetAttribute (panelHandle, picID, ATTR_ANIMATE_ENABLED, 1);
            flag = 1;
        }
        else
        {
            AnimateCtrl_SetAttribute (panelHandle, picID, ATTR_ANIMATE_ENABLED, 0);    
            flag = 0;
        }
    }
    
    return 0;
}

 

Hope double clicked the picture ring it can play animation. but I found that  the variable res got an error (-45). What is wrong?

 

David

0 Kudos
Message 1 of 7
(3,969 Views)

I've make some test, I find that once install a callback function for an animate control, it will never play animation.

0 Kudos
Message 2 of 7
(3,956 Views)

Hello David,

Ive rarely used the animation control but error -45 means "The control type passed is not a valid type", so I suppose you need to check the control ID you are passing to the function and check also that AnimateCtrl_ConvertFromPictRing returns a valid value.

 

Additionally, the help for the instrument specifically states that the animation control can have a callback, which in case receives two additional events. This should mean that you can obtain a behaviour like the one you want. I would suggest two tests:

 

1, Try not to install the callback to the control and see if the animation control works as expected

2. Try installing the callback in the UIR editor instead of programmatically

 

Later in the office I will make some test and add some more ints if I note something about this matter.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 7
(3,942 Views)

Ok, I tested with the sample located in samples\userint\custctrl\animate\animsample.cws and was able to modify it to start with a double click and stop with a single click. The control callback correctly receives and interpret the events.

I suggest you to take a look at the sample and try elaborating on it (hint: the rocket control if located to the right of the canvas; widen the panel to see it)



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 7
(3,938 Views)

Hello Roberto,

 

The attachment is a simple code I've coded. I just want to do such a thing: once double click the picture ring, it can play animation. But whatever doing something, it always say the control type is error.

 

David

 

 

 

 

 

 

0 Kudos
Message 5 of 7
(3,932 Views)

Attached your project modified and working. The solution is to set control callback in the editori instead of using InstallCtrlCallback (it is basically one of the suggestions I already gave to you: you could have tried it and solution your problem earlier Smiley Wink )

Alternatively, if you want/need to dynamically install the callback, set it before creating the animation control and the system will still be working.

 

When dealing with custom controls, you must understand that almost all of them use a special callback to accomplish control function. That callback is chained to a control callbak that eventually exists, and must not be modified afterwards, otherwise control behaviour will be affected (cancelled like in your case, you could also get GPFs or other errors for more complex controls). I have it as a general rule for myself: when I need to set some attribute for controls used to generate custom controls, I set it before passing the control to instrument functions.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 6 of 7
(3,929 Views)

Hi Roberto,

Thank you very much for your reply.

 

David

 

 

0 Kudos
Message 7 of 7
(3,915 Views)