PDA

View Full Version : Initializing LED to be Turned Off



colt45
08-14-2010, 02:59 PM
Hi,

I have working on my first SIOC script, which is an enhancement of an existing script borrowed from OC's forum to operate a transponder in a GA plane. My intent is to add a rotary switch to select Off, Standby, or Mode C for use in Squawkbox. In addition I would like to add an led to my panel to be lit when the transponder is in Mode C. I have had some success in getting that to work. However I would like the led to be off (ie. unlit) when I first start up FS. It will then turn on when I have rotated the switch to the input position which corresponds with Mode C.

I have gone through Nico's website for explainations of how to initialize variables to do this but am not getting the led to start unlit. When I start FS the led is lit and if I change the switch to the Mode C input and than back to standby it will turn off. Subsequent changes of the swiitch to Mode C will turn the led on and then back to off when switched to standyby.

I don't know how to embed my code into this post so I have attached my .txt file of my script. If someone can have a look at it and offer some suggestions I would be most appreciative.

Thanks, Dave

fordgt40
08-14-2010, 05:06 PM
Dave

Try:-

Var 0, value 0
{
&XPONDER_INIT = 10
&LED_INIT = 20
}

David

colt45
08-14-2010, 05:57 PM
David,

Thank you very much for your response. Unfortunately it has not done the trick. I am starting to think the problem is not in the initialization of the state of the led but rather in the manner in which I have scripted the rotary switch operation and the read/write statements for FSUIPC. I am going to have another go at it using a simple toggle switch. The offset $0B791 only gives the status of the transponder as standby ( =0) and Mode C ( =1) so the rotary switch is not really necessary. Just thought it would look more authentic rather than a toggle.

Any further thoughts are welcome.

Cheers, Dave

colt45
08-14-2010, 10:07 PM
The more I work on this problem, the more I think it has to do with the part of the script which deals with data going back and forth to FSUIPC. I now have a push button connected. When I start FS and hence SIOC, the led lights up (which I don't want). I push the button once and nothing happens to the light nor does the FSUIPC log show the offset being changed. The second time I push the button the led goes out and the offset changes to 0 which is standby mode. The third time I push the button the led lights up and the offset changes to 1.

Based on above I am getting close but still want the led to be unlit at start up and the offset to be correspondingly set to 0.

I have attached the revised SIOC script which uses the push button rather than the rotary switch used in my first attempt.

Any comments are welcome.

Cheers, Dave

deering
08-15-2010, 05:04 AM
Dave,

according to the SB doc. $7B91 = 0 is Normal(Mode C), 1 = Standby.

Jim.

fordgt40
08-15-2010, 05:15 AM
Dave

I see that you have not always defined the "TYPE" for some of the switch inputs. It might be worth doing that as I do not know what SIOC takes as its default

David

colt45
08-15-2010, 02:28 PM
Jim and David,

Thanks again for helping out with this and I am getting closer to what I want the script to do.

Jim you are right about the offset, oversight on my part. I have now changed the script to reflect 0 is Normal(Mode C), 1 = Standby. So now when I start FS and SIOC the led stays unlit as I am wanting and according to the FSUIPC log file the offset is set to 1. So far so good. However when I push the button there is no response in the FS or SIOC. The log file does not show the button push and the led does not light. However when I push the button a second time the led lights and the log file shows the offset state changing to 1. As it should and things are synchronized between the led and the offset. This remains the case for all subsequent button pushes. So the question is why does the first button push not get recognized?

Below is the portion of the script which deals with this. Again any thoughts or suggestions are appreciated.

Var 0135, Link FSUIPC_OUT, Offset $7b91, Length 1 // sets transponder mode based on input from push button

Var 0138, Link IOCARD_SW, Input 13, Type P // Push Button for Transponder Mode
{
V0135 = V0138
}

Var 0139, name XPONDER_STATE, Link FSUIPC_IN Offset $7b91 Length 1 // state of transponder to set led
{
IF &XPONDER_STATE = 0
{
&XPONDER_LED = 1
}
ELSE
{
&XPONDER_LED = 0
}
}

Var 0140, name XPONDER_LED, Link IOCARD_OUT Output 23 // led to indicate standby or Mode C


Cheers, Dave

deering
08-15-2010, 03:17 PM
Dave,
after initialization, the transponder is in Standy and XPONDER_STATE = 1. When you push the button for the first time V138 = 1 which you assign to V135.
V135=XPONDER_STATE and was already set to 1 before you make that assignment. As the vaue does not change, the attached script is not driven by SIOC. From here on you're in synch. You can assign V0138 = 1 in your initialization script to get off on the right foot.

Jim.

colt45
08-15-2010, 03:51 PM
Jim,

Continued thanks for your thoughts on this. I initialized V0138 =1 and no luck. I also tried setting V0135 = 1 at initialization eventhough it should already have that as an initial value and that didn't work either.

I will on this and hopefully something does the trick.

Cheers, Dave

deering
08-15-2010, 04:10 PM
Dave,
I know that SIOC won't let you set an initialization value on the declaration of an input; but, I tested it with VAR0 initialization and it appeared to work O.K.

You could:



Var 0138, Link IOCARD_SW, Input 13, Type P // Push Button for Transponder Mode
{
V0135 = CHANGEBITN 0 V0138
}

if that doesn't interfere with any other values that $7B91 might have. I don't use SB so I don't know the detals of its offsets.

Jim

deering
08-15-2010, 08:32 PM
Dave,

I had an error in my last post..should have read:



Var 0138, Link IOCARD_SW, Input 13, Type P // Push Button for Transponder Mode
{
V0135 = CHANGEBITN 0 V0138
}


Jim

colt45
08-15-2010, 09:32 PM
Jim,

Thanks for hanging in there with me. To the best of my knowledge the SB Offset isn't broke down further into bits. It is a value only (ie. 0 or 1)

However I am happy to report success. I went back to my original idea of using a rotary switch after finding a script at the OC forum. The script was much more complicated than I needed for a wide range of radio functions. Buried within it was the transponder and I was able to scrounge some code from the overall script. Modified it slightly and it worked. Rotary switch starts in off position and led is unlit ; switch to Standby position and led remains unlit ; switch to active (Mode C) and led lights up. Switching back to standby or off and led turns off.

FYI here is the piece of code that did the trick:


Var 0304, Link IOCARD_SW, Input 13 // XPNDR Mode STBY
{
IF V0304 = 1
{
V0399 = 1
}
}

Var 0305, Link IOCARD_SW, Input 14 // XPNDR Mode Normal
{
IF V0305 = 1
{
V0399 = 0
}
}

Var 0399, Link FSUIPC_OUT, Offset $7B91, Length 1 // Squawkbox XPNDR Mode
{
CALL V0139
}

Var 0139, Link SUBRUTINE // state of transponder to set led
{
IF v0399 = 0
{
&XPONDER_LED = 1
}
ELSE
{
&XPONDER_LED = 0
}
}

Var 0140, name XPONDER_LED, Link IOCARD_OUT Output 23 // led to indicate standby or Mode C

Cheers, Dave