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
) 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