Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi Everybody,

I'm confused and can't find any solutions for my problem. I'm using VB6.0 for programming. I'm trying to read offset 6048 to get the distance to the GPS Active waypoint :

Dim gpsData As Byte ( CORRECTED By MAD SCHATZ )

ReDim gpsData(8)

If FSUIPC_Read(&H6048, 8, VarPtr(gpsData(1)), dwResult) Then

If FSUIPC_Process(dwResult) Then

.....

Now the value returned in gpsData array is like :

gpsData(0)=0, gpsData(1)=48, gpsData(2)=177, gpsData(3)=161

gpsData(4)=238, gpsData(5)=139, gpsData(6)=78, gpsData(7)=1

gpsData(8)=65

So now I don't know what to do with these numbers ! What must I do with these numbers ?

Does anyone have any suggestion ?

Posted

I'm not familiar with VB, co apologies if any of this is incorrect.

Dim gpsData As As Byte

As as byte? Should that read As Byte?

If FSUIPC_Read(&H6048, 8, VarPtr(gpsData(1)), dwResult) Then
     If FSUIPC_Process(dwResult) Then

Does the gpsData array have 8 elements? If so, it doesn't make sense for there to be a 0th and an 8th element. The indexing either runs from 0 to 7 or 1 to 8.

Now the value returned in gpsData array is like :

gpsData(0)=0, gpsData(1)=48, gpsData(2)=177, gpsData(3)=161

gpsData(4)=238, gpsData(5)=139, gpsData(6)=78, gpsData(7)=1

gpsData(8)=65

There are nine values there.

Furthermore, I've just looked in the FSUIPC programmers guide and I can't find any reference to offset 6408 (hex). Is this the correct offset?

Posted

Oops: my SDK was a couple of versions behind AND I was looking for the wrong offset. I now see the new FS2004 GPS offsets. (Pete has been very busy!)

Offset 6048 is correct and is specified in the SDK as a 8-byte floating point double. 8*8=64 bit double.

I've just had a look in the VB section of the SDK and found the information about handling 64-bit numbers in VB.

Dim Fake64Bit As Currency
Dim dwResult As Long
Dim Latitude As Double

  If FSUIPC_Read(&H560, 8, VarPtr(Fake64Bit), dwResult) Then
    ' "Read" proceeded without any problems
    If FSUIPC_Process(dwResult) Then

        ' First we need to multiply the fake64bit number held in the currency VAR by 10,000
        ' to remove the decimal point - remember to force the double (#) to avoid overflow

        Latitude = Fake64Bit * 10000#

        ' Now convert from FS units to degrees, again forcing the double to avoid overflow

        Latitude = Latitude * 90# / (10001750# * 65536# * 65536#)
    Else
      ' Unable to "Process"
      lblStatus.Caption = "Processing: " & ResultText(dwResult)
    End If
  Else
    ' Unable to "Read"
    lblStatus.Caption = "Reading: " & ResultText(dwResult)
  End If

Posted

Hi Jamie,

According to your suggestion I corrected my code. Now it looks like :

Dim lnData As Currency

Dim lnMiles As Double

Dim dwResult As Long

If FSUIPC_Read(&H6048, 8, VarPtr(lnData), dwResult) Then

If FSUIPC_Process(dwResult) Then

lnMiles= lnData * 10000#

lnMiles=lnMiles / (10001750# * 65536# * 65536#)

....

I don't know if the calculation is true. I did it according to the example. But I think that this calculation is used to calculate LATITUDE.

Also In the SDK it is mentioned that the value is in Meters, so I should have to make a convertion mtr -> nm.

While converting Mtr to NM, which value I should use to divide, 1.6 or 1.8 ?

Posted

Also In the SDK it is mentioned that the value is in Meters, so I should have to make a convertion mtr -> nm.

While converting Mtr to NM, which value I should use to divide, 1.6 or 1.8 ?

There are rather more that 1.8 metres in a nautical mile! Try dividing by 1852.

Why is the destination for the result declared as "currency"? Surely you want that to be a double float too?

Pete

Posted

Hi ,

I don't know how to handle " floating point double " in VB. So I try to apply the example which is on the FSUIPC VB SDK text file. It may be wrong but I don't know where did I make the mistake :oops:

Posted

I don't know how to handle " floating point double " in VB.

So what is "InMiles", as defined by:

Dim lnMiles As Double

? If "Double" in VB isn't the same as a "double" in C, what on Earth is it?

Sorry, I don't know VB, but perhaps you have some reference book you can look it up in? Seems essential to have some reference when using any language.

Regards,

Pete

Posted

If "Double" in VB isn't the same as a "double" in C, what on Earth is it?

I don't know, but if it was the same as C the whole snippet I posted wouldn't be necessary. The VB code I posted comes straight from the FSUIPC SDK and appears to be posted as a workaround for VB's apparent inability to handle 64-bit numbers. I'd guess VB's 'double' is maybe 32 bits?

lnMiles=lnMiles / (10001750# * 65536# * 65536#)

You don't need this line. It was in the example because the example offset used needs conversion to the right units. Your data is already in the right units, although if you want it in miles you need to divide by 1852, as Pete said.

Posted

Dear Mr. Pete,

I apologize for the inconvenience :oops: .

Everything is caused by confusion of terms. When Jamie sent the reply, I did try to solve the problem in that way. I had tought that "FLOATING POINT DOUBLE" is a different variable that can be use in C. Anyway by the help of Mr.Pete I realised where I did make the mistake. Now I solved my problem. Thank you for your help.

Posted

I don't know, but if it was the same as C the whole snippet I posted wouldn't be necessary. The VB code I posted comes straight from the FSUIPC SDK and appears to be posted as a workaround for VB's apparent inability to handle 64-bit numbers. I'd guess VB's 'double' is maybe 32 bits?

That seems very unlikely. I think you are maybe confusing the 64 bit FIXED point numbers in FS -- like Latitude and Longitude -- with 64-bit FLOATING point numbers. There are completely different formats. 64 bit floats are the standard type of floating point in Intel processors and as far as I know are supported in all languages. There's also a 32-bit float (in C called "float" rather than "double"). FS SDKs use the terms FLOAT64 and FLOAT32 for clarity.

There are problems with handling 64-bit FIXED point numbers in most languages unless they support "long long" or "__int64" like most recent C compilers. This format is not a native Intel format on its 32-bit processors, but presumably will be on the 64-bit ones, hence the addition to compilers with backward compatibility.

The latter is the reason there is an extensive explanation of a possible way of handling the Latitude and Longitude in the Programmer's Guide, but not in any of the double floating point cases -- no further explanation should be needed for the latter as it is a universally supported format.

Regards,

Pete

Posted

I think you are maybe confusing the 64 bit FIXED point numbers in FS -- like Latirtude and Longitude -- with 64-bit FLOATING point numbers

Yes, you're right. I hadn't made the distinction and was comparing latitude/longitude with this double float offset as if they were.

no further explanation should be needed for the [double floating point cases] as it is a universally supported format.

In the interests of clarity of the thread (I'm not a VB user): does this mean that double floating point offsets (eg 6408) can be read directly into a VB double?

Posted

In the interests of clarity of the thread (I'm not a VB user): does this mean that double floating point offsets (eg 6408) can be read directly into a VB double?

Yes, that's the whole point really. Whatever language you are using, it is best to read the variables into the correct types to start with. I've searched for info on VB and for floating point there are types "Double", "Single" and "Decimal" in VB6. I don't know what "Decimal" is but I'd be amazed if Double isn't the same as C's double or FLOAT64, and "Single" C's float (FLOAT32),

The only ones that may give problems in VB are the 64 bit fixed point numbers and, for some weird reason completely unfathomable to me, strings! (VB seems to have the worst most incompatible string system that could be invented, judging by the number of questions and problems this area causes).

However, from the same source which gave me "Double", "Single" and "Decimal" for VB6 (the book "Visual Studio.NET for Dummies"), it seems that VB6 also supports "Long" for 64-bit FIXED point numbers (!), and Short for 16-bit numbers, as well as the common Integer for 32-bit.

Otherwise, for the 4-, 2- and 1- byte values you can of course read them into a standard 32-bit Integer, but that must be initialised to zero first so that the unused bytes of the 4 are clear and don't give a false value -- some support queries have arisen from this being forgetten too.

Regards,

Pete

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.