Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi everyone.

I have downloaded the FSUIPC SDK and read the notes, but it's a bit too advanced for me :-(

I have done some very simple programming in VisualBasic, but never anything that either reads from, or writes to, another application or a memory location.

Can someone help me with the way to approcah reading a value from FSUIPC to use in a VB application? Let's say I just wanted to read the Airspeed and display it as a number - just like FSlook does, only with the number changing as it changes in FS..... how would I go about this? Are there any tutorials out there that can be recomended? Anyone got a well commented chunk of cide from their very early days I can see? :-)

Thanks,

Richard

Posted

Richard,

Using the FSUIPC SDK "Hello" example from my VB conversion of the SDK, replace the code in the "Private Sub Timer1_Timer()" function as follows:

Private Sub Timer1_Timer()

Dim dwResult As Long
Dim iIAS128 As Long
Dim fIAS As Single

Call FSUIPC_Read(&H2BC, 4, VarPtr(iIAS128), dwResult)
Call FSUIPC_Process(dwResult)

fIAS = iIAS128 / 128
lblClock.Caption = "IAS is " & fIAS

End Sub

There are various other posts on this forum concerning the basics of reading and writing to various locations within FSUIPC from VB, it might be worth clicking on Search and browsing around other examples. However, what this simple example does is this: from the FSUIPC for Programmers document we can see that the airspeed offset is at location 02BC, which in VB means &H2BC or in Delphi means $02BC. We can also see that the number of bytes FSUIPC would wish to be able to fill when this offset is requested by a program would be 4 bytes. Thus, we have declared iIAS128 as a "Long" type above (a Long type in VB is a 4-byte variable, capable of holding a value from -2,147,483,648 to 2,147,483,647, and thus will easily satisfy our needs for an airspeed value). However, the description of what is obtained from &H2BC in the document says we can expect the airspeed in knots multiplied by 128. Thus the value returned to us will be 128 times greater than the actual airspeed in knots, and so I have chosen to declare an additional variable, fIAS, as a Single type (a floating point type) to hold the conversion to knots.

The calls to FSUIPC_Read and _Process are standard stuff. _Read requests that FSUIPC puts data held at location &H2BC into our variable iIAS128, and requests that it fills the variable with 4 bytes of info from this location (ie. it fills the whole iIAS128 variable). _Process activates the request in FSUIPC, and if successful, the iIAS128 variable now contains the airspeed value multiplied by 128. A quick division by 128 gives us the IAS in actual knots, and the value is output to the label on the form. As all this is in a timer, this entire procedure will be repeated every half second (timer interval is set to 500ms).

Hope this helps your understanding, apologies if it's too simple. Browsing other posts in this forum or doing a search should reveal you some more examples of reading and writing various values.

Chris

Posted

Thanks a lot Chris..... no, not too simple at all - in fact I had to read it more than once and refer to my VB textbook to figure out what the 'dwResult' was for / was doing ! :-)

However, one of the main reasons I'm doing this myself is to learn more advanced programming than the "Hello World" stuff I've tried so far, and I always find that stuff 'sticks' better if I have to work a bit at understanding it.

Thanks again,

Richard

Posted

Just another quick note Chris.... thanks again for the help, I was not only able to get the speed to display, but was able to get two other instrument readings in the same form :-)

Now comes trying to derive the code to display those numbers graphically :-(

Richard

Guest Macs
Posted

Yikes,

You mean Vector Grahpics? That certainly wont be easy...;)

Posted

I'm trying to think of a easy way to display a 'virtual gauge', and had an idea. Before I do a bunch of making image files, though, will it even work?

My idea is to use a bitmap of a whole panel as the background image to a form, then to load 360 very simple single color bitmaps of a needle, with a transparent background, each showing the needle pointing at a one degree different angle. I'd then use a "Select Case" routine to display the needle picture that corresponded to the angle I wanted to show.

My question, to those who are familiar with Visual Basic, is whether or not the bitmaps of the needle could refresh fast enough to 'keep up' with the 500ms rate of the timer control?

I realise that that would be hardware dependant, but I'm trying to make something that can run with a very basic hardware setup - the laptop I want to use is a P233 with a 4mb video card.

Thanks for any suggestions / advice,

Richard

Posted

It might be OK, although if you are planning on doing this with the standard GUI Windows graphics calls then it might well be slow on a P233. That said, a half second update rate might be OK - try an experiment and see. Bitmap resolution, and needle bitmap size/memory will also affect update rate.

There are other more efficient ways to make your own "virtual gauges" but if you are not too familiar with VB or programming in general, I'd stick to your idea and give it a try first.

Chris

Posted

Well, it didn't really work out :-(

Using 1' different bitmaps of the needle, with the timer running at 500ms, actually gave a fairly nice smooth movement to the heading indicator (The only one I tried it with)

The problem was that the heading gauge as displayed on the client was about 3 - 4 seconds behind the same gauge on the panel displyed on the server. Except in a sharp turn that might not matter too much - but three or four seconds delay on the artificial horizon would be totally unaccptable.

Posted
The problem was that the heading gauge as displayed on the client was about 3 - 4 seconds behind the same gauge on the panel displyed on the server. Except in a sharp turn that might not matter too much - but three or four seconds delay on the artificial horizon would be totally unaccptable.

What are you using to get such a delay? If this is with WideFS, there's something strange going on in your code -- there are many folks using cockpits powered by Project Magenta, using WideFS with multiple clients, and the PFD/AI/ND et cetera run at the same frame rate as FS. In fact since version 5 that's exactly what WideFS is designed to do -- send every Client updates at the FS frame rate. The latency is just a few milliseconds.

Pete

Posted

I'm using WideFS. The code that generates the gauge is Chris' "hello" example from the SDK, except that I've :-

1) Modified it to display the heading instead of the clock, and

2) Added an image box. I've then done a "select case" after the code that displays the heading as a number. The code just sets the imgHeading.Picture property to 1.bmp, 2.bmp, 3.bmp, or whatever the value of the heaing value is. Each bitmap is a small monochrome bitmap image of a needle, rotated to the relevant angle.

Richard

Posted
I'm using WideFS. The code that generates the gauge is Chris' "hello" example from the SDK

Hmm. I don't know it, maybe Chris will chip in here, but you'll need to check its "cycle" time and what your code is doing to find out where those extra seconds are coming from. Certainly WideFS will be easily capable of sending updated values at rates similar to FS frame rates -- in fact you can get the WideClient frame rate displayed in its title bar -- there's an option for that in the INI. Check the dox.

Project Magenta would be out of business if its instrumentation was several seconds out rather than pretty well instantaneous, and its Autopilot, running on a separate PC, would lose control in no time!

Regards,

Pete

Posted

I have no idea what was causing the lag..... but it's gone away.

I suspect the firewall software in the router through which the computers are connected, because it's done funny things before. :?

Now my simple black compass needle follows the reading displayed on the FS2002 whisky compass perfectly.

(I used the whisky compass rather than the heading just because FS2002 puts the actual heading in the whisky offset, but heading * 360 / ( 65536 * 65536) in the heading indicator offset, but now I know t works I'll change the offset and do the math to get the actual heading out.)

500ms timer and 1 degree increments seem to be fine - the movement looks smoth enough to me. Now to draw 360 pretty dial faces :(

(OK, draw one and use an image program to rotate it 1' 360 times )

Richard

Posted
I have no idea what was causing the lag..... but it's gone away.Now my simple black compass needle follows the reading displayed on the FS2002 whisky compass perfectly.

Okay, good.

(I used the whisky compass rather than the heading just because FS2002 puts the actual heading in the whisky offset, but heading * 360 / ( 65536 * 65536) in the heading indicator offset, but now I know t works I'll change the offset and do the math to get the actual heading out.)

Don't forget the whiskey compass, being magenetic/mechanical, doesn't read accurately except when flying straight and level. If you want your compass to behave like that then that's fine, but don't rely on it in turns, climbs, descents, or at least make the appropriate allowances if you do.

If you want it instead to behave like the gyroscopic heading indicator then you should use the heading instead, but adjust it for gyro drift (offset 0C3E) for more realism.

Regards,

Pete

  • 3 weeks later...
Posted

If I may interject, here, I may be able to provide some insight. First, I'm not sure if you're intending to create a useful product, however, it has promise. Instead of using 360 images, which can seriously degrade performance and memory usage, you might want to get into doing DIB programming. DIB (Device Independent Bitmap) programming would allow you to literally take one image and rotate it in the desired angle. Now, don't get me wrong, we're not talking DirectDraw. DIB is built into windows. I think I'll make a sample project in VB and show you. I'll provide all the code and assets with it and upload it.

Catchya later! :D

Jim

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.