12-22-2009 12:21 AM
basically i have this switch matrix that have five modes. I set up the logic to where if i hit the on and off control button, a led will light up green.
is there a way you can check the values of the led control or the on and off switch control to determine if the controls are on and off or the Led is at the initial stage or if its green?
because i want to set up some logic for each case.
example
if( LED == green)
{
blahhhhhh
}
if ( LED== RED)
{
blahhhh
}
the same goes for the on and off control.
I just need to is there a way you can check the in the controls are on and off.
12-22-2009 12:25 AM
Speaking about UI controls, a LED can be turned on and off with SetCtrlVal; its state can be read back with GetCtrlVal.
The same applies to toggle controls (button, switches and so on).
12-22-2009 01:57 AM
Im going to send you my c file, so you can see what im doing.
GetCtrlVal(g_panelHandle, PANEL_Erp_Pm_MODE, &g_retainSwitch4Value);
because how i got the logic set up, its the GetCtrlVal is going to always going to be 0.
to explain whats going on, basically i want to be able to turn PANEL_Amplifier_MODE off and on at any given time.
if the mode is off im going to give the g_Switch4Value =0
if the mode is off i give g_Switch4Value = 3
, I can do it with Prompt popup, but i dont wont to take that route.
case PANEL_Amplifier_MODE://Toggle Switch3->Bit 1
SetCtrlAttribute (g_panelHandle,PANEL_Erp_Pm_MODE,ATTR_VISIBLE,1);
SetCtrlAttribute (g_panelHandle,PANEL_LED_8,ATTR_ON_COLOR, 0);
SetCtrlVal(g_panelHandle, PANEL_Amplifier_MODE,1);
SetCtrlVal(g_panelHandle, PANEL_Erp_Pm_MODE, 0);
SetCtrlVal(g_panelHandle, PANEL_Spec_An_MODE,0);
SetCtrlVal(g_panelHandle, PANEL_Signal_Gen_MODE,0);
SetCtrlVal(g_panelHandle, PANEL_Awg_Mixed_MODE,0);
SetCtrlVal(g_panelHandle, PANEL_O_Scope_MODE,0);
SetCtrlVal(g_panelHandle, PANEL_Repeater_MODE,0);
SetCtrlVal(g_panelHandle, PANEL_Attenuator_MODE,0);
SetCtrlVal(g_panelHandle, PANEL_LED_8, 0);
SetCtrlVal(g_panelHandle,PANEL_LED,0);
SetCtrlVal(g_panelHandle,PANEL_LED_2,0);
SetCtrlVal(g_panelHandle,PANEL_LED_3,0);
SetCtrlVal(g_panelHandle,PANEL_LED_4,0);
SetCtrlVal(g_panelHandle,PANEL_LED_5,0);
SetCtrlVal(g_panelHandle,PANEL_LED_6,0);
SetCtrlVal(g_panelHandle,PANEL_LED_7,0);
SetCtrlVal(g_panelHandle,PANEL_LED_8,0);
g_commandAddr =atoi(g_sInstrData[DEVICE_ADDR2]);//range 1-3
//Promt the user to enter an event character.
PromptPopup ("Ampliflier Mode", "Enter Your Selection:\n\n1 - ON,\n\n 0 - OFF", sAmpMode, 1);
g_AmpMode=atoi(sAmpMode);
if(g_AmpMode==1)
{
Bit2Toggle=BIT1;
Position1=Bit2Toggle;
g_retainSwitch4Value=1;
g_dSwitch4Value=Position1;
g_retainAmpliflierValue=Position1;
}
else if(g_AmpMode==0)
{
Bit2Toggle=BIT0;
Position1=Bit2Toggle;
g_dSwitch4Value=Position1;
g_retainAmpliflierValue=Position1;
}
//Safefty check on define macro,setting the limits to make sure the correct
//bit position to toggle are between the range 0-4
if((Bit2Toggle<0)||(Bit2Toggle>1))
{
MessagePopup("Warning! SWITCH 4 ERROR:",switch4ErrorMsg);
return FAILURE;
}
//Position1 = g_dSwitch4Value;
if(g_dSwitch4Value==0)
{
Position1=TURN_BIT_OFF;
g_dSwitch4Value=Position1;
g_retainAmpliflierValue=Position1;
}
else if(g_dSwitch4Value==1)
{
Position1=(TURN_BITS_1AND2_ON);
g_dSwitch4Value=Position1;
g_retainAmpliflierValue=Position1;
}
else
{
MessagePopup("Warning! SWITCH 4 ERROR:",switch4ErrorMsg);
return FAILURE;
}
message = g_dSwitch5Value;
message <<=2;
message |= g_dSwitch4Value;
message <<=4;
message |= g_dSwitch3Value;
statusReturn=Control_Bus_Message (g_actualPort,COMMAND_CODE,
g_commandAddr,message);
12-22-2009 02:13 AM
I notice using GetCtrlVAl if when i hit the the Ampliflier mode , the value is going to be 1.
so how to fix the logic to where in if the mode is already on, i want to turn it off, and if its off i can turn it on.
how can i set that logic up.
12-22-2009 02:32 AM
darnell,
Pasting an entire code is not always the best way to help us feel what you are trying to do, especially with such uncommented, inconsistent coding style.
If your question is simple (and it looks so), ask the question in a simple way?
Reading your code makes things harder.
If you are trying to turn on/off a led connected to a switch, it is easy:
GetCtrlVal (panel, switch, &state); //state is defined as integer
SetCtrlVal (panel, led, state);
If that amplifier mode is controlled by a switch on the UI, it already toggles each time you click on it.
All you need is just to get the new value.
12-22-2009 03:32 AM
As ebalci already said, it is difficult for us to understand a rather complex and unknown code, so I'll try to give you some hint.
When you press a toggle button, its value goes to 1 and the corresponding callback (if any) is called. No need to set its value here. When you programmatically set a toggle button to 1 (on state) its callback is not called automatically: you need to call it directly with CallCtrlCallbackif you want it to be executed.
If your function is rather long and you need to set some control value and read it back within the same callback you will need to insert a ProcessDrawEvents or a ProcessSystemEvents to have the control updated. Be careful when using ProcessSystemEvents since another callback could be called that you do not want to handle inside the function; you may need to SetInputMode (..., ..., 0) all controls that you do not want to be active during your function.
12-22-2009 03:49 AM
actually, i took all the comments out, sorry about that. certain things i cant display.
let me make changes to see what works, give me a second
12-22-2009 03:53 AM
i know how to turn on and off a control switch, what im trying to do is if the switch is already on, i want to hit the switch to turn it off.
thats all i want to do.
12-22-2009 04:06 AM
darnell wrote:i know how to turn on and off a control switch, what im trying to do is if the switch is already on, i want to hit the switch to turn it off.
thats all i want to do.
Your message contradicts with itself: you know how to control a switch, but you do not know how to turn it off ?!?
Probably, your switch is set as Indicator mode.
That's why you cannot click on it and flip its state. Change its control mode to "Hot".
If you mean controlling programmatically, you can do this:
GetCtrlVal (panel, switch, &state);
SetCtrlVal (panel, switch, !state);
Hope this was the question,
12-22-2009 04:14 AM
the code does exactly what i want to do. for example if i turn the switch on, it stays on until I hit the switch again. at first when i hit the switch it
was just stay on instead of turning off. but now that i added the processSystemevents and Setinputmode, it works perfectly
case PANEL_Amplifier_MODE://Toggle Switch3->Bit 1
ProcessSystemEvents();/////////////I added the process events
SetInputMode(g_panelHandle,PANEL_Amplifier_MODE,1);/////////////*******I added setinputmode
SetCtrlVal(g_panelHandle, PANEL_Erp_Pm_MODE, 0);
SetCtrlVal(g_panelHandle, PANEL_Spec_An_MODE,0);
SetCtrlVal(g_panelHandle, PANEL_Signal_Gen_MODE,0);
SetCtrlVal(g_panelHandle, PANEL_Awg_Mixed_MODE,0);
SetCtrlVal(g_panelHandle, PANEL_O_Scope_MODE,0);
SetCtrlVal(g_panelHandle, PANEL_Repeater_MODE,0);
SetCtrlVal(g_panelHandle, PANEL_Attenuator_MODE,0);
SetCtrlVal(g_panelHandle, PANEL_LED_8, 0);
SetCtrlVal(g_panelHandle,PANEL_LED,0);
SetCtrlVal(g_panelHandle,PANEL_LED_2,0);
SetCtrlVal(g_panelHandle,PANEL_LED_3,0);
SetCtrlVal(g_panelHandle,PANEL_LED_4,0);
SetCtrlVal(g_panelHandle,PANEL_LED_5,0);
SetCtrlVal(g_panelHandle,PANEL_LED_6,0);
SetCtrlVal(g_panelHandle,PANEL_LED_7,0);
SetCtrlVal(g_panelHandle,PANEL_LED_8,0);
g_commandAddr =atoi(g_sInstrData[DEVICE_ADDR2]);//range 1-3
GetCtrlVal(g_panelHandle, PANEL_Amplifier_MODE,&g_dSwitch4Value);
//Safefty check on define macro,setting the limits to make sure the correct
//bit position to toggle are between the range 0-4
if((Bit2Toggle<0)||(Bit2Toggle>1))
{
MessagePopup("Warning! SWITCH 4 ERROR:",switch4ErrorMsg);
return FAILURE;
}
//Position1 = g_dSwitch4Value;
if(g_dSwitch4Value==0)
{
Position1=TURN_BIT_OFF;
g_dSwitch4Value=Position1;
g_retainAmpliflierValue=Position1;
SetCtrlVal(g_panelHandle, PANEL_LED_8, 1);
}
else if(g_dSwitch4Value==1)
{
Position1=(TURN_BITS_1AND2_ON);
g_dSwitch4Value=Position1;
g_retainAmpliflierValue=Position1;
}