Jump to content
The simFlight Network Forums
efratomer

Newbe with connection to FSUIPC (Via Visual Basic)

Recommended Posts

Hey Pete,

Well WOW now im confused.

What EXACTLY do you really want to fix? Do you want to be able simply to adjust the amount of fuel in the tanks, or do you want some value in some menu in FS to exactly reflect what you want? I don't understand.

Its kind of them both? I want to set the fuel level as execly as I wrote him.

Like 14.3 Galons in the left tank & in the right tank.

Meaning, I do NOT want it to round it for 15 or 13 whatever. How shell I do it?

Why not, instead of reading percentages in FS's dialogues, read the fuel levels on the gauges? That is surely the only thing that is relevant, isn't it?

I haven't seen in the offsets list an offset which will bring back Galons in tank... Did I missed it?

Maybe, whoever derived the units used in those locations got them slightly wrong? This dates from way before my time, from FS98 and FS95 before that. Maybe instead of being 128 = 100% it was 127.76541 or some other number which has some special significance. I do not know. I would be extremely reluctant to change the documentation now even if it is slightly wrong, because there are so many programs using this stuff quite happily that I would not want them all to have to change.

If all you want to achieve is to get a certain figure in the dialogue, then set that figure in that dialogue, read what is in the FSUIPC offset for that tank, and write that. This is the only way. You can read the value either in FSInterrogate or using the FSUIPC monitor (right-hand side of the Logging options page).

Im really sorry but I didnt understand what you are saying here.

Really thanks Pete!

Omer.

Share this post


Link to post
Share on other sites

efratomer

If all you want to achieve is to get a certain figure in the dialogue, then set that figure in that dialogue, read what is in the FSUIPC offset for that tank, and write that. This is the only way. You can read the value either in FSInterrogate or using the FSUIPC monitor (right-hand side of the Logging options page).

That's only solution... otherwise we can't really help by giving the exact you need.

Share this post


Link to post
Share on other sites

Its kind of them both? I want to set the fuel level as execly as I wrote him. Like 14.3 Galons in the left tank & in the right tank.

Meaning, I do NOT want it to round it for 15 or 13 whatever. How shell I do it?

And when you try to set 14.3 you get 15? Is that what you are saying? I really can't believe it is that much out. Let me check with FSInterrogate.

[Later]

I really don't know how you are seeing such large differences. Take the default 737 for instance.

Values read by FSInterrogate with FS paused (engines are running so the fuel is changing, which is why I paused it):

Centre tank: Capacity 2313

Level 99.81263% (the integer read is 8372890 which is 99.81262% x 128 x 65536).

Thus US Gallons = 2308.6661

Left Tank: 1500

Level 99.67475%

US Gallons = 1495.1213

Right Tank: 1500

Level 99.67475%

US Gallons = 1495.1213

Going to the dialogue in FS:

Centre = 99.8%, 2308 Gallons

Left = 99.7%, 1496 gallons

Right = 99.7%, 1496 gallons

Left 99.7%

These values match to within one part in 1496! How can you figures be correct?

Please check things using FSInterrogate. See if your figures match its figures. If not, you have got something wrong!

I haven't seen in the offsets list an offset which will bring back Galons in tank... Did I missed it?

For each tank there's a CAPACITY offset, which is how many US gallons 100% represents, and a LEVEL, which is the value you read or write to tell you how full it is. The CAPACITY offset is right next to each LEVEL offset, so I'm amzed you've not noticed it.

Having got the level and the capacity you can easily work out the number of US gallons.

Regards,

Pete

Share this post


Link to post
Share on other sites

Hey Pete!

And when you try to set 14.3 you get 15? Is that what you are saying? I really can't believe it is that much out. Let me check with FSInterrogate.

Yes that what happend.

Please check things using FSInterrogate. See if your figures match its figures. If not, you have got something wrong!

Somehow, I have now checked but after I load the default 737 and opened the FSInterrogate I got all 0 in all of the fuel tanks in the plane (event though it was full on fuel on board).

For each tank there's a CAPACITY offset, which is how many US gallons 100% represents, and a LEVEL, which is the value you read or write to tell you how full it is. The CAPACITY offset is right next to each LEVEL offset, so I'm amzed you've not noticed it.

Having got the level and the capacity you can easily work out the number of US gallons.

Well I just probebly didnt understood you in the last reply, I just didnt understood your talking on the Capacity of each fuel tank. This one I have seen.

And have been thinking on using it, and after you wrote to use it. I have tried and it is now much much more accurate.

I have done this:

Dim setfuel As Long
Dim maxfuel As Long
Call FSUIPC_Read(&HB80, 4, VarPtr(maxfuel), dwResult)
Call FSUIPC_Process(dwResult)
setfuel = (1000 / maxfuel) * (128 * 65536)
Call FSUIPC_Write(&HB7C, 4, VarPtr(setfuel), dwResult)
Call FSUIPC_Process(dwResult)

Now this have worked great!

It actualy returned 1001 galons in the fuel tank.

Tried the same code only with 1400 galons and that time it did returned 1400 galons in the fuel tank. :)

I think the fuel situtation as been solved finally. THANKS!! :D

Another question (really hope you still got power for me :oops:):

What about plane coordinates?

I have looked up for the right offsets and found the following:

0560 Lat Lo

0564 Lat Hi

0568 Long Lo

056C Long Hi

I have tried to see what im getting for the Lat Lo (0560) by this code:

Dim plane_latlo As Long
Call FSUIPC_Read(&H560, 4, VarPtr(plane_latlo), dwResult)
Call FSUIPC_Process(dwResult)
MsgBox plane_latlo

Now what that I had in the msgbox was: -1133445120

execly as I got in the FSInterrogate....

only problem is that I really dont know what to do with it for getting the full decimal lattitude and longtitude numbers of the plane. Some help please?

Thanks in advance,

Omer.

Share this post


Link to post
Share on other sites

And when you try to set 14.3 you get 15? Is that what you are saying? I really can't believe it is that much out. Let me check with FSInterrogate.

Yes that what happend.

You are most certainly making an elementary arithmetic error then, somewhere. I have now checked this thoroughly. The formula in my documentation is accurate. The only slight inaccuracy anywhere is in the FS displays, where is seems to usually round UP to the next whole number of gallons even if the value is .000001 over! The values you can read and write via FSUIPC are more accurate than the displays.

Somehow, I have now checked but after I load the default 737 and opened the FSInterrogate I got all 0 in all of the fuel tanks in the plane (event though it was full on fuel on board).

Does FSInterrogate read anything anywhere? The current version will not actually connect to FS unless FS is up and running first BEFORE you run FSInterrogate. There's a new version coming which is a lot better and will connect/disconnect as needed, automatically.

I have looked up for the right offsets and found the following:

0560 Lat Lo

0564 Lat Hi

0568 Long Lo

056C Long Hi

They are only split up like that in FSInterrogate because that version cannot handly 64-bit integers. Please use the Programmer's guide documentation as your main source of information. It contains much more explanatory material.

only problem is that I really dont know what to do with it for getting the full decimal lattitude and longtitude numbers of the plane. Some help please?

All the help you should need is in the documentation NOT in FSInterrogate. Read those values into a 64 bit value and apply the formula given.

There have been VB examples for this in threads in this Forum, and no threads have been deleted.

Pete

Share this post


Link to post
Share on other sites

You are most certainly making an elementary arithmetic error then, somewhere. I have now checked this thoroughly. The formula in my documentation is accurate. The only slight inaccuracy anywhere is in the FS displays, where is seems to usually round UP to the next whole number of gallons even if the value is .000001 over! The values you can read and write via FSUIPC are more accurate than the displays.

I got you my problem was that I set the precentage and not the gallons...

like I wrote it I want 70% of the fuel tank. Probebly thats why it was no accurate.

Does FSInterrogate read anything anywhere? The current version will not actually connect to FS unless FS is up and running first BEFORE you run FSInterrogate. There's a new version coming which is a lot better and will connect/disconnect as needed, automatically.

as I told:

Somehow, I have now checked but after I load the default 737 and opened the FSInterrogate I got all 0 in all of the fuel tanks in the plane (event though it was full on fuel on board).

I DID opened the FS first, of course.

They are only split up like that in FSInterrogate because that version cannot handly 64-bit integers. Please use the Programmer's guide documentation as your main source of information. It contains much more explanatory material.

As I know, and as I read here in the forum old threads - VB Doesn't support 64-bit integers...

All the help you should need is in the documentation NOT in FSInterrogate. Read those values into a 64 bit value and apply the formula given.

I did looked in the documenation and found this:

you will have to handle the high 32-bits and the low 32-bits separately, combining them into one double floating point value (say dHi). To do, copy the high part (the 32-bit int at 0564) to one double and the low part (the 32-bit unsigned int at 0560) to another (say dLo). Remember that the low part is only part of a bigger number, so doesn’t have a sign of its own. Divide dLo by (65536.0 * 65536.0) to give it its proper magnitude compared to the high part, then either add it to or subtract it from dHi according to whether dHi is positive or negative. This preserves the integrity of the original positive or negative number. Finally multiply the result by 90.0/10001750.0 to get degrees.

Now, if I have understood this correctly I have done the following:

Dim dHi As Double
Dim dLo As Double
Call FSUIPC_Read(&H564, 4, VarPtr(dHi), dwResult)
Call FSUIPC_Read(&H560, 4, VarPtr(dLo), dwResult)
Call FSUIPC_Process(dwResult)
dLo = dLo / (65536# * 65536#)
    If dHi > 0 Then
        dHi = dHi + dLo
    Else
        dHi = dHi - dLo
    End If
dHi = dHi * (90# / 10001750#)

At the end dHi was equal to: 2.32210853545386E-322

And I really doesn't know what this number means...

In addition, I have tried to set the dHi and the dLo as Long varients,

the result was that at the end dHi was equal to: 47

Which was part of my plane's coordinate: N47* 25.89' W122* 18.48'

Why im getting 2.32210853545386E-322 instead of a decimal coordinate?

Thanks,

Omer.

Share this post


Link to post
Share on other sites

As I know, and as I read here in the forum old threads - VB Doesn't support 64-bit integers...

No, but apparently there's something called "Currency" which may be a 64-bit integer with a sort of fractional part. From what I remember you can read it into one of those, copy it to a double floating point variable, and multiply the result by 10000 to get the true 64-bit integer values. At least that's what i seem to recall -- check the other threads (there are most certainly some here -- I do wish you'd take advice and go look!), or perhaps just look it up in a VB book.

Now, if I have understood this correctly I have done the following:

Dim dHi As Double

Dim dLo As Double

Call FSUIPC_Read(&H564, 4, VarPtr(dHi), dwResult)

Call FSUIPC_Read(&H560, 4, VarPtr(dLo), dwResult)

No, you seem not to have understood any of it. The numbers are NOT in floating point format. If you read them into floating point variables you will get absolute rubbish. Not only that but you have completely missed the point that a Double is 8 bytes, not 4. The code above will give you some unpredictable nonsense.

I am really at my limit with this level of basic elementary programming tuition and I am afraid I just cannot continue. Sorry. If I do try to continue my patience will have been completely exhausted. It is even more frustrating that you seem not to retain any information from what you are told, and so it gets very tiresome repeating things all the time, especially at this elementary level. I do hope you will find someone else here to help, but also please do find the threads already here. There are certainly ones dealing with these points and have more VB expertise than I can possibly muster.

Regards,

Pete

Share this post


Link to post
Share on other sites

Public Function Plane_Lat() As Double ' Planes latitude

Dim fake64bit As Currency

Dim dwResult As Long

Call FSUIPC_Read(&H560, 8, VarPtr(fake64bit), dwResult)

Call FSUIPC_Process(dwResult)

Plane_Lat = fake64bit * 10000#

Plane_Lat = Plane_Lat * 90# / (10001750# * 65536# * 65536#)

End Function

Public Function Plane_Lon() As Double ' Plane's longitude

Dim fake64bit As Currency

Dim dwResult As Long

Call FSUIPC_Read(&H568, 8, VarPtr(fake64bit), dwResult)

Call FSUIPC_Process(dwResult)

Plane_Lon = fake64bit * 10000#

Plane_Lon = Plane_Lon * 360# / (65536# * 65536# * 65536# * 65536#)

End Function

Share this post


Link to post
Share on other sites

Hello again,

Thanks! Thats all I needed!

What i've done was that in a click of a button your are getting located in some parking space at some airport including the heading of the parking...

Another issue I have in mind:

After im moving the plane into a far away coordinate, it doesn't show the loading screen and it loads while in the plane so you can see the loading action infront of you, I say its kind of ugly, Is there any way of forcing the simulator of showing the loading screen?

Pete, sorry if you get tired of me :?

Thanks in advance,

Omer.

Share this post


Link to post
Share on other sites

After im moving the plane into a far away coordinate, it doesn't show the loading screen and it loads while in the plane so you can see the loading action infront of you, I say its kind of ugly, Is there any way of forcing the simulator of showing the loading screen?

Sorry, I don't understand. You mean reloading scenery progress bar? To force FS to reload scenery after you've moved the aircraft like that you need to send the "Refresh Scenery" control (look it up in the List of FS2004 controls supplied with FSUIPC). You can do that via offset 3110.

Pete, sorry if you get tired of me :?

It isn't so much that as me being frightened of losing my cool and getting irritable. I really am not a good teacher (ask my children!) and I can, these days, recognise when my patience has expired -- and that's when I have to stop or risk getting horribly unpleasant.

On top of that I do not even know VB -- and what I do know of it makes me horrified that such an inconsistent and illogical language (to me at least) is an entry for new programmers.

Regards

Pete

Share this post


Link to post
Share on other sites

Well, Thanks Pete.

I think i'll just give in with this one.

I'ts not that improtant for me, just didnt thought it will be that difficult.

Anyway, I have something more important for my program:

I would like to write text messages into the simulator using the offset 3380.

I just doesn't get string(text) inputs work...

I have done this code:

    Dim writetxt As String
    writetxt = "Test"
    Call FSUIPC_Write(&H3380, 1, VarPtr(writetxt), dwResult)
    Call FSUIPC_Process(dwResult)

Doesn't work :?

Thanks in advance,

Omer.

Share this post


Link to post
Share on other sites

Here,

    Dim writetxt As String
    Dim delay As Integer
    delay = 4
    writetxt = "test"
    Call FSUIPC_Write(&H32FA, 2, VarPtr(delay), dwResult)
    Call FSUIPC_Process(dwResult)
    Call FSUIPC_WriteS(&H3380, 1, VarPtr(writetxt), dwResult)
    Call FSUIPC_Process(dwResult)

Thanks!

Omer.

Share this post


Link to post
Share on other sites

writetxt - "test"

writetxt = Left(writetxt , 127)

writetxt = writetxt & vbNullChar

j = 4

Call FSUIPC_WriteS(&H3380, Len(writetxt ), writetxt , dwResult)

Call FSUIPC_Write(&H32FA, 2, VarPtr(j), dwResult)

Call FSUIPC_Process(dwResult)

Share this post


Link to post
Share on other sites

I think i'll just give in with this one.

I'ts not that improtant for me, just didnt thought it will be that difficult.

What's difficult? Sending a control to FS? That only involves writing one number to offset 3110. I don't understand.

I just doesn't get string(text) inputs work...

I have done this code:

    Dim writetxt As String
    writetxt = "Test"
    Call FSUIPC_Write(&H3380, 1, VarPtr(writetxt), dwResult)
    Call FSUIPC_Process(dwResult)

Doesn't work :?

Apart from the fact that I think, for VB, you need to use FSUIPC_WriteS (for Write String), and also that you have used a length of 1 byte for what looks like a string of 4 characters (plus terminator, so 5), I'll have to leave this to a VB programmer. I think VB uses a completely different string format to FS (and to Windows for that matter). Both Windows and Flight Sim use 8-bit ASCII encoded characters with a zero byte at the end terminating the string. I think VB normally uses 16-bit wide characters or Unicode with a length byte at the start.

There are more things put in place to trip up VB programmers than in any other language you can use. Sometimes I think even Assembly code would be easier! ;-)

Pete

Share this post


Link to post
Share on other sites
writetxt - "test"

writetxt = Left(writetxt , 127)

writetxt = writetxt & vbNullChar

j = 4

Call FSUIPC_WriteS(&H3380, Len(writetxt ), writetxt , dwResult)

Call FSUIPC_Write(&H32FA, 2, VarPtr(j), dwResult)

Call FSUIPC_Process(dwResult)

Thanks!!

Works as magic!!

What about current aircraft name?

I've tried the offset 3D00, but it returns me some strange numbers:

Dim tst As String
Call FSUIPC_Read(&H3D00, 1, VarPtr(tst), dwResult)
Call FSUIPC_Process(dwResult)
MsgBox tst

What's difficult? Sending a control to FS? That only involves writing one number to offset 3110. I don't understand.

It wasn't what I ment anyway,

nevermind, Really thanks Pete!

Thanks,

Omer.

Share this post


Link to post
Share on other sites

There are more things put in place to trip up VB programmers than in any other language you can use. Sometimes I think even Assembly code would be easier! ;-)

Pete

Well C (or C++) would be a nice compromise, I would never ever use VB! ;-)

Share this post


Link to post
Share on other sites

What about current aircraft name?

I've tried the offset 3D00, but it returns me some strange numbers:

Dim tst As String
Call FSUIPC_Read(&H3D00, 1, VarPtr(tst), dwResult)
Call FSUIPC_Process(dwResult)
MsgBox tst

Well, first you are only reading 1 byte, which would only contain the first character in any case -- please do check the sizes of the various offsets, these are shown in the table. You cannot get many Aircraft names in 1 character!

Anyway, it probably wouldn't come out correctly in any case because of the strange way strings are formatted in VB. I think you need code to deal with it. Hopefully, as before, you will get a VB programmer to show you.

I hate to keep saying this, but VB is a big pain for me and support. In C, C++, Delphi, even Assembler, it would all be so straightforward! ;-)

By the way, I hope, when you have these things figured out, that you are not doing "Read/Process" pairs all the time. It would be extremely inefficient, both for you program and for FS. You want to bunch all your Reads and Writes then do one Process call to send all the requests over to FSUIPC in one visit.

Regards,

Pete

Share this post


Link to post
Share on other sites

writing something from scratch here

say you want a 12 byte string

dim t as string

dim s(12) as byte

Call FSUIPC_Read(&H3D00, 12, VarPtr(s(1)), dwResult)

Call FSUIPC_Process(dwResult)

t = ""

For j = 1 To 12

If s(j) = 0 Then Exit For

t = t & Chr(s(j))

Next j

MsgBox s

Share this post


Link to post
Share on other sites
writing something from scratch here

say you want a 12 byte string

dim t as string

dim s(12) as byte

Call FSUIPC_Read(&H3D00, 12, VarPtr(s(1)), dwResult)

Call FSUIPC_Process(dwResult)

t = ""

For j = 1 To 12

If s(j) = 0 Then Exit For

t = t & Chr(s(j))

Next j

MsgBox s

Working! the only problem was that you needed to do msgbox t not s :) but I fixed that.

Thanks!

By the way, I hope, when you have these things figured out, that you are not doing "Read/Process" pairs all the time. It would be extremely inefficient, both for you program and for FS. You want to bunch all your Reads and Writes then do one Process call to send all the requests over to FSUIPC in one visit.

So you mean for best performance of FS and my program I should make a single proccess for multiple read / write actions?

Thanks,

Omer.

Share this post


Link to post
Share on other sites

So you mean for best performance of FS and my program I should make a single proccess for multiple read / write actions?

Yes, isn't that what I said? Sorry.

The whole reason the FSUIPC_Read and FSUIPC_Write calls are separated from the FSUIPC_Process call is to allow you to read and write more than one little item at a time.

The FSUIPC_Read and FSUIPC_Write calls are really nothing whatsoever to do with FSUIPC. They are just supposed to make life easier in your programs (though in the case of VB they may be making it harder by the look of it!). All the code for those procedures is inside your program.

The only call which deals with FSUIPC is FSUIPC_Process. That sends a specially formatted message to FS which causes a Process Switch (i.e. your program loses the processor, FS gains it) and allows FSUIPC to process all the read and write requests you queued up. The process switching takes A LOT LONGER that the processing of the reads and writes is likely to -- the latter are rarely as much as 1 millisecond (thousandth of a second) altogether, whereas the process switch could easily cost as much as 10 or 100 milliseconds, an order or two more.

So, if you request 10 items separately, i.e. each with their own Process call, you could be using up 1000 milliseconds just for process switching (time wasted to both your program and FS), plus the 1 millisecond (max) for the actual work requested, instead of 100 milliseconds for the one process switch plus the 1. The more stuff you ask for so inefficiently the more processor time you waste.

Regards,

Pete

Share this post


Link to post
Share on other sites

Hello,

I know this topic is reallllllly olddd but i hope for an answer.

How we know what is the code to catch te funcion i mean if i want the Heading off the aircraft what will be the code?

for the Altitude is Dim GndAlt As Integer and for the heading?

i mean there is any list whith all the aircraft funcions codes?

Share this post


Link to post
Share on other sites

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

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