Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Changing LED BlinkMode

I'm using MS V7.1.
In order to maintain consistency with my various LEDs in my application, I've implemented a static function in a class the receives a reference to a  NationalInstruments.UI.WindowsForms.Led as a parameter, along with another enum object which indicates the led status (error, warn or OK). In this function, depending on the enum, I set the color of the LED to green, yellow or red. I set the blink mode to None when green, and to BlinkWhenOn for yellow or red.
The problem I'm seeing is that this works for the first call of the function, but not for subsequent calls. The color always changes with no problem, but once the blink mode is set from BlinkWhenOn to None and back to BlinkWhenOn again, the LED won't blink.
Any ideas on what the problem is?
Thanks in advance,
Dennis

 

0 Kudos
Message 1 of 8
(4,350 Views)
I wrote some quick code and it seems to work for me. Without seeing any of your code, I am wondering if you are also setting the value of the led. BlinkMode has values None, BlinkWhenON, BlinkWhenOff. BlinkWhenOn only works if the value of the led is true (the led blinks when the value is true). Likewise, BlinkWhenOff only works if the value of the led is false. So, if you are changing the led's value as well as the BlinkMode they could be out of sync.
0 Kudos
Message 2 of 8
(4,327 Views)

Thanks for taking the time to look at this.

Yes, the value is set to true. I also experimented with a variety of other things, including turning the value false then true, and trying the Update() member function. Still, no luck.

FYI: Here's the content of my static function:

public static void SetLED( NationalInstruments.UI.WindowsForms.Led led, eGENERALSTATUS eStatus )

{

switch( eStatus )

{

case eGENERALSTATUS.Good:

led.BlinkMode = NationalInstruments.UI.LedBlinkMode.None;

led.OnColor = Color.Lime;

break;

case eGENERALSTATUS.Warning:

led.BlinkMode = NationalInstruments.UI.LedBlinkMode.BlinkWhenOn;

led.BlinkInterval =

new TimeSpan( 0,0,0,250 );

led.OnColor = Color.Yellow;

break;

default:

led.BlinkMode = NationalInstruments.UI.LedBlinkMode.BlinkWhenOn;

led.BlinkInterval =

new TimeSpan( 0,0,0,250 );

led.OnColor = Color.OrangeRed;

break;

}

led.Update();

}

Best regards,

Dennis

0 Kudos
Message 3 of 8
(4,316 Views)
Ok the code:
led.BlinkInterval = new TimeSpan( 0,0,0,250 );
is actually setting the BlinkInterval to 250 seconds. It appears like it isn't working, but it is. You just have to wait 250 seconds (4.16 minutes) to see it blink. There are factory methods on TimeSpan that makes this easier because it is an easy mistake to make. Try using the methods TimeSpan.FromSeconds or TimeSpan.FromMilliseconds. The default BlinkInterval on the led is 800 milliseconds. You don't have to set it if this is reasonable for your application.
0 Kudos
Message 4 of 8
(4,310 Views)

Oops, a silly mistake!

It should have been this, to set a 250 ms blink rate.

led.BlinkInterval = new TimeSpan( 0,0,0,0,250 );

Thanks a lot for noticing the error!

Dennis

0 Kudos
Message 5 of 8
(4,304 Views)

Believe it or not, the problem still exists.

Here's a revised version of the code, with the TimeSpan construction fixed. As you can see, I also tried toggling the LED off and on at the end.

The color changes as expected, but the blink does not work.

public static void SetLED( NationalInstruments.UI.WindowsForms.Led led, eGENERALSTATUS eStatus )

{

switch( eStatus )

{

case eGENERALSTATUS.Good:

led.BlinkMode = NationalInstruments.UI.LedBlinkMode.None;

led.OnColor = Color.Lime;

break;

case eGENERALSTATUS.Warning:

led.BlinkMode = NationalInstruments.UI.LedBlinkMode.BlinkWhenOn;

led.BlinkInterval = new TimeSpan(0,0,0,0,250);

led.OnColor = Color.Yellow;

break;

default:

led.BlinkMode = NationalInstruments.UI.LedBlinkMode.BlinkWhenOn;

led.BlinkInterval = new TimeSpan(0,0,0,0,250);

led.OnColor = Color.OrangeRed;

break;

}

led.Value = false;

led.Value = true;

}

0 Kudos
Message 6 of 8
(4,295 Views)
Hi Dennis,
 
I created a brand new C# windows application, added your last set of code, made some slight modifications (like changing eStatus to a string for simplicity), and everything worked wonderfully.  My project has an LED and a Windows button, and the button click callback changes the LED value to true and then calls your static method.  I even took out the code that reset the value of the LED (to false and then back to true) and it still doesn't exhibit the incorrect behavior.  I've attached my project here, I'm not sure if you're running version 8.0 or not, so I'm not sure if you'll be able to open it.  Since the code is working great on this end, the only think I can think of is that your "Off" color could be similar or the same as your "On" color which wouldn't show the blinking correctly.  Let me know if you can get this project to work and any other things you may discover.  Thanks and have a good one.
0 Kudos
Message 7 of 8
(4,280 Views)

Hello Adam,

Thanks a lot for the help.

I'm using V7.1, and tried to use your project, but had a problem with the license file. It references V8.0 components.

I saw what you did, so I created my own simple app in V7.1, and the LED works just fine.

In my original application that exhibits the problem, the form that implements the static function is in a class library. Perhaps that has something to do with the problem I'm seeing.

Best regards,

Dennis

0 Kudos
Message 8 of 8
(4,272 Views)