Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get simconnect exception when using code outside of example script #8

Open
Slipperyseaweed opened this issue Jun 1, 2023 · 3 comments
Labels
question Further information is requested

Comments

@Slipperyseaweed
Copy link

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.

@Slipperyseaweed
Copy link
Author

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))`

@patricksurry
Copy link
Owner

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?

@patricksurry patricksurry added the question Further information is requested label Jun 11, 2023
@Slipperyseaweed
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants