Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hello all,

I have been searching the net, and particularly this forum for an answer or some direction to follow but I didn't find any, so here goes my problem.

I have a small inputs card with some switches... And I developed a small software application in Visual C# to interface this inputs card to FS2004 via FSUIPC (registered version).

Here goes a step by step of what I do and what happens:

1) Launch FS2004 with default C172;

2) Launch my application who connects to inputs card and acquire switches states;

3) My application connects to FS2004 via FSUIPC;

4) My application sends switches states to FS2004 via FSUIPC (via suitable Offsets and according values) to initialize the aircraft for a cold and dark start...

Problem 1: Everything goes OK. All switches in FS2004 replicate the real switches states EXCEPT for MASTER BAT and MASTER AVIONICS who doesn't switch OFF (as requested by my application).

Problem 2: During startup of the engine (after ignoring problem 1 and forcing manually all switches OFF), everything works OK but when I switch ON the MASTER ALT, electricity goes off! I mean, MASTER ALT goes ON then OFF, MASTER BAT goes OFF and MASTER AVIONICS goes OFF.

Can anyone help me or explain me why this could be happening?

FYI: The code I to control these switches:

MASTER ALT:

keyswitch = 0; //OFF

keyswitch = 1; //ON

result = fsuipc.FSUIPC_Write(0x3101, keyswitch, ref token, ref dwResult);

MASTER BAT:

keyswitch = 0; //OFF

keyswitch = 1; //ON

result = fsuipc.FSUIPC_Write(0x281C, keyswitch, ref token, ref dwResult);

MASTER AVIONICS:

keyswitch = 0; //OFF

keyswitch = 1; //ON

result = fsuipc.FSUIPC_Write(0x2E80, keyswitch, ref token, ref dwResult);

Many thanks and best regards to all,

Emmanuel.

Posted

Problem 1: Everything goes OK. All switches in FS2004 replicate the real switches states EXCEPT for MASTER BAT and MASTER AVIONICS who doesn't switch OFF (as requested by my application).

Problem 2: During startup of the engine (after ignoring problem 1 and forcing manually all switches OFF), everything works OK but when I switch ON the MASTER ALT, electricity goes off! I mean, MASTER ALT goes ON then OFF, MASTER BAT goes OFF and MASTER AVIONICS goes OFF.

Can anyone help me or explain me why this could be happening?

I need more information. You need to enable Event logging and IPC Write logging -- see the Logging Tab in FSUIPC options. Then repeat the whole sequence. Check that what you THINK you are writing is actually being written.

Also check whether it applies to all aircraft or only some -- the Master Alternator might be tied to the Battery switch so that you have to operate one before the other.

FYI: The code I to control these switches:

What sort of code is that? Where is the size of the write defined? Is the "keyswitch" value supplied in the FSUIPC_Write call a pointer to where the 0 or 1 is stored, as it should be? Does the variable pointed to have the correct size?

BTW I am away from tomorrow (Friday) until Sunday 13th March. So apologies if you get no more replies from me till then.

Regards

Pete

Posted

Hello Pete,

Thanks for your reply!

I need more information. You need to enable Event logging and IPC Write logging -- see the Logging Tab in FSUIPC options. Then repeat the whole sequence. Check that what you THINK you are writing is actually being written.

Also check whether it applies to all aircraft or only some -- the Master Alternator might be tied to the Battery switch so that you have to operate one before the other.

I am not with my hardware by my side (I'm not at home right now), so I can't make the tests right now, I have to let this for tomorrow. I'll be back with what you asked for.

What sort of code is that? Where is the size of the write defined? Is the "keyswitch" value supplied in the FSUIPC_Write call a pointer to where the 0 or 1 is stored, as it should be? Does the variable pointed to have the correct size?

My bad, I apologise, it's not a code, but rather some kind of pseudo-side-note-code. I'm sorry for getting you confused and spend your precious time over this.

"keyswitch" is a 32 bit variable (Int32) containing the logic state of the switch: 0 or 1.

So here goes an excert of the actual code:

Int32 keyswitch;   //Variable declaration
if (RXstring.Substring(50, 1) == "0")   //I090 - MASTER BAT switch OFF  <-- RXstring is received via serial port
{
   keyswitch = 0;
   result = fsuipc.FSUIPC_Write(0x281C, keyswitch, ref token, ref dwResult);
}
else                                    //I091 - MASTER BAT switch ON
{
   keyswitch = 1;
   result = fsuipc.FSUIPC_Write(0x281C, keyswitch, ref token, ref dwResult);
}
result = fsuipc.FSUIPC_Process(ref dwResult);

BTW I am away from tomorrow (Friday) until Sunday 13th March. So apologies if you get no more replies from me till then.

Regards

Pete

Not a problem at all! I just hope that you'll get some quality time in the meanwhile. ;)

I'll be here waiting. 8-)

Best regards,

Emmanuel.

Posted

Hi again Pete,

I remembered I had exactly the same problem some time ago with a "virtual hardware" I did. So I just used it to make the test you asked earlier in your post. Please find the log below.

I lanched FS2004 with default C172SP, sitting on the runway ready to depart (as default by FS).

Then I lanched my application, when it connects to FSUIPC, it shuts everything off in the aircraft, in order to put it as "cold and dark cockpit".

Then I start the engine start-up sequence:

- Master BAT ON

- Fuel valve BOTH

- Fuel pump ON

- Mixture RICH

- Start

Then, when I "hit" the MASTER ALT button, all electrical stuff goes OFF (Master BAT, master avionics and even the fuel pump).

HOWEVER, if I do this but instead of using my software to "hit" the master ALT, I use the button in Flight Simulator, everything goes fine! Strange huh?!

********* FSUIPC, Version 3.93 by Pete Dowson *********

Running inside FS2004 (FS9.1 CONTROLS.DLL, FS9.1 WEATHER.DLL)

User Name="Emmanuel******"

User Addr="************************"

FSUIPC Key is provided

WideFS Key is provided

[Continuation log requested by user]

Module base=61000000

ClassOptions: UIPCMAIN=FF7F, FS98MAIN=FF7F, FS2KMAIN=FF5E

WeatherOptions(Orig)=4000BE87[4000BE87]

InitDelay: 0 seconds

WeatherReadInterval=4

LogOptions=00000005

1281828 System time = 03/03/2011 22:01:13, FS2004 time = 12:16:30 (12:16Z)

1286250 WRITE0 3210, 2 bytes: FF FF

1289734 WRITE0 (failed, read-only!) 330A, 4 bytes: 02 00 00 00

1290078 WRITE0 0892, 2 bytes: 00 00

1290078 WRITE0 37F0, 8 bytes: 00 00 00 00 00 00 00 00

1290078 WRITE0 0890, 2 bytes: 00 00

1290078 WRITE0 088E, 2 bytes: 00 00

1290078 WRITE0 2E80, 4 bytes: 00 00 00 00

1290078 WRITE0 281C, 4 bytes: 00 00 00 00

1290078 WRITE0 3101, 4 bytes: 00 00 00 00

1290078 WRITE0 029C, 1 bytes: 00

1290078 WRITE0 029D, 3 bytes: 00 00 00

1290078 WRITE0 3110, 4 bytes: A3 01 01 00

1290078 WRITE0 0BC8, 2 bytes: FF 7F

1290078 WRITE0 0BCA, 2 bytes: 00 00

1290078 WRITE0 0BE8, 4 bytes: FF 3F 00 00

1290078 WRITE0 0D0C, 2 bytes: 00 00

1290078 WRITE0 0D0E, 2 bytes: 00 00

1290078 WRITE0 3110, 4 bytes: 3B 00 01 00

1290078 WRITE0 3104, 4 bytes: 00 00 00 00

1290078 *** EVENT: Cntrl= 66242 (0x000102c2), Param= 0 (0x00000000) TOGGLE_MASTER_ALTERNATOR

1290078 *** EVENT: Cntrl= 65955 (0x000101a3), Param= 0 (0x00000000) FUEL_SELECTOR_OFF

1290078 *** EVENT: Cntrl= 65595 (0x0001003b), Param= 0 (0x00000000) FLAPS_UP

1295141 WRITE0 281C, 4 bytes: 01 00 00 00

1296609 WRITE0 3210, 2 bytes: FF FF

1297766 WRITE0 3110, 4 bytes: A3 01 01 00

1297766 *** EVENT: Cntrl= 65955 (0x000101a3), Param= 0 (0x00000000) FUEL_SELECTOR_OFF

1297781 WRITE0 3110, 4 bytes: A4 01 01 00

1297781 *** EVENT: Cntrl= 65956 (0x000101a4), Param= 0 (0x00000000) FUEL_SELECTOR_ALL

1301594 WRITE0 3104, 4 bytes: 01 00 00 00

1301594 *** EVENT: Cntrl= 66339 (0x00010323), Param= 0 (0x00000000) TOGGLE_ELECT_FUEL_PUMP

1303562 WRITE0 0890, 2 bytes: 00 00

1303641 WRITE0 0890, 2 bytes: 00 00

1303656 WRITE0 0890, 2 bytes: 73 00

1303687 WRITE0 0890, 2 bytes: E5 00

1303719 WRITE0 0890, 2 bytes: 3D 02

1303734 WRITE0 0890, 2 bytes: AF 02

1303766 WRITE0 0890, 2 bytes: 07 04

1303781 WRITE0 0890, 2 bytes: 5E 05

1303812 WRITE0 0890, 2 bytes: 9B 07

1303844 WRITE0 0890, 2 bytes: 6B 0D

1303859 WRITE0 0890, 2 bytes: 8D 10

1303891 WRITE0 0890, 2 bytes: 57 12

1303906 WRITE0 0890, 2 bytes: EB 15

1303937 WRITE0 0890, 2 bytes: 43 17

1303969 WRITE0 0890, 2 bytes: BC 1B

1303984 WRITE0 0890, 2 bytes: F8 1D

1304016 WRITE0 0890, 2 bytes: AE 24

1304031 WRITE0 0890, 2 bytes: 5D 27

1304062 WRITE0 0890, 2 bytes: BB 2C

1304094 WRITE0 0890, 2 bytes: F8 2E

1304109 WRITE0 0890, 2 bytes: A7 31

1304141 WRITE0 0890, 2 bytes: FE 32

1304156 WRITE0 0890, 2 bytes: 92 36

1304187 WRITE0 0890, 2 bytes: 77 37

1304219 WRITE0 0890, 2 bytes: 26 3A

1304219 WRITE0 0890, 2 bytes: 63 3C

1304781 WRITE0 0890, 2 bytes: F7 3F

1304812 WRITE0 0890, 2 bytes: F7 3F

1306984 WRITE0 3210, 2 bytes: FF FF

1309109 WRITE0 0892, 2 bytes: 00 00

1309125 WRITE0 0892, 2 bytes: 01 00

1311062 WRITE0 0892, 2 bytes: 01 00

1311078 WRITE0 0892, 2 bytes: 02 00

1312797 WRITE0 0892, 2 bytes: 02 00

1312828 WRITE0 0892, 2 bytes: 03 00

1314672 WRITE0 0892, 2 bytes: 03 00

1314687 WRITE0 0892, 2 bytes: 04 00

1317328 WRITE0 3210, 2 bytes: FF FF

1318828 WRITE0 0892, 2 bytes: 04 00

1318859 WRITE0 0892, 2 bytes: 03 00

1327703 WRITE0 3210, 2 bytes: FF FF

1334625 WRITE0 3101, 4 bytes: 01 00 00 00

1334625 *** EVENT: Cntrl= 66339 (0x00010323), Param= 0 (0x00000000) TOGGLE_ELECT_FUEL_PUMP

1334625 *** EVENT: Cntrl= 66241 (0x000102c1), Param= 0 (0x00000000) TOGGLE_MASTER_BATTERY

1334625 *** EVENT: Cntrl= 66242 (0x000102c2), Param= 0 (0x00000000) TOGGLE_MASTER_ALTERNATOR

1334703 *** EVENT: Cntrl= 66242 (0x000102c2), Param= 0 (0x00000000) TOGGLE_MASTER_ALTERNATOR

1338062 WRITE0 3210, 2 bytes: FF FF

1349406 LogOptions changed, now 00000001 (LogExtras=0)

Thank you for your time Pete!

Best regards,

Emmanuel.

Posted

Then, when I "hit" the MASTER ALT button, all electrical stuff goes OFF (Master BAT, master avionics and even the fuel pump).

HOWEVER, if I do this but instead of using my software to "hit" the master ALT, I use the button in Flight Simulator, everything goes fine! Strange huh?!

No, not so strange. did you not look to see what your program is doing? Look

1290078 WRITE0 3104, 4 bytes: 00 00 00 00

1290078 *** EVENT: Cntrl= 66242 (0x000102c2), Param= 0 (0x00000000) TOGGLE_MASTER_ALTERNATOR

1290078 *** EVENT: Cntrl= 65955 (0x000101a3), Param= 0 (0x00000000) FUEL_SELECTOR_OFF

1290078 *** EVENT: Cntrl= 65595 (0x0001003b), Param= 0 (0x00000000) FLAPS_UP

and

1334625 WRITE0 3101, 4 bytes: 01 00 00 00

1334625 *** EVENT: Cntrl= 66339 (0x00010323), Param= 0 (0x00000000) TOGGLE_ELECT_FUEL_PUMP

1334625 *** EVENT: Cntrl= 66241 (0x000102c1), Param= 0 (0x00000000) TOGGLE_MASTER_BATTERY

1334625 *** EVENT: Cntrl= 66242 (0x000102c2), Param= 0 (0x00000000) TOGGLE_MASTER_ALTERNATOR

1334703 *** EVENT: Cntrl= 66242 (0x000102c2), Param= 0 (0x00000000) TOGGLE_MASTER_ALTERNATOR

Did you not norice that 3101 and 3104 are a one byte values? You are writing 00 to 3102, 3103 and 4104 as well when you write 3101, and similarly also to 3105, 3106 and 3107 when you write to 3104. No wonder things are goping off which should be on. I'm surprised worse doesn't happen!

I wonder how many other things you have set the wrong size write? You can easily crash FS this way!

This is why I asked you about the size (length) of the writes you are making. I don't know your type of code, I only know C/C++ and ASM. That's why I asked. Just because the source value is 32-bits doesn't mean (shouldn't meant) you only ever write 4 bytes. You should stick to the documented variable size!

Also I'd like to know more about what these lines are for:

1286250 WRITE0 3210, 2 bytes: FF FF

...

1296609 WRITE0 3210, 2 bytes: FF FF

..

1306984 WRITE0 3210, 2 bytes: FF FF

...

1317328 WRITE0 3210, 2 bytes: FF FF

..

1327703 WRITE0 3210, 2 bytes: FF FF

...

1338062 WRITE0 3210, 2 bytes: FF FF

Seems that every 10 seconds you set all virtual buttons 64,0 to 64,15 to "pressed". What are these buttons assigned t od? Do you intend this?

Regards

Pete

Posted

Emmanuel,

Pete is away for a bit so I thought I'd chip in here in case you're not clear how to proceed. It looks like you're using the old-school c# SDK so my advice is based on that.

Some of the offsets you are trying to write (e.g. 0x3101) are only 1 byte long. You are declaring your KeySwitch variable as Int32 which is fine for Master Avionics at 2E08 (because that is 4 bytes) but not for 3101. You are accidentally writing subsequent offsets (3101, 3102, 3103 and 3104) at the same time.

You need to declare another variable as 'byte' and use that in the _Write() method. This will invoke the correct overload and only write 1 byte to FSUIPC, not the 4 your are currently writing with the Int32 variable.

So it will be something like:

byte altswitch;   //Variable declaration for 1 byte offsets
altswitch = 0; // Or 1
result = fsuipc.FSUIPC_Write(0x3101, altswitch, ref token, ref dwResult);
result = fsuipc.FSUIPC_Process(ref dwResult);

For 2 Byte offsets your data must be passed in a variable of type 'short'.

If you've not written much FSUIPC code you might want to look at my FSUIPC Client DLL for .NET. It's much easier to use than the SDK you are using and supports all FSUIPC offsets. The SDK you are using doesn't handle any floating point or string offsets and doesn't do unsigned integers. (However, I do have code that can add such support if you really want to carry on using it). My DLL also comes with a user guide that explains what type of C# variables to use for each type of FSUIPC offset.

The DLL is free and can be downloaded from the 'Downloads' sub-forum:

FSUIPC Client DLL For .NET

Paul

Posted

Hello Pete and Paul,

Thank you very much to both of you for your answers!

To Pete:

Some time ago, I was suspecting, now I'm sure: I really need to reinforce my glasses. :) Thanks Pete for pointing me the ONE BYTE values mistake. In fact I never noticed that these values were only one byte wide... Since I read your post I corrected the error and verified the remaining variables sizes. Fortunately, there was only one more of this type. I too wondered about how many error of this kind I would find in my code. Hopefully, my codes are rather simple, just to interface some hardware I build to FS. I am an electronics guy who only knows about ASM (for several CPU architectures) and C programming above Linux. In Windows (due to MSFS) I started to use Visual C# Express Edition (free). I have been able to do some stuff, but very painfully. I've never seen such a stupid way of doing things as I do on Windows; I just can't find any suitable programming tutorial or manual for this "programming language"... Anyway, thanks again.

About the writing two FF bytes at 0x3210, every ten seconds. My code never writes anything there. I don't know where this comes from. I didn't find any evidence of the origin of these writing, but I will keep looking for.

To Paul:

Yes! I am still using the C# SDK.

Thank you for your answer too. You are also right about writing the wrong size variable. Thanks for your code example, it is almost exactly the same as I have written.

About your DLL, once I finish this piece of code (almost there) I will try the DLL (I already downloaded it), and given what you say, I will use it in my future developments. ;)

I cannot finsh my post without thanking both of you once more for your precious help. Thank you! 8-)

Best regards to all,

Emmanuel.

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.