Jump to content
The simFlight Network Forums

Event Handler Issue


Recommended Posts

Good day,

I'm experiencing an issue when writing to an offset from an event delegate. In this case 0x0354 (Transponder). The code below, from the SDK, works PERFECTLY when I call the function from a button, timer tick, etc. However, once I call the same SetTransponder() from an event delegate, the value in FSX only updates refreshes about 20% of the time. The other 80% of the time it doesn't update. What's even stranger is if I immediately read back the offset from FSUIPC, I always get the correct value, even though the value in FSX hasn't changed.  I added a counter to the function to make sure the function was firing, and it accurately increments every time the function is called.

 
private Offset<ushort>  FSUIPC_TransponderCode = new Offset<ushort>(0x0354);
int counter;

UDPConnection.UDPDataReceived += new EventHandler(SetTransponder); // Start UDP listener

SetTransponder ()
{
     FsTransponderCode txHelper = new FsTransponderCode((int)value);
     FSUIPC_TransponderCode.Value = txHelper.ToBCD();
     counter++;
}

 

Output

If I fire this function 15 times from the event handler, and send the results to the Output window I get:

Output Window (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);

But in FSX, I will see

Transponder Frequency (0001, 0004, 0005, 0010, 0013)

However, If I fire this function from a timer or button I get:

Output Window (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);

Transponder Frequency (0001,0002,0003,0004,0005,0006,0007,0008,0009........0015)

The function is definitely firing, as I'm getting the correct counter output on each function call AND I'm getting the correct value back if I immediately query FSUIPC. So, any idea why FSX doesn't update consistently when the function is fired by an event?

Thanks much,

Robert

Link to comment
Share on other sites

Hi Robert,

It's a bit difficult to tell from the code you've posted.

One thing I'm not clear on is where the process() is happening. I would expect it to be in SetTransponder() after the value is set.

If your process() call is elsewhere (like on a separate timer loop) then it's probably that the UDPDataReceived event is firing faster than the Process() calls. So it's going something like this:
 

FSUIPC_TransponderCode.Value = 1
Process()
FSUIPC_TransponderCode.Value = 2
FSUIPC_TransponderCode.Value = 3
FSUIPC_TransponderCode.Value = 4
Process()

In that case you would only see 1 and 4 set in the sim,

Quote

I'm getting the correct value back if I immediately query FSUIPC

Do you mean the local variable (FSUIPC_TransponderCode.Value)? That will just hold a copy of whatever you've set it to locally.

Or do you mean you've done a Process() call to get the current value back from FSUIPC?

Paul

Link to comment
Share on other sites

Thank you for your response Paul!

It was running Process() in a separate timer at 15ms intervals, but I also added it as the very next line after writing the transponder code and it does the same thing.

FsTransponderCode txHelper = new FsTransponderCode((int)value);
FSUIPC_TransponderCode.Value = txHelper.ToBCD();
Process();

 

Quote

Do you mean the local variable (FSUIPC_TransponderCode.Value)? That will just hold a copy of whatever you've set it to locally.

Or do you mean you've done a Process() call to get the current value back from FSUIPC?

I am indeed referring to the local variable FSUIPC_TransponderCode.Value, and I've called Process()

Robert

Link to comment
Share on other sites

I'm not really sure what's causing this then.

I would put some messages (Debug.WriteLine) in your code to see the timing and the order in which your methods and events are being called. That might give you a clue as to what's going wrong.

Generally, it sounds like UDPConnection.UDPDataReceived is being fired too quickly and FSUIPC/FSX just can't keep up with the requests to change the transponder code.

Paul

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.