bendix King KT76A Transponder

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Message
Author
vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

bendix King KT76A Transponder

#1 Post by vangyver »

I am trying to modify the instrument Bendix/King KT 76A Transponder made by Experimental Sim Avionics to show just as pictured. I removed all the coding not required for me. The instrument works fine except when I turn off the ELECTRICAL AVIONICS BUS VOLTAGE switch or if I turn off XpdrModeKnobPos to position 0 in the simulator the transponder light still blinks. My “ident” button does not work in the instrument but does work in the simulator. I added the LVARs and still playing with the coding for a week and will keep trying. I do not use FS2020. Hoping I can get a little help here in the forum.
All of my instruments are done with the exception of the last three. (KT 76A, DME, and the ADF) for my simulator). All of my instruments are projected via a pico-projector to the rear side of the instrument panel. It eliminates many problems of installing multiple led screens and cutting/removing the vertical support ribs in the instrument panel.
Thanks in advance,
Van
Last edited by vangyver on Fri Aug 27, 2021 12:01 pm, edited 1 time in total.

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: bendix King KT76A Transponder

#2 Post by vangyver »

Code: Select all

local gbl_busv = 0
local gbl_ident = false
math.randomseed( os.time() )

-- Add images in Z-order --
img_add_fullscreen("BKKT76A.png")
img_ident = img_add("light.png", 160, 54, 46, 22)

-- Set default visibility --
opacity(img_ident, 0)

-- Add text in Z-order --
txt_code_1000 = txt_add("7", " font:Arimo-Bold.ttf; size:30px; color: #DCDCDC; halign: center;", 188, 33, 200, 200)
txt_code_100 = txt_add("0", " font:Arimo-Bold.ttf; size:30px; color: #DCDCDC; halign: center;", 298, 33, 200, 200)
txt_code_10 = txt_add("0", " font:Arimo-Bold.ttf; size:30px; color: #DCDCDC; halign: center;", 411, 33, 200, 200)
txt_code_1 = txt_add("0", " font:Arimo-Bold.ttf; size:30px; color: #DCDCDC; halign: center;", 523, 33, 200, 200)

function new_transponder(code, mode, brightness)
    
    -- Transponder code
    txt_set(txt_code_1000, math.floor(code / 1000))
    txt_set(txt_code_100, math.floor(code % 1000 / 100))
    txt_set(txt_code_10, math.floor(code % 1000 % 100 / 10))
    txt_set(txt_code_1, math.floor(code % 10))

    -- Transponder light
    opacity(img_ident, brightness)

end

function new_transponder_FSX(code, bus_volts)

    new_transponder(code, 3, 0)
    
    gbl_mode = 3
    gbl_busv = bus_volts

end

timer_start(nil, 250, function(count)

  -- Transponder light
    if (fs2020_connected() or fsx_connected() or p3d_connected()) and gbl_busv >= 8 then
        if gbl_mode >= 3 and not gbl_ident then
            if count%10 == math.random(0,9) then
                opacity(img_ident, 1, "LOG", 0.2)
            else
                opacity(img_ident, 0, "LOG", 0.2)
            end
        elseif gbl_mode == 2 and not gbl_ident then
            opacity(img_ident, 1, "LOG", 0.2)
        elseif (gbl_mode >= 3 or gbl_mode == 1) and gbl_ident then
            opacity(img_ident, 1, "LOG", 0.2)
        else
            opacity(img_ident, 0, "LOG", 0.2)
            timer_stop(ident_timer)
            gbl_ident = false
        end
    end
end)

-- Bus subscribe --

fsx_variable_subscribe("TRANSPONDER CODE:1", "Hz",
                       "ELECTRICAL MAIN BUS VOLTAGE", "Volts", 
                       "L:XpdrModeKnobPos", "enum",
                       "L:XpdrIdentSwitch", "enum",
                       "ELECTRICAL AVIONICS BUS VOLTAGE", "Volts", new_transponder_FSX)

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: bendix King KT76A Transponder

#3 Post by vangyver »

My Air manager instrument and my simulator:
Xpndr.jpg
After.jpg

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: bendix King KT76A Transponder

#4 Post by Sling »

Hi vangyver,

I see you have a new found Air Manager creation drive. I only have time for a quick reply now but I should be able to give you some more detailed help tomorrow. From the quick look I had you have not set the subscribe callback arguments and are therefore not using the related variable data to do anything. It is therefore no surprise the instrument does not respond to any change in this data.

I’ll try and post an update tomorrow. In the mean time it would be a good idea for you to watch the video tutorial on subscribes to help you understand how simple it is to get data from the sim into your Air Manager instruments. Videos are linked in my signature below.

Nice cockpit BTW.

Tony

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: bendix King KT76A Transponder

#5 Post by vangyver »

I edited the original script removing each unwanted code one step at a time keeping a backup on each edit. Once the script stops working I restore my last backup. So far the script works with the exceptions I noted. My next step was adding the subscribe callback arguments and editing the “IF” statement to include ELECTRICAL AVIONICS BUS VOLTAGE and the XpdrModeKnobPos. That is where I ran into problems. Yes I will watch the video on subscribe. I am persistent in trying to do things on my own without asking for help until I reach a dead end.
As you probably know I have all my real switches, buttons, and encoders are hooked up to Leo`s USB card. Air manager instruments are used as displays only via the pico-projector. So the Air Manager instrument only needs to display the transponder code. The flashing light when the electrical main bus, avionic switch and transponder is on or when I push the ident button that is connected to Leo`s USB card.
If you have time to assist that would be greatly appreciated and if not that is ok as I will try to find my answers even before you reply. I understand you may be very busy with other priorities.
Thanks in advance,
Van

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: bendix King KT76A Transponder

#6 Post by vangyver »

A micro step for you but one large step for me. Watched the videos. Understanding a little more. Slow learner.
experimenting.jpg

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: bendix King KT76A Transponder

#7 Post by vangyver »

My experimenting script:

Code: Select all

local gbl_mode = 0
local gbl_busv = 0
local gbl_ident = false
math.randomseed( os.time() )

-- Add images in Z-order --
img_add_fullscreen("BKKT76A.png")
img_ident = img_add("light.png", 160, 54, 46, 22)

-- Set default visibility --
opacity(img_ident, 0)

-- Add text in Z-order --
txt_code_1000 = txt_add("7", " font:Arimo-Bold.ttf; size:30px; color: #DCDCDC; halign: center;", 188, 33, 200, 200)
txt_code_100 = txt_add("0", " font:Arimo-Bold.ttf; size:30px; color: #DCDCDC; halign: center;", 298, 33, 200, 200)
txt_code_10 = txt_add("0", " font:Arimo-Bold.ttf; size:30px; color: #DCDCDC; halign: center;", 411, 33, 200, 200)
txt_code_1 = txt_add("0", " font:Arimo-Bold.ttf; size:30px; color: #DCDCDC; halign: center;", 523, 33, 200, 200)

function new_transponder(code, mode, brightness)
    
    -- Transponder code
    txt_set(txt_code_1000, math.floor(code / 1000))
    txt_set(txt_code_100, math.floor(code % 1000 / 100))
    txt_set(txt_code_10, math.floor(code % 1000 % 100 / 10))
    txt_set(txt_code_1, math.floor(code % 10))

    -- Transponder light
    opacity(img_ident, brightness)

end

function new_transponder_FSX(code, bus_volts)

    new_transponder(code, 3, 0)
    
    gbl_mode = 3
    gbl_busv = bus_volts

end

timer_start(nil, 250, function(count)

  -- Transponder light
    if (fs2020_connected() or fsx_connected() or p3d_connected()) and gbl_busv >= 8 then
        if gbl_mode >= 3 and not gbl_ident then
            if count%10 == math.random(0,9) then
                opacity(img_ident, 1, "LOG", 0.2)
            else
                opacity(img_ident, 0, "LOG", 0.2)
            end
        elseif gbl_mode == 2 and not gbl_ident then
            opacity(img_ident, 1, "LOG", 0.2)
        elseif (gbl_mode >= 3 or gbl_mode == 1) and gbl_ident then
            opacity(img_ident, 1, "LOG", 0.2)
        else
            opacity(img_ident, 0, "LOG", 0.2)
            timer_stop(ident_timer)
            gbl_ident = false
        end
    end
end)

function new_avionicsbus_FSX(avionics)
end

function new_mainbus_FSX(mainbus)
end

function new_XpdrMode_FSX(XpdrMode)
end

function new_Xpdrswt_FSX(identbutton)
end

function new_XpdrMode_FSX(XpdrMode)
    if XpdrMode >= 1 then
    print("A"..XpdrMode.."   yes")
    else
    print("B"..XpdrMode.."   nope")
    end
end

-- Bus subscribe --

fsx_variable_subscribe ("TRANSPONDER CODE:1", "Hz", new_transponder_FSX)
fsx_variable_subscribe("ELECTRICAL MAIN BUS VOLTAGE", "Volts", new_mainbus_FSX)
fsx_variable_subscribe("L:XpdrModeKnobPos", "enum", new_XpdrMode_FSX)
fsx_variable_subscribe("ELECTRICAL AVIONICS BUS VOLTAGE", "Volts", new_avionicsbus_FSX)
fsx_variable_subscribe("L:XpdrIdentSwitch", "enum", new_Xpdrswt_FSX)

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: bendix King KT76A Transponder

#8 Post by Sling »

Hi vangyver,

Not sure if you watched the xplane subscribe video but it explains multiple subscriptions with one callback as this original instrument had. Although its mainly about the xplane datarefs the learning methods very much carry over to the other sim platforms just with slightly different syntax.

Anyhow I found a few minutes to look over your code. As i just eluded to, you need to keep the multiple subscribe but add the extra callback argument names for every new subscribe you added. Compare my code with what you originally posted to see the difference in this regard. I also added the necessary changes required to action those new subscriptions. As you can see from the code comments this assumes the ident and mode LVAR's actually return what i've assumed. As with the NAV/COM radio code we did recently if it doesn't work correctly you can use print statements in the code while operating the transponder to see what the LVAR's are actually providing and then modify the code accordingly.

Hope this helps.

Tony

Code: Select all

local gbl_busv = 0
local gbl_mode = 0
local gbl_ident = false
local gbl_avv = 0
math.randomseed( os.time() )

-- Add images in Z-order --
img_add_fullscreen("BKKT76A.png")
img_ident = img_add("light.png", 160, 54, 46, 22)

-- Set default visibility --
opacity(img_ident, 0)

-- Add text in Z-order --
txt_code_1000 = txt_add("7", " font:Arimo-Bold.ttf; size:30px; color: #DCDCDC; halign: center;", 188, 33, 200, 200)
txt_code_100 = txt_add("0", " font:Arimo-Bold.ttf; size:30px; color: #DCDCDC; halign: center;", 298, 33, 200, 200)
txt_code_10 = txt_add("0", " font:Arimo-Bold.ttf; size:30px; color: #DCDCDC; halign: center;", 411, 33, 200, 200)
txt_code_1 = txt_add("0", " font:Arimo-Bold.ttf; size:30px; color: #DCDCDC; halign: center;", 523, 33, 200, 200)

function new_transponder_FSX(code, bus_volts, mode, ident, av_volts)

    --make globals
    gbl_busv = bus_volts
    gbl_mode = mode        --assumes 0=off, 1=sby, 2=tst, 3=on, 4=alt
    gbl_ident = ident == 1 --assumes ident LVAR is 1 while in ident (lasts a few seconds) & 0 when not
    gbl_avv = av_volts
    
    -- Transponder code
    txt_set(txt_code_1000, math.floor(code / 1000))
    txt_set(txt_code_100, math.floor(code % 1000 / 100))
    txt_set(txt_code_10, math.floor(code % 1000 % 100 / 10))
    txt_set(txt_code_1, math.floor(code % 10))

end

timer_start(nil, 250, function(count)
    -- Transponder light
    if (fs2020_connected() or fsx_connected() or p3d_connected()) and gbl_busv >= 8 and gbl_avv >= 8 and gbl_mode > 0 then
        if gbl_mode >= 3 and not gbl_ident then
            --generate random reply light
            if count%10 == math.random(0,9) then
                opacity(img_ident, 1, "LOG", 0.2)
            else
                opacity(img_ident, 0, "LOG", 0.2)
            end
        elseif gbl_mode == 2 then
            --tst
            opacity(img_ident, 1, "LOG", 0.2)
        elseif (gbl_mode >= 3 or gbl_mode == 1) and gbl_ident then
            --ident
            opacity(img_ident, 1, "LOG", 0.2)
        else
            --light off
            opacity(img_ident, 0, "LOG", 0.2)
        end
    else
        --power off
        opacity(img_ident, 0, "LOG", 0.2)
    end
end)

-- Bus subscribe --
fsx_variable_subscribe("TRANSPONDER CODE:1", "Hz",
                       "ELECTRICAL MAIN BUS VOLTAGE", "Volts", 
                       "L:XpdrModeKnobPos", "enum",
                       "L:XpdrIdentSwitch", "enum",
                       "ELECTRICAL AVIONICS BUS VOLTAGE", "Volts", new_transponder_FSX)

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: bendix King KT76A Transponder

#9 Post by vangyver »

Tony,
Due to my impatience and rush to learn new things I hastily looked through a few videos before jumping down to E06 - FSX P3D and FS2 variable subscribe. There was just too much I did not understand until I realized I needed to look at the “APIs” and read their proper usage. I found watching the videos are a great learning tool but they must be accompanied by the “WIKI/APIs” for anything one does not understand.
Looking at your new script I was a bit confused when using multi variables. Reading that variable subscribe function determines the order in which the variables will enter the callback function left me with a question. The fsx variable subscribe order is the same as “function new_transponder_FSX(code, bus_volts, mode, ident, av_volts)” but not the same order as the first four lines of the script ?
local gbl_busv = 0
local gbl_mode = 0
local gbl_ident = false
local gbl_avv = 0

The new script works great with the exception that the gbl_mode = mode
--assumes 0=off, 1=sby, 2=tst, 3=on, 4=alt. But the actual mode is
0 – off, 1 – Standby, 2 – On, 3 – alt, 4 – Test
The test mode lights the ident window which is the same thing as the ident button in A2A Piper Cherokee.

I’ve got a lot to learn and hoping I can do the next one on my own without troubling you for help.

Thank You so much for being patient with me,
Van

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: bendix King KT76A Transponder

#10 Post by Sling »

Hi vangyver,

The order of the subscribes absolutely needs to match the callback function argument order so the right data is used for the right thing. The order the declaration of the global variables is done is not important. All you are doing here is turning the sim data argument variable into a global variable that can be used elsewhere in the code. i.e. outside of the callback function.

The mode is the same as Xplane uses but for some reason fs2020 went the way I used as my assumption. I incorrectly assumed your add-on was the same but obviously not. Change out the following to make it work correctly.

Code: Select all

timer_start(nil, 250, function(count)
    -- Transponder light
    if (fs2020_connected() or fsx_connected() or p3d_connected()) and gbl_busv >= 8 and gbl_avv >= 8 and gbl_mode > 0 then
        if (gbl_mode == 2 or gbl_mode == 3) and not gbl_ident then
            --generate random reply light
            if count%10 == math.random(0,9) then
                opacity(img_ident, 1, "LOG", 0.2)
            else
                opacity(img_ident, 0, "LOG", 0.2)
            end
        elseif gbl_mode == 4 then
            --tst
            opacity(img_ident, 1, "LOG", 0.2)
        elseif gbl_mode >= 1 and gbl_mode <= 3 and gbl_ident then
            --ident
            opacity(img_ident, 1, "LOG", 0.2)
        else
            --light off
            opacity(img_ident, 0, "LOG", 0.2)
        end
    else
        --power off
        opacity(img_ident, 0, "LOG", 0.2)
    end
end)

Post Reply