odwdinc / Python-SimConnect

Python interface for MSFS2020 SimConnect.dll
GNU Affero General Public License v3.0
281 stars 106 forks source link

Example for writing back values #4

Closed relax81 closed 4 years ago

relax81 commented 4 years ago

Thank you for this nice project. Im a beginner at programming, so this helped me a lot to build something that can control my desk / room lights based on ingame events.

Would it be possible to add an example how i can write back values to things like

PROP RPM:index or GENERAL ENG THROTTLE LEVER POSITION:index

?

Similar to your example with the toggle event for the Gear which helped me a lot. I tried to figure it out through the SDK Examples but that was a bit too overwhemling for my beginner level.

odwdinc commented 4 years ago

At this time I have not had luck writing to Simulation Variables. Only Event IDs seem to take input.

I am new so excuse me, but what use is it to set the Propeller rpm anyway?

For throttle you could use event THROTTLE[1-4]_SET to Set throttles exactly range is (0- 16383) where 0 is 0% throttle and 16383 is 100%

sample code:

# Create Request to read the throttle 1 lever position as Percent THROTTLERequest = sm.newRequest(time=5000) # set auto data collection time @ 5s THROTTLERequest.add('THROTTLE', (b'GENERAL ENG THROTTLE LEVER POSITION:1', b'Percent'))

# Create Event to write the throttle 1 lever position as integer form 0 - 16383 THROTTLE1_SET = sm.MapToSimEvent(b'THROTTLE1_SET')

sm.SendData(THROTTLE1_SET,DWORD(0)) #0%
sm.SendData(THROTTLE1_SET,DWORD(16383)) #100%

# check for data from THROTTLERequest data = sm.GetData(THROTTLERequest ) if data is not None: print("THROTTLE: %f" % ( data.THROTTLE ))

`

relax81 commented 4 years ago

Thank you very much for the help.

Throttle and RPM was just an example because they seem to work right now. I would like to use it later to randomly add cargo to the planes, but that Variable seems to have a bug at the moment so i mentioned something that works.

odwdinc commented 4 years ago

Thanks for the feedback

Are you referring to Simulation Variable "EXIT TYPE "? seems to be the only reference I can find to "cargo". If so, that seem to be a read only variable as there is a N in Settable column. If not do you have a list of ones that you would like to test all see if I can get them working proper. Maybe I can workout why I cant set Simulation Variables yet.

FYI you may want to try the Simvars form the SDK, its under samples. It has working get/set Simulation Variables. Might help with what is working vs is bugged, as yes not everything is supported/working.

relax81 commented 4 years ago

Thanks again for the reply, your example above works great.

My guess would be that the variables to add cargo should be

PAYLOAD STATION WEIGHT:index and PAYLOAD STATION OBJECT:index

In the "SimConnect_Status_of_Simulation_Variables" of the SDK they mention that it's "Settable". There is also a read only PAYLOAD STATION COUNT which might be used to get the amound of payload slots? But i'm not sure.

I'll try it during the weekend, but even big Add-Ons like OnAir have currently a problem with adding cargo via SimConnect. They can adjust the fuel, but not the cargo at the moment.

odwdinc commented 4 years ago

8 https://github.com/odwdinc/Python-SimConnect/pull/8/commits/4c74593758ca6bc21c059dce7c729047499af8c7

should add support for Settable Simulation Variables. I will close this for now feel free to reopen.