LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I do that a Leds of a UIR is Blinking all the time

Hello

 

I have  a question of CVI, I am modify a UIR and I am add a LEDs in my UIR, I nedded do that these Leds is blinking all the time, but I am having problem for do this.

 

I know that exist 2 functions in CVI SetCtrlVal and GetCtrlVal for Set and Get the state of the Led, but in my code I am try of use these functions for the Led and this Is not blinking. Only change of color one time not more.

 

Do you know what is the form or the method for does this ??

0 Kudos
Message 1 of 4
(4,416 Views)

SetCtrlVal is not processed all the time: if you are in a tight loop that is not processing any event you won't see the control updated. If this is your case, you may want to add a simple ProcessDrawEvent inside the loop to permit updating the control values and so have the blinking effect operate correctly.

 

Even in this case, tough, there may be conditions in which the led cannot be updated, for example while a single read from the serial port is processing a long read with timeout: while the system waits inside ComRd it is not processing events at all and you want see the led blinking. In this and similar cases you can transform the single ComRd instruction in a loop that processes GetInQLen and executes a single ComRd only when all expected characters are in the queue (you'll have to implement the timeout yourself inside that loop, though, since the system cannot handle it by itself in this structure).  Serial communications is taken here only as an example: there may be several other cases of instructions tied into a long timeout.



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 2 of 4
(4,404 Views)

The simplest approach is to have a Timer Control on the UIR, set to trigger at a rate to suit the LED blink rate and attached to a callback funtion. Within that function, code similar to the following will make the LED blink:

 

    case EVENT_TIMER_TICK:

        GetCtrlVal (panelHandle, PANEL_LED1, &state);   // Is the LED on or off?

        state ^= 1;                                     // Change to the opposite state

        SetCtrlVal (panelHandle, PANEL_LED1, state);    // Set the new state

        break;

 

As Roberto says, it is possible that other parts of your program may have an effect on this Timer callback operation. If so, you might want to consider using Asynchronous Timers instead - these operate in their own thread which should not be affected by a busy CVI program. Another trick which you can use sometimes is to call ProcessDrawEvents() to ensure that the screen is updated after you make any changes to the appearance of any controls - normally this should not be necessary but it depends on the structure of your program.

 

JR

Message 3 of 4
(4,391 Views)

 Roberto, Jr2005

 

I have made the changes necesary in the code and the IUR is now working with the Led's. I add a timer in the program for control these.

 

 

Thanks so much for your help.

 

 

0 Kudos
Message 4 of 4
(4,369 Views)