Closed iceyrazor closed 3 years ago
oml. nvM it happenes when i minus down the game, or if it unloads when i tab out. a way to reconnect would be nice -_-
nvm. im changing the title because i just did get the error that was poping up. 3 times in a row
and i also got [WinError -1073741506] Windows Error 0xc000013e earlier
i saw on another form unrelated to this specific library that your not supposed to spam request with sim connect. so im going to try and save the last sate of each variable and only switch it if its changed. and only save to the last state if its actully switched.
the reason why im making so many post about these issues is because im having trouble simply finding things related to these issues. and the examples do not show how to loop stuff properly. so maby these github issues can help other people too
i beleive this did solve most of my issues. but this constantly getting this error because of constant request is annoying. is there anyway i can do a auto reconnect or error management on this?
ok this is just ridiculous. im reopening this because its crashing over this ONE get request.
def sim_conn_output(): while True: if 'eng1' in json_data.keys(): if aq.get("INDICATED_ALTITUDE"): ser.write(bytes('<D' + ("%05d" % aq.get("INDICATED_ALTITUDE")) + '\r\n', 'utf-8')) json_data["curr_altitude"] = ("%05d" % aq.get("INDICATED_ALTITUDE")) time.sleep(0.3)
if there is a way to get the altitude live ouput without it crashing. please let me know
well now its running fine. this is confusing.
So it looks like there is a misunderstanding on how the coed works, My guess with this code.
while True:
if 'eng1' in json_data.keys():
if aq.get("INDICATED_ALTITUDE"): # Your problem is hear. This is a new request for data.
ser.write(bytes('<D' + ("%05d" % aq.get("INDICATED_ALTITUDE")) + '\r\n', 'utf-8')) # As well as hear.
json_data["curr_altitude"] = ("%05d" % aq.get("INDICATED_ALTITUDE")) # As well as hear.
time.sleep(0.3)
Any time you call get
on data it sets the value to None and will ask the sim for new data, if the sim request times out then the data is still None.
you have 3 requests, one to check if the data is good, this duse not save the data for the next too requests. The results are that lines ser.write
and json_data
my have None passed as the return value.
You may want to try something:
while True:
if 'eng1' in json_data.keys():
ia = aq.get("INDICATED_ALTITUDE") # Data is temp saved to variable ia
if ia: # if ia is not None
ser.write(bytes('<D' + ("%05d" % ia) + '\r\n', 'utf-8')) # Do what you will with the data.
json_data["curr_altitude"] = ("%05d" % ia)
time.sleep(0.3)
So it looks like there is a misunderstanding on how the coed works, My guess with this code.
while True: if 'eng1' in json_data.keys(): if aq.get("INDICATED_ALTITUDE"): # Your problem is hear. This is a new request for data. ser.write(bytes('<D' + ("%05d" % aq.get("INDICATED_ALTITUDE")) + '\r\n', 'utf-8')) # As well as hear. json_data["curr_altitude"] = ("%05d" % aq.get("INDICATED_ALTITUDE")) # As well as hear. time.sleep(0.3)
Any time you call
get
on data it sets the value to None and will ask the sim for new data, if the sim request times out then the data is still None.you have 3 requests, one to check if the data is good, this duse not save the data for the next too requests. The results are that lines
ser.write
andjson_data
my have None passed as the return value.You may want to try something:
while True: if 'eng1' in json_data.keys(): ia = aq.get("INDICATED_ALTITUDE") # Data is temp saved to variable ia if ia: # if ia is not None ser.write(bytes('<D' + ("%05d" % ia) + '\r\n', 'utf-8')) # Do what you will with the data. json_data["curr_altitude"] = ("%05d" % ia) time.sleep(0.3)
yeah like i said. i had it run for about 5-10 minutes and it was fine.
this one occasionally causes it to crash too
if 'eng1' in json_data.keys():
if not json_data['throttle'] == last_json_data['throttle']:
aq.find('GENERAL_ENG_THROTTLE_LEVER_POSITION:1').value = int(json_data['throttle'])
aq.find('GENERAL_ENG_THROTTLE_LEVER_POSITION:2').value = int(json_data['throttle'])
if str(aq.get("GENERAL_ENG_THROTTLE_LEVER_POSITION:1")) == json_data['throttle']:
last_json_data['throttle'] = json_data['throttle']
so is there a better way to also send mass set request too?
oh wait i think i get it now. you set it as a variable to make the request. and if the request is valid. then it will do stuff.
i got it for sending i think
while loop == True:
if 'eng1' in json_data.keys():
if not json_data['throttle'] == last_json_data['throttle']:
throt=aq.find('GENERAL_ENG_THROTTLE_LEVER_POSITION:1')
if throt:
throt.setIndex(1)
throt.value=int(json_data['throttle'])
throt.setIndex(2)
throt.value = int(json_data['throttle'])
if str(aq.get("GENERAL_ENG_THROTTLE_LEVER_POSITION:1")) == json_data['throttle']:
last_json_data['throttle'] = json_data['throttle']
though still. jim's sim connect between arduino and fsx is faster. this is still sorta fun to get to work. but the documentation isnt really that good. theres alot. but also alot is unclear. like how you make a request with by setting it as a variable first then checking it with a if statement. haven't seen that anywhere. maby im just not seeing it
See the examples,
https://github.com/odwdinc/Python-SimConnect/blob/master/local_example.py
I'm not 100% what you are looking for, best to use what works for you. good luck
@odwdinc this loop crashed it
while loop == True:
event=aq.get('CABIN_SEATBELTS_ALERT_SWITCH')
if event==True:
print("true")
also i see it in the examples. but its not really explained why you do it that way. rather than put the request in the if statement. there are also some other things that are not explained well. like the this
throt.setIndex(1)
throt.value=int(json_data['throttle'])
throt.setIndex(2)
throt.value = int(json_data['throttle'])
on your example
# If useing
# Throttle = aq.find('GENERAL_ENG_THROTTLE_LEVER_POSITION:index')
# Need to set index befor read/write
# Note to set index 2 vs 1 just re-run
# Throttle.setIndex(1)
didnt quite get that. i only got it because i saw it in a seperate doc. and because when i tested it like this.
throt1=aq.find('GENERAL_ENG_THROTTLE_LEVER_POSITION:1')
throt2=aq.find('GENERAL_ENG_THROTTLE_LEVER_POSITION:2')
if throt:
throt.value=int(json_data['throttle'])
throt2.value = int(json_data['throttle'])
it only set one throttle then i thought of that. so i gues it was clear? XD. but id imagine some people might not get it
again is there a way to make it reconnect or handle errors with this?
just happened again
its definitely not crashing as much but still
ok now its been running for a hour.....
you could uses a try
??
https://www.w3schools.com/python/python_try_except.asp
Don't use AircraftRequests.find()
or AircraftRequests.get()
more then once per object as this is returning an new object not values.
The setIndex
is for working with any 'name:pos' type to update the pos potation of the sim variable.
maybe have a look over
https://github.com/odwdinc/Python-SimConnect/blob/master/SimConnect/RequestList.py This should work fine.
throt=aq.find('GENERAL_ENG_THROTTLE_LEVER_POSITION:index')
while loop == True:
try:
if 'eng1' in json_data.keys():
if not json_data['throttle'] == last_json_data['throttle']:
if throt:
throt.setIndex(1) # Any reading or writing will be to "GENERAL_ENG_THROTTLE_LEVER_POSITION:1"
throt.value=int(json_data['throttle'])
throt.setIndex(2) # Any reading or writing will be to "GENERAL_ENG_THROTTLE_LEVER_POSITION:2"
throt.value = int(json_data['throttle'])
throt.setIndex(1) # sets back to "GENERAL_ENG_THROTTLE_LEVER_POSITION:1"
if str(throt.value) == json_data['throttle']:
last_json_data['throttle'] = json_data['throttle']
except OSError as err:
print("OS error: {0}".format(err))
While is nice to see you interested in the project there is no plan to support fsx:se. The mods to get working aka the replacement of the dll are untested, and unsupported. If you would like to test with MSFS2020 and confirm if the problems are with the lib or the your mods. Filling up the issues with unsupported requests and over 60 emals have come in over the last 3 days. I work a 9 to 5 M-F and have a family and comments like this come cross, Note even if you go back and change it later..
"i am just about fed up with this library. its giving me SO many issues its unreal. good effort though ill probly switch to c++ at this point"
So I ask why are you hear? This lib is a work in progress aka the 0.4.23 not a 1.x.x+. This lib is in a parity ruff state. The code speaks for its self. I work on it as a have free time for, others have offered to help where they can. If you need take the time to read the code and understand what and how it works or it my not be the best fit for you. Other projects are at a much more stable point. With such thing as the switch to async pending, it do not make sense for me to document things more than they are now.
English is not easy for me and trying to get documentation is last.
oh ok thanks for the info. sorry you got spammed. i just notice new things with it as a go and think it might help other people out with this. i didn't even think that 0.4 ment beta.
but i think maby other people having the same issues or dont understand it like i don't might get some help out of these. but i can stop if it bothers you too much.
yeah i get how to use set index now. i was just saying it wasn't clear to me to begin with. but for real though. great work on the lib. better than anything i could do.. i didn't mean to be any annoyance. im just impatient.
sorry.
im also new to github too.
i get the error shown blow after letting a while loop run aq.get for a while. is this a issue with threading? what is causing this
the errors are stacking because of 2 loops running aq get separately.
is there a way to handle these errors and simply just reconnect to the sm accrosed threads?