Jump to content
The simFlight Network Forums
Paul Henty

FSUIPC Client DLL for .NET - Version 2.0

Recommended Posts

I am new to this and I didt really understand the SDK manual all that much. I am in the makeing of createing a acars system for a virtual airline which works 100% but I would like to add two features if possible. One I would like to let them know on landing what there landing rate was and also what there current altitude is. I have looked for the offsets and have tryed but all I get is random numbers for the altitude. If I try to landing rate I get a rate but most of the time it is 0.0 or -1.0. I know for a fact I cant get that with my nose down 100% and it still reads that. If you could so kidly help me that would be great!

Thank You

www.republicv.org

CEO

Share this post


Link to post
Share on other sites
I have looked for the offsets and have tryed but all I get is random numbers for the altitude. If I try to landing rate I get a rate but most of the time it is 0.0 or -1.0.

It would really help if you could paste the relevant bits of your code in here. It's difficult to help without seeing what you're doing. I need to see the declaration of the offsets and where you are using the values for the altitude and landing rate.

Anyway - here is how to get the altitude using the DLL. It gives a result in metres. You'll need to convert to feet if you want feet. I've had to assume you're using VB.

Private altitude As Offset(Of Long) = New FSUIPC.Offset(Of Long)(&H570)

...

FSUIPCConnection.Process()
Dim altMetres As Double
altMetres = altitude.Value / (65536.0 * 65536.0)

I can't help on the landing rate because I don't know what offset you're trying to use for that.

Paul

Share this post


Link to post
Share on other sites

Landing Rate:

Dim touch As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H30C)

Me.Label12.Text = airpeedKnots.ToString("f1")

Dim touchrate As Double = touch.Value / (3.28084 / 256)

Also for the altitude how would I convert it? Thank you again for the help

Share this post


Link to post
Share on other sites
Also for the altitude how would I convert it?

You mean to feet? Just multiply by 3.28084.

Dim altFeet As Double
altFeet = altitude.Value / (65536.0 * 65536.0) * 3.28084

For the touchdown rate, the conversion is this for feet per second:

Dim touchrate As Double = (touch.Value /256.0) * 3.28084

Or this for feet per minute:

Dim touchrate As Double = (touch.Value /256.0) * 3.28084 * 60.0

Paul

Share this post


Link to post
Share on other sites

I would like to thank you for that information and also one more thing I see that the altitude has alot of numbers after the "." is there anyway to make that not appear?

Thank You So MUCH

Share this post


Link to post
Share on other sites
the altitude has alot of numbers after the "." is there anyway to make that not appear?

You can round the altitude after the conversion like this:

altFeet = altitude.Value / (65536.0 * 65536.0) * 3.28084

altFeet = Math.Round(altFeet, 0)

The second parameter of the round function specifies how many digits to keep after the decimal point.

Paul

Share this post


Link to post
Share on other sites

I thank you for the help It works great I am sorry cant help but ask is there anyway to make my program know that the aircraft has landed so my program can do things such as

If landed = 1 Then

label1.text = landingrate

End If

Share this post


Link to post
Share on other sites

Here is some code but it never worked:

Dim landed As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H814) ' Basic integer read example

Dim landed As Double

If landed = "1" Then

Me.TextBox5.Text = touchrate.ToString("f1")

End If

Share this post


Link to post
Share on other sites
Here is some code but it never worked:

Dim landed As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H814) ' Basic integer read example

I'm not surprised. Offset 0814 isn't used. In FS2000 and FS98 it used to be the "flight analysis mode", and was always 1 if you'd asked FS to analyse your landings -- but it never ever meant you had landed. It isn't supported in FS2002, FS2004, FSX or ESP.

The only way to detect when you land is to watch the "on ground" flag, offset 0366.

Pete

Share this post


Link to post
Share on other sites
Ok so is there a way to have it in an if statement?

You have to read it from FSUIPC first, then test it in an if statement, obviously. Same as anything you want to read and deal with from FSUIPC. If you don't read it you can't test it.

Sorry, I'm not about to learn VB.NET. If you aren't a programmer someone else will have to program it for you.

Regards

Pete

Share this post


Link to post
Share on other sites

Is it possible to use the DLL as well in VC++ like in C#?

Hi Thomas,

I don't know anyone who has tried it, but as far as understand the answer is 'yes' with Visual Sudio C++ 2005 and onwards. The DLL is a standard .NET class library so C++ should be able to reference it like any other part of the .NET framework and use the classes inside it. All my documentation has examples in VB.NET and C#, so as long as you can translate one of those into C++ you shouldn't have any problems. I can't really help you on that because I don't know C++ at all.

If you're used to programming for the .NET framework in C++ then I'm sure you'll have no trouble.

I'd be interested to know if you get it working...

Paul

Share this post


Link to post
Share on other sites

Hi Paul

I'm writing in C# by using Visual Studio 2005 Pro version. For this your FSUIPCClient.dll works really perfect

Just now I'm trying to use VC++.

I just got it to work and it seems to work here as well okay :-)

Share this post


Link to post
Share on other sites

Hi Paul,

First, I must say your DLL is running great!

Although, I think I might have found a bug which crashs FS.

I have built a program in vb.net which reads onGround flag and Aircraft's title evry 1 second.

The problem occur when I change aircraft if I write a string to the offset &H3380 which is the text message offset..

Improtant to say that this happens even if I dont write the &H32FA (text delay) offset so the text even not displayed.

furthermore, all read & writes works great with out the text offset. In addition, disconnecting the offset after the write proccess doesn't help the issue.

Is it really a bug or i'm doing something wrong?

Thanks in advance,

Omer.

Share this post


Link to post
Share on other sites

Although, I think I might have found a bug which crashs FS.

I have built a program in vb.net which reads onGround flag and Aircraft's title evry 1 second.

The problem occur when I change aircraft if I write a string to the offset &H3380 which is the text message offset..

Improtant to say that this happens even if I dont write the &H32FA (text delay) offset so the text even not displayed.

furthermore, all read & writes works great with out the text offset.

If this is truly related to VB.NET and/or the DLL I'll let Paul handle it, but meanwhile please could you enable IPC write logging in FSUIPC, reproduce the crash, and show us the last parts of the log, leading to the crash. There should be no way of crashing FS just by writing to 3380 as it is purely an FSUIPC memory location, so it may be that the string that you end up writing is too long (more than the 128 bytes including zero terminator) and so overwriting something more critical.

And, please, can you elaborate on:

In addition, disconnecting the offset after the write process doesn't help the issue.

as it doesn't make sense to me I'm afraid.

Regards

Pete

Share this post


Link to post
Share on other sites

Is it really a bug or i'm doing something wrong?

Hi Omer,

I've tried to recreate what you're doing but I can't make it crash. I've setup a project that reads data from FSUIPC regularly. I then have a button to write a message to the FS screen for 2 seconds.

I run the program and press the button. The message appears on the screen. Then I change the aircraft and everything is fine.

Can you post some code in here so I can see exactly what you're doing? I especially need to the see the relevant offset declarations and the code that writes the string.

It may be useful if you can post in a small bit of code that will reproduce the error for me.

Also the FSUIPC log (see Pete's post above) would also be useful.

@Pete: The disconnect is a concept within the DLL. It allows you to 'turn off' offsets you've declared so that they are not read or written in subsequent 'Process' calls until you 'reconnect' them again.

Paul

Share this post


Link to post
Share on other sites

Hello Pete & Paul,

Sorry for the delay on replying as I wasn't at home.

Pete, for your request I have enabled IPC write logging and started a new log file and reproduced the crash. the resulted log file is as follows:

********* FSUIPC, Version 3.71 by Pete Dowson *********

Running inside FS2004(original release)

User Name=""

User Addr=""

FSUIPC not user registered

WIDEFS not user registered, or expired

[Continuation log requested by user]

Module base=61000000

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

WeatherOptions(Orig)=0000B027[0000B027]

InitDelay: 0 seconds

WeatherReadInterval=4

LogOptions=00000005

376125 System time = 02:08:04, FS2004 time = 02:04:10 (10:04Z)

376125 LogOptions changed, now 00000005 (LogExtras=0)

376532 WRITE0 7B91, 1 bytes: 00

376953 WRITE0 7B91, 1 bytes: 00

377438 WRITE0 7B91, 1 bytes: 00

377922 WRITE0 7B91, 1 bytes: 00

378438 WRITE0 7B91, 1 bytes: 00

378938 WRITE0 7B91, 1 bytes: 00

379422 WRITE0 7B91, 1 bytes: 00

379922 WRITE0 7B91, 1 bytes: 00

380438 WRITE0 7B91, 1 bytes: 00

380953 WRITE0 7B91, 1 bytes: 00

381438 WRITE0 7B91, 1 bytes: 00

382000 WRITE0 7B91, 1 bytes: 00

382453 WRITE0 7B91, 1 bytes: 00

382922 WRITE0 7B91, 1 bytes: 00

383453 WRITE0 7B91, 1 bytes: 00

383969 WRITE0 7B91, 1 bytes: 00

384453 WRITE0 7B91, 1 bytes: 00

384922 WRITE0 7B91, 1 bytes: 00

385453 WRITE0 7B91, 1 bytes: 00

385938 WRITE0 7B91, 1 bytes: 00

386422 WRITE0 7B91, 1 bytes: 00

386953 WRITE0 7B91, 1 bytes: 00

387453 WRITE0 7B91, 1 bytes: 00

387922 WRITE0 7B91, 1 bytes: 00

388453 WRITE0 7B91, 1 bytes: 00

388938 WRITE0 7B91, 1 bytes: 00

389422 WRITE0 7B91, 1 bytes: 00

389985 WRITE0 7B91, 1 bytes: 00

390547 WRITE0 7B91, 1 bytes: 00

390938 WRITE0 7B91, 1 bytes: 00

391438 WRITE0 7B91, 1 bytes: 00

391985 WRITE0 7B91, 1 bytes: 00

392422 WRITE0 7B91, 1 bytes: 00

392953 WRITE0 7B91, 1 bytes: 00

393422 WRITE0 7B91, 1 bytes: 00

393953 WRITE0 7B91, 1 bytes: 00

394422 WRITE0 7B91, 1 bytes: 00

394953 WRITE0 7B91, 1 bytes: 00

395422 WRITE0 7B91, 1 bytes: 00

395953 WRITE0 7B91, 1 bytes: 00

396438 WRITE0 7B91, 1 bytes: 00

396953 WRITE0 7B91, 1 bytes: 00

397438 WRITE0 7B91, 1 bytes: 00

397953 WRITE0 7B91, 1 bytes: 00

398438 WRITE0 7B91, 1 bytes: 00

398922 WRITE0 7B91, 1 bytes: 00

399438 WRITE0 7B91, 1 bytes: 00

399953 WRITE0 7B91, 1 bytes: 00

400438 WRITE0 7B91, 1 bytes: 00

400922 WRITE0 7B91, 1 bytes: 00

401438 WRITE0 7B91, 1 bytes: 00

401922 WRITE0 7B91, 1 bytes: 00

402438 WRITE0 7B91, 1 bytes: 00

402922 WRITE0 7B91, 1 bytes: 00

403438 WRITE0 7B91, 1 bytes: 00

403922 WRITE0 7B91, 1 bytes: 00

404438 WRITE0 7B91, 1 bytes: 00

404953 WRITE0 7B91, 1 bytes: 00

405438 WRITE0 7B91, 1 bytes: 00

406000 WRITE0 3380, 128 bytes: 54 69 6D 65 72 20 68 61 73 20 62 65 65 6E 20 73

406000 74 6F 70 70 65 64 21 20 49 6E 63 6F 72 72 65 63

406000 74 20 70 6C 61 6E 65 20 74 79 70 65 2E 00 00 00

406000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

406000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

406000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

406000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

406000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

406000 WRITE0 3400, 32 bytes: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

406000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

406000 WRITE0 3420, 8 bytes: 00 00 00 00 00 00 00 00

406000 WRITE0 3428, 16 bytes: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

406000 WRITE0 3438, 32 bytes: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

406000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

406000 WRITE0 3458, 16 bytes: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

406000 WRITE0 3468, 24 bytes: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

406000 00 00 00 00 00 00 00 00

406000 WRITE0 32FA, 4 bytes: 0A 00 00 00

406000 WRITE0 7B91, 1 bytes: 00

406453 WRITE0 7B91, 1 bytes: 00

406953 WRITE0 7B91, 1 bytes: 00

407469 WRITE0 7B91, 1 bytes: 00

407922 WRITE0 7B91, 1 bytes: 00

408453 WRITE0 7B91, 1 bytes: 00

408938 WRITE0 7B91, 1 bytes: 00

409453 WRITE0 7B91, 1 bytes: 00

409938 WRITE0 7B91, 1 bytes: 00

410453 WRITE0 7B91, 1 bytes: 00

410922 WRITE0 7B91, 1 bytes: 00

411422 WRITE0 7B91, 1 bytes: 00

411922 WRITE0 7B91, 1 bytes: 00

412469 WRITE0 7B91, 1 bytes: 00

413125 WRITE0 7B91, 1 bytes: 00

413453 WRITE0 7B91, 1 bytes: 00

413938 WRITE0 7B91, 1 bytes: 00

414422 WRITE0 7B91, 1 bytes: 00

414922 WRITE0 7B91, 1 bytes: 00

415422 WRITE0 7B91, 1 bytes: 00

415922 WRITE0 7B91, 1 bytes: 00

416422 WRITE0 7B91, 1 bytes: 00

And Paul, a small code snippest as you requested:

Dim fsuipc_ground As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H366)
Dim fsuipc_planetitle As Offset(Of String) = New FSUIPC.Offset(Of String)(&H3D00, 256)
Dim fsuipc_writeTxt As Offset(Of String) = New FSUIPC.Offset(Of String)(&H3380, 256)
Dim fsuipc_TextDelay As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H32FA)

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Try
                FSUIPCConnection.Process()
            Catch ex As FSUIPCException
                If ex.FSUIPCErrorCode = FSUIPCError.FSUIPC_ERR_SENDMSG Then
                    ConnectionTerminated()
                Else
                    Throw ex
                End If
            Catch ex As Exception
            End Try
            Plane_onGround = CBool(fsuipc_ground.Value)
            Plane_Title = fsuipc_planetitle.Value
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            fsuipc_writeTxt.Value = "Timer has been stopped! Incorrect plane type."
            fsuipc_TextDelay.Value = 10.0F
            fsuipc_writeTxt.Disconnect(True)
            fsuipc_TextDelay.Disconnect(True)
    End Sub

* Timer 1 is set to 1000 miliseconds interval.

Thanks for your guys help!

Omer.

Share this post


Link to post
Share on other sites

Hi Omer,

It's a bit late where I am so I'll check this out properly tomorrow. But an obvious mistake I can see at the moment is:

Dim fsuipc_TextDelay As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H32FA)

Offset 32FA is only 2 bytes long and therefore should be declared as Short not Integer. By declaring it as Integer you're accidentally overwriting the next 2 byte offset as well (32FC). Similarly, 0366 should also be a Short. I don't know if this will fix your problem though.

Dim fsuipc_TextDelay As Offset(Of Short) = New FSUIPC.Offset(Of Short)(&H32FA)
Dim fsuipc_ground As Offset(Of Short) = New FSUIPC.Offset(Of Short)(&H366)

Also your fsuipc_writeTxt offset should really be declared as write-only otherwise you're reading the text back in each time you process().

Dim fsuipc_writeTxt As Offset(Of String) = New FSUIPC.Offset(Of String)(&H3380, 256, True)

That's what instantly leaps out at me - I'll look more closely tomorrow.

Paul

Share this post


Link to post
Share on other sites

Pete, for your request I have enabled IPC write logging and started a new log file and reproduced the crash. the resulted log file is as follows:

Right, and it is exactly what I said it probably was -- you are writing 256 bytes to 3380, not 128.

Please please, you MUST take note of the sizes of each of the offset values! It is surely a trivial matter, but it is very important. Since FSUIPC lets you into the innards of FS, such bad errors can easily play havoc -- not necessarily doing nice tidy things like crashing FS, but other things which may be much more difficult to work out!

I see you also got the size for 32FA wrong too. I think you need to go through all of your code and recheck every single offset size, make sure you correct them all!

********* FSUIPC, Version 3.71 by Pete Dowson *********

If I'd known you were still on such a very old version of FSUIPC I wouldn't have helped. That is so old it is unbelievable! I don't support anything earlier than 3.85 at present, and 3.90 will be released later this month. Please do try to keep up to date and ALWAYS check versions before asking for support!

Anyway, now I've started I'll finish: here is where your write to 3380 is going awry:

  • 406000 WRITE0 3380, 128 bytes: 54 69 6D 65 72 20 68 61 73 20 62 65 65 6E 20 73
    406000 74 6F 70 70 65 64 21 20 49 6E 63 6F 72 72 65 63
    406000 74 20 70 6C 61 6E 65 20 74 79 70 65 2E 00 00 00
    406000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    406000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    406000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    406000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    406000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    406000 WRITE0 3400, 32 bytes: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    406000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    406000 WRITE0 3420, 8 bytes: 00 00 00 00 00 00 00 00
    406000 WRITE0 3428, 16 bytes: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    406000 WRITE0 3438, 32 bytes: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    406000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    406000 WRITE0 3458, 16 bytes: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    406000 WRITE0 3468, 24 bytes: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    406000 00 00 00 00 00 00 00 00

In fact the string you write is only 46 bytes, including the zero terminator -- providing the string is less than 128 bytes in total you would be better using the string length (+ 1 for the terminator).

And here the incorrect 4 bytes, instead of 2, for 32FA:

  • 406000 WRITE0 32FA, 4 bytes: 0A 00 00 00

And the code shows these errors clearly, even though I don't know the language:

  • Dim fsuipc_writeTxt As Offset(Of String) = New FSUIPC.Offset(Of String)(&H3380, 256)
    Dim fsuipc_TextDelay As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&H32FA)

Please update your FSUIPC !!!

Pete

Share this post


Link to post
Share on other sites

Hello guys,

I must say thanks! I have done fixes that you have showen me. Though, after the changes the SIM crashed as usual. But, after I had updated my FSUIPC version to the newest exists (3.85) it all worked well!

I will just take care to check clients's FSUIPC verison and prompt as needed.

Pete, Another question with your permission: You had mentioned I should specify the string length but I can't see how if the declaration of the offset is in the declaration area and if I put it everytime I use the offset I get an error: offset already exists.

Any suggestions?

Thanks in advance,

Omer.

Share this post


Link to post
Share on other sites

Pete, Another question with your permission: You had mentioned I should specify the string length but I can't see how if the declaration of the offset is in the declaration area and if I put it everytime I use the offset I get an error: offset already exists.

That's really a question for me. With my DLL you can't do what Pete suggests like you can with the SDKs for all other languages. The DLL always writes the full size declared for string offsets, padding with 0s at the end. I will modify the DLL to only write the length of the actual text for a future release, but for now there's nothing to worry about. It's very slightly inefficient like it is at the moment, but it's not doing any harm. (As long as you declare the correct length of course ;-) ).

Paul

Share this post


Link to post
Share on other sites

Hi Paul,

Just a question, I've established using FSInterrogate what variable sets the sim rate and using FSI I have wrote to FS.

Is it possible to write to FS / disable time acceleration by detecting a change in the number and setting it straight back to 1x.

thanks

Share this post


Link to post
Share on other sites

Is it possible to write to FS / disable time acceleration by detecting a change in the number and setting it straight back to 1x.

Hi Hawk,

Yes. Declare the offset:

Private SimRate As Offset(Of Short) = New FSUIPC.Offset(Of Short)(&HC1A)

Then in your timer loop, put this after the process() call:

If SimRate.Value <> 256 Then SimRate.Value = 256

256 = 1x (real time).

Depending on how often your timer executes it'll allow the new rate for a fraction of a second before resetting it.

Paul

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×

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.