LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Background colour is not updated

Hi. I have a curious problem that I do not understand, and perhaps someone could offer an answer.
I'm running some code to log data from an instrument, and when the instrument is not "connected", i.e. state == FALSE, I want to show this by setting a dark background ("BL_OFF") in 4 numeric displays. When it is "connected", i.e. state == TRUE, the background should change to a nice bright colour ("BL_ON").

This is the code that does that:

...
    if(state == TRUE) {
        SetCtrlAttribute (panel, HV_PANEL_VOLTAGE, ATTR_TEXT_BGCOLOR, BL_ON);      /* Numeric control */
        SetCtrlAttribute (panel, HV_PANEL_POWER, ATTR_TEXT_BGCOLOR, BL_ON);
        SetCtrlAttribute (panel, HV_PANEL_FILAMENT_CURRENT, ATTR_TEXT_BGCOLOR, BL_ON);
        SetCtrlAttribute (panel, HV_PANEL_BEAM_CURRENT, ATTR_TEXT_BGCOLOR, BL_ON);
        GetCtrlAttribute (panel, HV_PANEL_BEAM_CURRENT, ATTR_TEXT_BGCOLOR, &colour);
       
    }
    else {
        SetCtrlAttribute (panel, HV_PANEL_VOLTAGE, ATTR_TEXT_BGCOLOR, BL_OFF);
        SetCtrlAttribute (panel, HV_PANEL_POWER, ATTR_TEXT_BGCOLOR, BL_OFF);
        SetCtrlAttribute (panel, HV_PANEL_FILAMENT_CURRENT, ATTR_TEXT_BGCOLOR, BL_OFF);
        SetCtrlAttribute (panel, HV_PANEL_BEAM_CURRENT, ATTR_TEXT_BGCOLOR, BL_OFF);
        SetCtrlVal (panel, HV_PANEL_XRAY_ON_LED, OFF);                /* LED */
        SetCtrlVal (panel,  HV_PANEL_STAND_BY, OFF);                      /* LED */
        SetCtrlVal (panel,  HV_PANEL_INTERLOCK_OPEN, OFF);        /* LED */
        SetCtrlVal (panel,  HV_PANEL_INTERLOCK_CLOSED, OFF);   /* LED */
    }
...

Now to the funny business... If all is well when the program is started, it will run through the "state == TRUE" bit and set the colours to "BL_ON". I know this works as one panel is default set to "BL_OFF" in the .UIR file, but it is changed to "BL_ON" when the program executes. If I then force the program to go through the "else" bit, the colours change to "BL_OFF", as expected. Then when I send the program through the "state == TRUE" code again, one would expect that the colours would change to "BL_ON" (since it says so Smiley Tongue) as it did the first time... but not so! The colours remain dark ("BL_OFF") in the display. The really interesting bit is that the last command in the "state == TRUE" block reads the background colour, and it reads it as "BL_ON" and yet it displays "BL_OFF"! If I then force the program through the "state == TRUE" again, the colours will change as I would have expected them to do the first time through.

Any suggestions?

Cheers,
Mattias

Ps. using LabWindows\CVI 8.0.1


0 Kudos
Message 1 of 3
(2,886 Views)

Depending on the rest of your code, you might want to add a ProcessDrawEvents() call, to force any UIR changes made within a program loop (especially from using SetCtrlAttribute(), which has a deferred effect anyway) to actually appear on the screen. Having said that, I have in the past noticed odd things happening with regard to re-colouring screen areas of Windows programs, not just CVI ones. I would hazard a guess that Windows only performs this at a fairly low priority, so on occasion it appears that the expected colours take a bit of time to actually appear.

JR

0 Kudos
Message 2 of 3
(2,873 Views)
Thank you for that tip. I had been looking for some function to force a re-draw or update of the panel, but I didn't know of that one.
Thanks for the help!

Mattias
0 Kudos
Message 3 of 3
(2,850 Views)