pysimconnect
pysimconnect copied to clipboard
Get simconnect exception when using code outside of example script
I have created a class which uses pysimconnect. This class works as intended when I use it locally with if name == "main", but when i import the class from another module I get the following warning: "WARNING:root:sc.receiveNext: exception 3, sendID 2, index 4294967295"
I also get the same warning when I copy and paste the class inside my main code and run it.
Here is example code.
`from simconnect import SimConnect, PERIOD_VISUAL_FRAME
class Simdata():
def __init__(self):
self.sc = SimConnect(default_receivers=[])
self.sim_data = None
self.latest = 0
self.simvars = [
# Provide a dictionary to specify optional attributes:
# 'units' (per SDK), 'epsilon' (default 1e-4) and 'type' (default DATATYPE_FLOAT64)
dict(name="Airspeed indicated", units="knots"),
dict(name="Indicated Altitude", units="feet"),
dict(name="KOHLSMAN SETTING MB:1", units="millibars"),
dict(name="ATTITUDE INDICATOR BANK DEGREES", units='degrees'),
dict(name="ATTITUDE INDICATOR PITCH DEGREES", units='degrees'),
]
self.dd = self.sc.subscribe_simdata(self.simvars, period=PERIOD_VISUAL_FRAME, interval=10)
def fetch_data(self):
#TODO: add timeout incase we do not receive something to avoid infinite loop
while True:
self.sc.receive()
n = len(self.dd.simdata.changedsince(self.latest))
if n:
return self.dd.simdata
def update_data(self):
print("trying to update data")
self.sim_data = self.fetch_data()
def return_data(self, requested_data):
return self.sim_data[requested_data]
test = Simdata()
if name == "main": test = Simdata() test.update_data() print(test.sim_data) for var in test.sc._receivers: print(vars(var))`
that's strange; my guess would be somehow the class is being instantiated twice somehow. in your code above you have test=Simdata() before (and after) the if __name__ ... which probably wouldn't work. can you try adding a simple print statemement inside your init function to make sure it's only getting called once when you're importing as a module?
Thanks for replying. It was calIed only once. I tried removing the class entirely, and still I get the error. I then copied the modified code without a class directly into my main pygame file and still I got the error. Perhaps it somehow does not play well with the pygame module somehow? I will try to investigate further.