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

Simulator gets stuck when using StartCommand #21

Open
maduranma opened this issue Feb 23, 2021 · 4 comments
Open

Simulator gets stuck when using StartCommand #21

maduranma opened this issue Feb 23, 2021 · 4 comments

Comments

@maduranma
Copy link

maduranma commented Feb 23, 2021

I use the DataRefTool and I discovered for my purpose that sim/flight_controls/pitch_trim_down and up is perfect.

Just for testing I do:
CancellationTokenSource trimTokenSource = xPlaneConnector.StartCommand(XPlaneConnector.Commands.FlightControlsPitchTrimUp);

After 3 seconds I cancel the token.

During the 3 seconds the sim just hung up and the trim doesn't change.

Am I missing something? Tested on FF A320

Edit:
Tested in a Cessna 172 default, it gets trimmed after closing the program, same, it hungs, but after the hung the trim that was being applied appears.

Edit 2:
I've looked the code of the connector.
It seems like there's a thread making an infinite loop sending the command, in my case it overloads the simulator, isn't there any alternative?
I've tried sending the command every 20ms and less, but not enough even to move...

@MaxFerretti
Copy link
Owner

MaxFerretti commented Mar 1, 2021 via email

@maduranma
Copy link
Author

maduranma commented Mar 1, 2021

I have an i7 4790k OCed at 5.2GHz, which is still a quite decent processor.
Windows 10 latest update.

I've seen that you just do a thread that is sending the command in an infinite loop.

I've tried adding a delay but the cockpit did not react, but I have not reasearch too much, I was just waiting.

@BirdyB
Copy link

BirdyB commented May 19, 2022

I have the same issue with Xplane 11.55r2 on MacOS Monterey. If i use your example with engaging starters X-Plane crashes immediately.

@DocMoebiuz
Copy link

The problem is that the task repeats the Command too fast. A thread.Sleep(10) will help, e.g.

public CancellationTokenSource StartCommand(XPlaneCommand command)
{
    var tokenSource = new CancellationTokenSource();

    Task.Run(() =>
    {
        while (!tokenSource.IsCancellationRequested)
        {
            SendCommand(command);
            Thread.Sleep(5);
        }
    }, tokenSource.Token);

    return tokenSource;
}

The starter will work and xplane won't crash for me, but we have a general limitation with this approach: It is a repeated "press" and not a "hold" - the effect of "holding" a Command is different, e.g. GNS530 CLR Button. It will bring you to the default page. I cannot trigger this behavior with the repeated command.

As far as I can tell, the UDP interface does not expose the https://developer.x-plane.com/sdk/XPLMCommandBegin/ and https://developer.x-plane.com/sdk/XPLMCommandEnd/ - so in my opinion there is no option to do it correctly at all without actually using a XP Plugin that is able to receive a special UDP message type and then trigger the respective API functions.

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

No branches or pull requests

4 participants