Synchronize switches with xplane not working

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

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

Re: Synchronize switches with xplane not working

#31 Post by Sling »

xplanearg wrote: Thu Apr 15, 2021 9:36 am
Sling wrote: Thu Apr 15, 2021 7:11 am Yes my thoughts exactly. When trying to diagnose an issue or to get some code working you should keep the environment the same for each test as it just introduces more and more variances each time you test. I always recommend testing with default c172 if at all possible. Once working you can then start to introduce new things.
Hi, please try to reproduce like so:

1) set up airmanager to load automatically on the computer startup
2) configure your panel to load at airmanager startup.
3) use the code i provided in the example above
4) turn off the pc running airmanger
5) put your phisicall switch in the on position (battery for instance)
6) start the pc running airmanager, it will load airmanger automatically and load your panel automatically
7) start x-plane (airplane previously set up to load cold and dark)
8) the battery will not be turned on as it should
I don't need to go to all that trouble to be able to tell you that what you are currently doing will not work. The good news is it can be made to work as you want with one extra step in the code. Before i elaborate on the solution can you confirm that the code i posted works if you allow the hardware to be connected before trying to run the panel. you will obviously have to start the panel manually for this test. That means it works if you load xplane after AM as you wanted.

Its important we get this established first.

xplanearg
Posts: 44
Joined: Mon May 04, 2020 10:37 am

Re: Synchronize switches with xplane not working

#32 Post by xplanearg »

sorry im confused.
you are asking me to test your code but first start x-plane and then airmanager?

or you want me to disable my panel from auto starting when airmanager starts, so i then start airmanager and wait for the hardware to become available and then manually start my panel, and then start x-plane?

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

Re: Synchronize switches with xplane not working

#33 Post by Sling »

The second one

xplanearg
Posts: 44
Joined: Mon May 04, 2020 10:37 am

Re: Synchronize switches with xplane not working

#34 Post by xplanearg »

Sling wrote: Thu Apr 15, 2021 9:02 pmThe second one
Hi, ive tested the following with this code:

Code: Select all

local switch_36_pos
function switch_36_callback(position)
  print("The battery switch got changed to position " .. position)
  if position == 0 then
    xpl_command("sim/electrical/battery_1_off")
    xpl_command("laminar/c90/fltctrl/switch/elev_trim_control_dn") -- c90 laminar
  elseif position == 1 then
    xpl_command("sim/electrical/battery_1_on")
    xpl_command("laminar/c90/fltctrl/switch/elev_trim_control_up") -- c90 laminar
  end
  switch_36_pos = position
end
switch_36_id = hw_switch_add("ARDUINO_MEGA2560_A_D36", switch_36_callback)
switch_36_pos = hw_switch_get_position(switch_36_id)

function switch_36_subscribe(position)
  if position ~= switch_36_pos then
    switch_36_callback(switch_36_pos)
  end
end
xpl_dataref_subscribe("sim/cockpit/electrical/battery_on", "INT", switch_36_subscribe)
0) set the battery phisical switch to ON
1) start the pc with airmanager, stop the panel and disable the panel auto start
2) close airmanager
3) open airmanager, wait for devices to show available
4) start panel manually
5) start x-plane
6) the battery is OFF in x-plane. it did not work. Ive tested with C90 and C172 from Laminar

I think the problem is when you start first airmanager and then x-plane. Panel autostart on/off makes no difference

What is the solution to this problem?
cheers.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Synchronize switches with xplane not working

#35 Post by Keith Baxter »

xplanearg wrote: Fri Apr 16, 2021 9:57 am
Sling wrote: Thu Apr 15, 2021 9:02 pmThe second one
What is the solution to this problem?
cheers.
Hi,

We all want to help you but you are not helping your self.
The solution is to do what @Sling Tony is asking you to do.

Tony is taking you through a process of elimination.

SCRAP ALL YOU CODE IDEAS

Once established that the code works on your setup, and I can assure you it is fundamentally correct and has no flaws.Tony will show you how to start you AM and the arduino as you want.

It will save you a lot of time and frustration.
Just a friendly heads up.
Should you persist with your method, I fear you will find that those willing to help will walk away and you will be left to do your own thing.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

xplanearg
Posts: 44
Joined: Mon May 04, 2020 10:37 am

Re: Synchronize switches with xplane not working

#36 Post by xplanearg »

Keith Baxter wrote: Fri Apr 16, 2021 10:28 am
xplanearg wrote: Fri Apr 16, 2021 9:57 am
Sling wrote: Thu Apr 15, 2021 9:02 pmThe second one
What is the solution to this problem?
cheers.
Hi,

We all want to help you but you are not helping your self.
The solution is to do what @Sling Tony is asking you to do.

Tony is taking you through a process of elimination.

SCRAP ALL YOU CODE IDEAS

Once established that the code works on your setup, and I can assure you it is fundamentally correct and has no flaws.Tony will show you how to start you AM and the arduino as you want.

It will save you a lot of time and frustration.
Just a friendly heads up.
Should you persist with your method, I fear you will find that those willing to help will walk away and you will be left to do your own thing.

Keith
i literally did the test tony asked me to do

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Synchronize switches with xplane not working

#37 Post by Keith Baxter »

xplanearg wrote: Fri Apr 16, 2021 11:06 am
i literally did the test tony asked me to do
Cool,

If you ran his code EXACTLY as he posted and it works then tell him so. He will then help you with code to start AM and the arduing to do what you want.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

xplanearg
Posts: 44
Joined: Mon May 04, 2020 10:37 am

Re: Synchronize switches with xplane not working

#38 Post by xplanearg »

ok, i think i wont be able to find help here.
my findings indicate that i must start airmanager after x-plane is loaded for it to work, witch is what was described on my first message.
thanks to everyone that help, the issue is still there but i have to move on to other things, cant be dealing with this forever. will have to live with it or move my sim to another I/O solution
please close this, the issue is unresolved

thanks.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Synchronize switches with xplane not working

#39 Post by Keith Baxter »

xplanearg wrote: Fri Apr 16, 2021 11:30 am ok, i think i wont be able to find help here.
my findings indicate that i must start airmanager after x-plane is loaded for it to work, witch is what was described on my first message.
thanks to everyone that help, the issue is still there but i have to move on to other things, cant be dealing with this forever. will have to live with it or move my sim to another I/O solution
please close this, the issue is unresolved

thanks.
Hi,

No that is not the case.
You will find help and Tony will provide a solution. You must be prepared to do what Tony asks and tell him. ....Yes Tony you code works if the computer is switched on and then AM started. Or no I have no success with you code at all.

It is like building a house. First you buy the land. Then you get plans drawn up. Then foundations are laid etc etc

AM has features to do what you want and Tony will show you. I am sure of that. But he wants to make sure there are no underlying issues and other undiscovered issue not mentioned.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Synchronize switches with xplane not working

#40 Post by jph »

Keith Baxter wrote: Fri Apr 16, 2021 11:46 am
xplanearg wrote: Fri Apr 16, 2021 11:30 am ok, i think i wont be able to find help here.
my findings indicate that i must start airmanager after x-plane is loaded for it to work, witch is what was described on my first message.
thanks to everyone that help, the issue is still there but i have to move on to other things, cant be dealing with this forever. will have to live with it or move my sim to another I/O solution
please close this, the issue is unresolved

thanks.
Hi,

No that is not the case.
You will find help and Tony will provide a solution. You must be prepared to do what Tony asks and tell him. ....Yes Tony you code works if the computer is switched on and then AM started. Or no I have no success with you code at all.

It is like building a house. First you buy the land. Then you get plans drawn up. Then foundations are laid etc etc

AM has features to do what you want and Tony will show you. I am sure of that. But he wants to make sure there are no underlying issues and other undiscovered issue not mentioned.

Keith
Keith brother, there are times to 'hold' and times to 'fold' .. this is the time to 'fold' ;)
Life is too short. :shock:
People have gone out of their way to help !!!! - and FAR more - everything they can !, yet the user's belligerence rules.
:roll:
Stop wasting your precious time. I think Tony, yourself, and others have had the patience of saints here.
Time to call it quits. Let him be on his way.
I have HAD to bite my tongue here otherwise I would probably be banned as REAL hardcore profanities may be too much :roll: :roll: :o
I DO NOT suffer fools.
Joe. CISSP, MSc.

Post Reply