Jump to content
The simFlight Network Forums

Airspeed not being read from c#2 app [solved]


Recommended Posts

Hi all,

I am just starting to experiment with the c# sdk and as a result have written a little console app to experiment with the sdk.

I am able to initialise, open and close the fusipc instance. But a read on airspeed always returns 0.

The fsuipc (f in the code) is the supplied class with the SDK. I should point out this is dotNet 2.

Code Below,

Many Thanks in advance

Simon

--- Code ---

using System;
using System.Collections.Generic;
using System.Text;
using FsuipcSdk;

namespace FSUIPC_testing {
    class Program {

        static Fsuipc f = new Fsuipc();
        static bool result = false;
        static bool stop = false;
        static int fsVersion = 0;
        static int fsuResult = -1;
        static int offAirspeed = 0x02BC;
        static int size4 = 4;
        static int token = -1;

        static string TranslateResultCode(int code) {

            string message = string.Empty;


            switch (code) {
                case Fsuipc.FSUIPC_ERR_OK:
                    message = "FSUIPC_ERR_OK";
                    break;
                case Fsuipc.FSUIPC_ERR_OPEN:
                    message = "Already Open";
                    break;

                case Fsuipc.FSUIPC_ERR_NOFS:
                    message = "FSUIPC_ERR_NOFS";
                    break;

                case Fsuipc.FSUIPC_ERR_REGMSG:
                    message = "FSUIPC_ERR_REGMSG";
                    break;

                case Fsuipc.FSUIPC_ERR_ATOM:
                    message = "FSUIPC_ERR_ATOM";
                    break;

                case Fsuipc.FSUIPC_ERR_MAP:
                    message = "FSUIPC_ERR_MAP";
                    break;

                case Fsuipc.FSUIPC_ERR_VIEW:
                    message = "FSUIPC_ERR_VIEW";
                    break;

                case Fsuipc.FSUIPC_ERR_VERSION:
                    message = "FSUIPC_ERR_VERSION";
                    break;

                case Fsuipc.FSUIPC_ERR_WRONGFS:
                    message = "FSUIPC_ERR_WRONGFS";
                    break;

                case Fsuipc.FSUIPC_ERR_NOTOPEN:
                    message = "FSUIPC_ERR_NOTOPEN";
                    break;

                case Fsuipc.FSUIPC_ERR_NODATA:
                    message = "FSUIPC_ERR_NODATA";
                    break;

                case Fsuipc.FSUIPC_ERR_TIMEOUT:
                    message = "FSUIPC_ERR_TIMEOUT";
                    break;

                case Fsuipc.FSUIPC_ERR_SENDMSG:
                    message = "FSUIPC_ERR_SENDMSG";
                    break;

                case Fsuipc.FSUIPC_ERR_DATA:
                    message = "FSUIPC_ERR_DATA";
                    break;

                case Fsuipc.FSUIPC_ERR_RUNNING:
                    message = "FSUIPC_ERR_RUNNING";
                    break;

                case Fsuipc.FSUIPC_ERR_SIZE:
                    message = "FSUIPC_ERR_SIZE";
                    break;

                case Fsuipc.FSUIPC_ERR_BUFOVERFLOW:
                    message = "FSUIPC_ERR_BUFOVERFLOW";
                    break;

                default:
                    message = code.ToString();
                    break;
            }

            return message;
        }



        static void Main(string[] args) {

            bool exit = false;
            string command = string.Empty;

            while (!exit) {
                command = Console.ReadLine();
                switch (command) {
                    case "init":
                        Console.WriteLine(Init());
                        break;
                    case "open":
                        Console.WriteLine(Open());
                        break;
                    case "close":
                        Console.WriteLine(Close());
                        break;
					case "airspeed":
						Console.WriteLine(GetAirspeed());
						break;
                    case "exit":
                        exit = true;
                        break;
                    default:
                        Console.WriteLine("-- Bad Command : " + command);
                        break;
                }
            }

        }

        static private string Init() {
            f.FSUIPC_Initialization();
            return "-- Initialised";
        }

        static private string Open() {
			result = f.FSUIPC_Open(fsVersion, ref fsuResult);
            if (result) {
                return "-- Open";
            } else {
                string msg = "-- Not Open: " + TranslateResultCode(fsuResult);
                return msg;
            }

        }

        static private string Close() {
			f.FSUIPC_Close();
			return "-- Closed";
        }

		static private string GetAirspeed() {

			string msg = string.Empty;

			result = f.FSUIPC_Read(offAirspeed, size4, ref token, ref fsuResult);
			if (result) {
				msg = "a/s read; ";
			} else {
				msg += "-- Error: " + TranslateResultCode(fsuResult);
				return msg;
			}
			result = f.FSUIPC_Process(ref fsuResult);
			if (result) {
				msg += "a/s processed; ";
			} else {
				msg += "Error: " + TranslateResultCode(fsuResult);
				return msg;
			}
			result = f.FSUIPC_Get(ref token, ref fsuResult);
			if (result) {
				msg += "a/s got; ";
			} else {
				msg += "Error: " + TranslateResultCode(fsuResult);
				return msg;
			}
			return msg += "a/s = " + fsuResult * 128;
		}


    }
}

Link to comment
Share on other sites

I am just starting to experiment with the c# sdk and as a result have written a little console app to experiment with the sdk.

I am able to initialise, open and close the fusipc instance. But a read on airspeed always returns 0.

I'm afraid I am unable to help with C#, which is really quite alien to a C programmer (I have no idea why MS called it C anything :roll: ).

The C# part of the SDK is undergoing a serious overhaul with new tools being added, but I don't think a release is imminent. Meanwhile, you could direct you questions to its author, one Pelle Liljendal. I think you should find his details, even his website, via the Sticky above about FSInterrogate.

Two things I do find rather odd, but it may be my non-understanding of C#:

1) You seem to have a thing called "fsuResult" which somehow has a dual purpose. For example, on an error you treat it as a result code:

TranslateResultCode(fsuResult)

but then, just after that, you treat it as if it receives the Air Speed itself:

fsuResult * 128

Surely if it were to contain the result code, a zero for success would be what you'd expect?

2) The value in 02BC is, as documented, the airspeed in knots * 128. In other words the units are 1/128ths of a knot. Yet here you are multiplying it again by 128. Do you really want it in 1/16384ths of a knot?

Regards

Pete

Link to comment
Share on other sites

Hi Paul,

Thanks for checking. I have tried dividing / 128 and using the fsuResult value unadjusted, its always 0. I take it you were getting a speed?

Could this be a version problem. I am using the version of FSUIPC that came with my PMDG 737-600/700 NG (dll version 3.1.2.9). Apologees if I may be out of date or out of touch, but am just returning to the flight sim world after a lay off.

Cheers

Simon

Link to comment
Share on other sites

Could this be a version problem. I am using the version of FSUIPC that came with my PMDG 737-600/700 NG (dll version 3.1.2.9). Apologees if I may be out of date or out of touch, but am just returning to the flight sim world after a lay off.

No, the airspeed has been provided in the same place since FSUIPC version 1.00, and is the same in FS98, FS2000, CFS1, FS2002, CFS2 and FS2004.

However, I cannot possibly support a version which is so old! So, first please go to http://www.schiratti.com/dowson and download the currently supported version. The one you have doesn't even work with the current version of FS2004, released 18 months ago!

Second, did you purchase an FSUIPC access key?

Regards,

Pete

Link to comment
Share on other sites

Errr,

That's odd. It does connect and FS Navigator is working fine. I was under the impression that used FSUIPC (of course I could be wrong, oddly enough it's happened before).

I will download a new version.

Nope I didn't purchase an FSUIPC access key. The only applications I have used in the past with it are "accredited" so to speak. I am planning to develop an application(s) which will be freeware to the FS community.

I may be confused about the licensing and in fact maybe this is the root of my problem.

Cheers

Simon

Link to comment
Share on other sites

That's odd. It does connect and FS Navigator is working fine. I was under the impression that used FSUIPC (of course I could be wrong, oddly enough it's happened before).

No, FSNav does not use FSUIPC.

In any case almost all payware add-ons, and most freeware add-ons, which use FSUIPC incorporate their own access codes which grants them access automatically. This doesn't mean your program has access.

I may be confused about the licensing and in fact maybe this is the root of my problem.

Yes, it seems so. Developers normally (100% so far) purchase a user access key for FSUIPC. This enables them to write programs, use debuggers, and so on, with FSUIPC. If you like, the payment sort of helps justify the programming support I provide (which can be extensive for languages I understand) and the upkeep of the SDK.

Freeware programs can be provided with an application access key on request, but by that time they are usually mostly developed. Before that, most debugging environments wouldn't work with an application access key in any case because they'd actually be running as a different process.

If you haven't got a valid access key, and haven't registered FSUIPC as a User, the initial connection to FSUIPC still works, but the data you get will not be valid, other than things like the FS and FSUIPC versions. This connection stage has to happen, as the automatic registration from your program consists of writing a Key to offset 8001 AFTER connection, but before anything else is done.

If you check the FSUIPC log file you should see this. You can even (without paying!) enable IPC read and write logging in FSUIPC's options so you can see EXACTLY what transpired.

I'm rather surprised you haven't actually been prompted by a message box saying there's an access error. Maybe you are trying to use an invalid user key?

Please look again at the FSUIPC SDK, and in particular find the document therein on Access Registration.

Regards,

Pete

Link to comment
Share on other sites

Sorry Peter,

I did get that dialog but I didn't quite understand the implications. I was assuming it was a "nag" screen that indicated that the access wasn't licensed as such.

Ok I'm clear, now I need to purchase a license key. I'm sure there is info for that somewhere, but if you want to drop a link or method of payment in here thats appreciated.

Cheers

Simon

Link to comment
Share on other sites

Ok I'm clear, now I need to purchase a license key. I'm sure there is info for that somewhere, but if you want to drop a link or method of payment in here thats appreciated.

When you download the current supported FSUIPC from the site I gave you, you'll see a link for the registration. If not, it's in the first few pages of the documentation. If you don't see that either, check the Announcements here. There's one entitled "PAYING FOR FSUIPCthe Why and How".

Please do keep an eye on the announcements here in any case. They are designed to help you.

Regards

Pete

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • 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.