LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

programmatically suspending command button?

Solved!
Go to solution

Hello smartprogrammer,

forgive me for answering with another question: how long does your control callback takes to complete?

Your question makes me think you have a long function that takes dozens of seconds to complete, so in the meanwhile you want to block user interaction on your panel. If this is the case, I strongly urge you to modify you program so that the long function is not executed inside the control callback.

 

You could for example rewrite your code this way:

  • Operator clicks on a button to start the function
  • Inside the button callback you dim all other controls and then PostDeferredCall the long function
  • At function completion you reactivate UI controls
  • Don't forget to call ProcessSystemEvents () periodically in the long function to permit handling events for controls remaine active (e.g. an 'abort' button)

An alternative is to rewrite the function so it can be executed inside a timer control or an asynchronous timer.

 

 

If on the contrary you are not in this situation, you can experiment by using ProcessSystemEvents ( ProcessDrawEvents inside the button callback, as you can see in this discussion. Be careful when using this command: *all* UI events are processed with these commands so you may find yourself in a unwanted situation if the user has clicked somewhere before you process events.



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 11 of 17
(2,087 Views)

Here is what I am doing now (no child panel requirement any more)

errChk (panelHandle =     LoadPanel (0, "workstation.uir", PANEL));

errChk (panelHandle_pass = LoadPanel (0, " workstation.uir", PANEL_pass));

   errChk (popup1 = LoadPanel (0, " workstation.uir", pop1));                    

   errChk (popup2 = LoadPanel (0, " workstation.uir", pop2));  

 

NOW the screen displayed below is my popup1 screen with 5 command buttons

untitled.JPG 

 

I press one command button which will send command on COM port and wait for response command; I want that when I press one command button then all the 5 buttons on the screen get suspended (dimmed or disabled) and when all the tasks assigned to one command button are over then all the five buttons are enabled again so that new commands can be send please suggest me better way to do so, I have disabled buttons using

SetInputMode (popup1, pop1_CodeInfo, 0);

And

SetCtrlAttribute (popup1, pop1_CodeInfo, ATTR_DIMMED, 1);  

Both are equally good but the issue is that when I use these commands then buttons are disabling after completion of task on function exit not on the entry, due to which while actions to be performed by command button are first executed then buttons are disabled afterwards.

Here I am attaching my code Specially for respected Friend Roberto Bozollo for modification and better program flow.

here is code under one of my command button similiarly i am doing for other command buttons.

 

int CVICALLBACK func_LinkEstablishment (int panel, int control, int event,

                                void *callbackData, int eventData1, int eventData2)

{

if (event == EVENT_COMMIT)

{              switch (event)

                {     case EVENT_COMMIT:

                                if ((SetInputMode (panelHandle, -1, 1) ) >=0) //deactivating all panel

                                                {              if (SendCommandFrame(0x1F) == 1) // function sends data to COM port              

                                                                                                                          //if successful then returns 1

                                                {

SetCtrlVal (panelHandle,PANEL_event_display ,"\n\n(C) Link Establishment Command Successful ");

                                                for (int retry=0 ; retry<3 ; retry ++ ) // retry three times at same port for reply

                                                                {

                                if(ReceiveCommandFrame(0x1F)==1)   // function that receives data at same com port

                                                                               {

SetCtrlVal (panelHandle,PANEL_event_display ,"\n\n(CR) Link Establishment Successful ");

                                                                               break; // if success then breaks

                                                                               }

                                                                                else

                                                                                {

SetCtrlVal (panelHandle,PANEL_event_display ,"\n\n(CR) Link Establishment Unsuccessful %d ");

                                                                                }

                                                                Delay(1);

                                                                }

                                                SetInputMode (panelHandle, -1, 0);   //Activate panel Command Buttons at end             

                                                }

                                                else

                                                {

SetCtrlVal (panelHandle,PANEL_event_display ,"\n\n(C) Link Establishment Command Unsuccessful ");

                                                }

                                }

                                                break;

                }

}             

                return 0;

}

0 Kudos
Message 12 of 17
(2,075 Views)

Hi smartprogrammer,

to disable controls at the beginning of the function you must pass 0 as the last parameter in Setinputmode; 1 to enable at function end. You are making the opposite.

 

Besides that, there are several redundancies in the code, which could be simplified. As an example, rhe switch (event) is useless since you already tested event ==EVENT_COMMIT.



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 13 of 17
(2,049 Views)

very true that i dont need to use switch and now i will not use swith,  well Sir  my real question is still not answered as it was my code printing mistake, obviously i will use 0 insted of 1 as if u check recall function paned then rather than 0 or 1 it gives option of diable or enable so please answer my real question. well as i have explained before i have used both setctrlattribute and setinput mode to deactivate all buttons and during  which fuctions assigned to specific button are bieng executed so kindly check why buttons are disabled after the functions to be performed are done although setinput mode or setctrlattribute are initiated first in the function ,kindly replay will wait for your detailed reply

0 Kudos
Message 14 of 17
(2,027 Views)

Well, calling ProcessDrawEvents as suggested earlier by wolfgang should be enough for your needs.

 

See the attached example and experiment with available options. See also the help for ProcessEvents functions to understand the difference between them.

Consider also that there is a difference between disabling all controls individually as I do and disabling with control ID = -1 as you do: you may choose the option that you like most.



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 15 of 17
(2,006 Views)

dear roberto, i ma new in labwindows... i will change the button background color, but it doesnt support, therfore i will change the text of the button during running the program. i have made a ring to choose which color, but it doesnt happan any change???!!! i have used:

GetCtrlVal (panelHandle, PANEL_RING, &color);
SetCtrlAttribute (panelHandle, PANEL_COMMANDBUTTON, ATTR_LABEL_COLOR, color);

the color has integer values from 0-18 for VAL_RED until VAL_LT_GRAY. when i choose a color and press the button, nothing is changed???!!! can yo help me out? thanks

my email is orbit@live.se and i havent been succeed to put my question personaly in the forum?!

appreciate your answer. thanks

0 Kudos
Message 16 of 17
(1,329 Views)

Hi venusnajad56,

 

I would recommend posting on a new forum so that more people see your post. It's unlikely anyone will see this since the last post here was three years ago.

 

Regards,

 

B. Poteet

0 Kudos
Message 17 of 17
(1,318 Views)