Jump to content
The simFlight Network Forums

FSUIPC-VB6 Users Need Help


Recommended Posts

Guys,

To let you know... The only part of VB languages/codes that I am expert is based on office use such as: Excel, database entries, calcuations, and etc. BUT I have no knowledge on implementing for game or enterainment related programs and may need all of your help to use it for my future benefit. So PLEASE bear with me especially with all of "probablly" stupid asked question. I am only try to learn here.

So after Registered FSUIPC and WideFS.... I did a few experiment creating form layout with one Label box and of course one button box (to end connection with FSUIPC/FS2002 to prevent from it crashing). The Label Boz which left blank will display (IAS) Indicated Air Speed with Offset Value of 02BC (found on FSUIPC Manual). So, let take a look at below of codes tor language I wrote:

FORM CODES:

Private Sub btnDiv_Click()

Unload IStation

End Sub

--------------------------------------------------------------

Private Sub Form_Unload(Cancel As Integer)

FSUIPC_Close

End Sub

---------------------------------------------------------------

Private Sub Timer1_Timer()

Dim ISpeed As Long

Dim dwResult As Long

Call FSUIPC_Read(&H2BC, 4, VarPtr(ISpeed), dwResult)

Call FSUIPC_Process(dwResult)

IASpeed.Caption = ISpeed

End Sub

And I did a little revison on General.BAS module.

GENERAL BAS Module

Option Explicit

Public ResultText, SimulationText

Sub Main()

Dim dwResult As Long

' set VB "constant" string refs dynamically now ready for result

'messages

ResultText = Array("Okay", _

"Attempt to Open when already Open", _

"Cannot link to FSUIPC or WideClient", _

"Failed to Register common message with Windows", _

"Failed to create Atom for mapping filename", _

"Failed to create a file mapping object", _

"Failed to open a view to the file map", _

"Incorrect version of FSUIPC, or not FSUIPC", _

"Sim is not version requested", _

"Call cannot execute, link not Open", _

"Call cannot execute: no requests accumulated", _

"IPC timed out all retries", _

"IPC sendmessage failed all retries", _

"IPC request contains bad data", _

"Maybe running on WideClient, but FS not running on Server, or wrong FSUIPC", _

"Read or Write request cannot be added, memory for Process is full")

SimulationText = Array("Any", "FS98", "FS2K", "CFS2", "CFS1", "FLY", "FS2002", "FSNEXT", "FSYETANOTHER")

' initialize important vars for UIPC comms - call only once!

FSUIPC_Initialization

' Try to connect to FSUIPC (or WideFS)

If FSUIPC_Open(SIM_ANY, dwResult) Then

' Connected to simulator (visible in the form's caption)

IStation.Caption = IStation.Caption & ResultText(dwResult)

' Enable the timer which is actually reading the FS clock time

IStation.Timer1.Enabled = True

Else

' Unable to "Connect"

IStation.Caption = IStation.Caption & "Can't connect: " & ResultText(dwResult)

End If

IStation.Show

End Sub

So I full comple it, No error indicated..

I run FS2002.. and I had succesful connection.. between Form I created to FS2002. So that would make a first check mark on few step-by-step agendas.

Now there is a problem:

From FS2002 I show IAS at '248' knots....

From the form I created, I show IAS was at '31997'

Something is wrong, so what may be wrong? Isn't that because I wrote wrong language? I confirmed offset was correct.... What did I forget to add? what do I need to do to solve this problem getting IAS from the form to be matched with FS2002 ?

Thanks in Advance

Arthur

Link to comment
Share on other sites

Hi,

in my opinion:

--------------------------------------------------------

Private Sub Timer1_Timer()

Dim ISpeed As Long

Dim dwResult As Long

If FSUIPC_Read(&H2BC, 4, VarPtr(ISpeed), dwResult) Then

If FSUIPC_Process(dwResult) Then

IASpeed.Caption = Format(ISpeed/128,"0")

End If

End If

End Sub

--------------------------------------------------------

Bye bye

Armando chibante

Link to comment
Share on other sites

That's tight, Armando.

The only change I'd suggest is moving the Dim statements outside the timer Sub.

At the moment, every time the Timer loops the variables are re-Dim'd. No biggie for just two variables, but when the app grows it'll give a bit of a performance hit.

Richard

Link to comment
Share on other sites

Armando,

Thanks for the input... I did thought of that first place but wasn't sure how to implement it. With your help it worked. Thanks again Buddy

Richard

I have tried to find such place to put DIM statement: DIM ISpeed as long somewhere else before timer but I couldn't think of any... Would I need to include:

Private Sub Click()

DIM ISpeed As long

DIM dwResulr As Long

end sub

This was the first try I did, and instead of that I get an error defined.

Richardo, Armando, or anyone

Now I suppose, Value of 1= on 0=off (for landing light, strobes, warning light or etc) could be implement as:

LandingLight.Label = Format(LLInd 1,0,"0")

or something?

Any ideas??

Link to comment
Share on other sites

Easiest place to put the DIM statements is in the Form_Open sub.

Yes, you can do that with the 1 / 0 value for a label caption, but a better looking way is to make the label, say, dark green with a gray caption if the value is 0, and bright green with a black caption if it's 1. If you look at, say, the gear lights on my FSEicas app, that's how I implemented them.

Richard

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

I'm a Mechatronic Student of Colombia, and i'm restoring a very old simulator named GAT 1.

The main idea is to use MSFS as simulation software.

It's very important for me to adquire the pitch, heading and bank from MSFS and to send some signals to offests of MSFS.

I have some SDK examples, one of them named FSinterrogate by Pete Dowson and works very good, but the VB5.0 code don't runs and i don't know what's happening with VB6.0, also i used a program that shows the local time and it always shows 00:00:00. What can be the reason because it doesn't works?

If you have some code examples that run good, please send to me.

Thanks a lot

Cali - Colombia.

Link to comment
Share on other sites

  • 8 years later...

Hello Anyone, did you ever get FSUIPC to communicate with Excel's VBA? I got it to work with VB6 but not Excel. I don't have any runtime errors reported but also no data is coming in. I keep getting an error: dwResult = 9, which is "link not open." Thanks. Oops, nevermind, got it to work! 1) deleted the BitwiseOps.bas, 2) cleaned up FSUIPC.bas and General.bas and instead of using the form timer object (required by VB6), I call(ed) my module. I haven't attempted to Write to FSUIPC but that's next.

Link to comment
Share on other sites

okay.... what is a crikey? Yes, I use Excel for just about everything !!! Probably the only thing I don't use it for is word-processing. I use it for color analysis to ensure consistent pigment , real GPS input for my own "FMC", HMI for PLC programming, and now that I can receive joystick input, found a really cheap way for I/O. Plus many, many other uses. If Mr. Dowson reads, this, I was accessing offset 2B00 (gyro compass) and I found out that as I turn around, the numbers received vs degree heading is not linear, what is the formula to get from FS so I can get degrees for heading? Thanks.

Link to comment
Share on other sites

I was accessing offset 2B00 (gyro compass) and I found out that as I turn around, the numbers received vs degree heading is not linear, what is the formula to get from FS so I can get degrees for heading?

No formula needs. As stated in the documentation, 2B00 is already in degrees, as a 64 bit double floating point value. If you treat the 8-byte value you get correctly, it will read correctly. Please use the documentation (offsets lists) which tell you these things.

Pete

Link to comment
Share on other sites

Hello, well I hope you know that I DID read and I also used FSInterrogate which suggests the same info. But it does not work. I even derived information from the FSUIPC_SDK's file ReadThisVB.txt by Stuart Browne and I was able to get the altitude (0570) to work great but not 2B00. This is what I attempted (plus other modifications of * 360, π/180,180/π,65536 etc., - to no avail):

Dim HI64 As Currency

Dim HI As Double

If FSUIPC_Read(&H2B00, 8, VarPtr(HI64), dwResult) Then

If FSUIPC_Process(dwResult) Then

HI = HI64 * 10000#

Range("a7") = HI

I get some really large number (despite the HI64 * 10000# => converts from currency to double) and that would be okay if that number was linear to the actual heading - then I could determine the formula. I found out that when I go from a heading of 360° and turning right back to 360° that the difference say, between 360° to 1° is very relatively large number compared to 359° to 360°. As I turned right, I took readings of every 30° and looked at the numbers received and then took the difference and the resultant started large but got progressively smaller as I came about to 360°. By the way, here is the code for altitude and again, it works great:

Dim Altitude64 As Currency

Dim Altitude As Double

If FSUIPC_Read(&H570, 8, VarPtr(Altitude64), dwResult) Then

If FSUIPC_Process(dwResult) Then

Altitude = Altitude64 * 10000#

Altitude = Altitude * 3.28084 / (65536# * 65536#)

Range("a5") = Altitude

Also, I have no idea what Heading (0580) is sensing. I have the heading bug set at 330°, the heading indicator shows 330°, the whiskey compass show 330° [shft]-z shows 330° but FSInterrogate shows 350° and input to spreadsheet shows 350°, I suspect it's true heading since I have a magvar of 23° but then shouldn't I be reading 353°, is this only viable for slew mode?

... so a bit confused.

Still confused about why the 2B00 doesn't work and what the [shft]-z shows is a mag var of 23° but the FSUIPC/FSInterrogate is showing 20° so that makes sense now - sort of (I was in KSEA area). Heading is True Heading. So given the MagVar and TH, I can derive the Mag Heading, would have rather received it directly though. As I may have stated before, it's too bad I got into FSUIPC so late. It wasn't until I got unhappy with Saitek really that made me motivated to learn FSUIPC. Quite happy with FSUIPC too! Not only do I have the button controls I like, ...NOW ..... I can do something else that I've been wanting to do for a very long time and that is test/teach PID controls. There are various simulators out there, including for Excel but none of them, within reasonable cost, can interract with "real" world. With FS2004, FSUIPC and Excel, I can show and see not only the results through the flight sim, I can see the interaction through the charts in "real" time.

Link to comment
Share on other sites

Mr Guitar

Here is the code I wrote for getting the current heading of the aircraft taken from my aircraft class module. You can see the calculations involved in getting this.



'heading'
Private fsCurrentHeading As Offset(Of UInt32) = New FSUIPC.Offset(Of UInt32)("heading", &H580)
Public CurrentHeading As UInt32

'magnetic variation'
Private fsMagneticVariation As Offset(Of Short) = New FSUIPC.Offset(Of Short)("magneticvariation", &H2A0) 'this is the heading of the aircraft'
Private MagneticVariation As Short

'gyrodrift'
Private fsGyroDrift As Offset(Of Short) = New FSUIPC.Offset(Of Short)("gyrodrift", &HC3E)
Private GyroDrift As Short

Public Sub getCurrentHeading()
'return aircraft heading'
FSUIPCConnection.Process("heading")
FSUIPCConnection.Process("magneticvariation")
FSUIPCConnection.Process("gyrodrift")
Me.CurrentHeading = fsCurrentHeading.Value * 360D / (65536D * 65536D)
MagneticVariation = fsMagneticVariation.Value * 360D / 65536D
GyroDrift = fsGyroDrift.Value * 360D / 65536D
Me.CurrentHeading = norm360((CurrentHeading + GyroDrift) - MagneticVariation)
End Sub
[/CODE]

and this function I use is from John Dekker from another posting yonks ago

[CODE]
Function Norm360(ByVal h As Short) As Long
'this function returns correct heading within 360 degrees'
If h > 360 Then
Norm360 = h - 360
ElseIf h = 0 Then
Norm360 = 0 'originally 360'
ElseIf h < 0 Then
Norm360 = h + 360
Else
Norm360 = h
End If
Return Norm360
End Function
[/CODE]

Link to comment
Share on other sites

I get some really large number (despite the HI64 * 10000# => converts from currency to double)

This is your problem. You didn't really properly read the documentation nor even my previous reply where I pointed out that 2B00 is a 64-bit floating point number, i.e. a double. It is NOT the same as the Lat/Lon values which are 64-bit fixed point nmbers (your "currency" would work for those). Just read 2B00 directly into a double. No conversion is needed, as I told you already! :-(

Pete

Link to comment
Share on other sites

Chill out please, I wasn't upset and more importantantly I was able to use heading (being True Heading) and applying Magnetic Variance to get the gyro compass (I wasn't concerned about drift - turned it off for testing), so I was able to get the info needed albeit, a round-about way I'll admit. You are right in that I did not catch the difference between 64 bit floating and 64 bit fixed. If the explanation of the datatypes are shown, please tell me where? In addition, as I may have mentioned before, I am now using FSUIPC, along with Excel to apply PID control theory. It took some reading up how to do charts of live data but got there. My question/observation is this: When I read 0BB8 (Aileron Position Indicator), the manual says: (may be adjusted from input), which would be fine (cuz not using joystick - unplugged) however, When I'm not sending 0BB8 info, the reading of 0BB8 also shows 0 even after in autopilot and making a heading bug change. Is there a direct reading of the actual aileron displacement? I suppose banking info might work but like to see direct aileron position. My PID is working ok, per 1/f4 wave damping but I would it rather control like the PID of FS and smooth out as the desired heading is near. I wanted to plot what the aileron position itself is doing.

Link to comment
Share on other sites

You are right in that I did not catch the difference between 64 bit floating and 64 bit fixed.

Really? Yet you declared these:

Dim Altitude64 As Currency

Dim Altitude As Double

and even stated your conversion:

I get some really large number (despite the HI64 * 10000# => converts from currency to double)

Even after I repeated what the documentation states, that 2B00 is a 64-bit floafing point value.

If the explanation of the datatypes are shown, please tell me where?

In the offsets list each value is described. I don't know what you are using, but against 2B00 in the official lists, the only ones i produce, it clearly states 64-bit floating point for this offset. That IS the explanation. If you want floating point defined you'll need to look it up elsewhere. It is a sufficient description for use in any language which supports the underlying intel processor architecture. I rarely use the term "double" because that is a C/C++ type, not a description -- I ddn't even know it was "Double" in VB6, but i am pretty sure it isn't using that word in all languages. Data type wors are language dependent.

My question/observation is this: When I read 0BB8 (Aileron Position Indicator), the manual says: (may be adjusted from input), which would be fine (cuz not using joystick - unplugged) however, When I'm not sending 0BB8 info, the reading of 0BB8 also shows 0 even after in autopilot and making a heading bug change.

Sorry, I don't know what you mean. Monitoring the value in 0BB8 I can see it changing constantly whilst the autopilot sets or changes heading. I'm using FSInterrogate to watch it.

Is there a direct reading of the actual aileron displacement?

Didn't you search the offsets list on the word "aileron"? You'd have surely found offset 2EA8, where I see that, contrary to my statement above, I did describe it as a double -- also a FLOAT64, which is of course a 64-bit floating point nmuber again.

Please do use search facilities in your PDF viewer. That's all I do when I need an offset. I don't remember them all, you know.

Pete

Link to comment
Share on other sites

Of course ! I did do a search (find) of "aileron position"and it ONLY showed 0BB8 up. I did not do a search of "aileron" by itself as I thought I was only interested in the aileron's position. I realize you can't possibly know all the offsets, just thought I'd ask in case I did miss something. Thanks for your time and info, always grealy appreciated. So glad for FSUIPC, wished I messed with it years ago. Heres' what's going to happen. I can now see and modify the PID parameters and watch the result in FS9. Next I'll being using a DC step motor connected to my yoke and see how it controls the FS9. Upon successful application of that, I will take the DC step motor and attach it to my airplane's (actually my brother-inlaw's) yoke and test the heading changes. It doesn't have an autopilot so here's perhaps an alternative for those long trips I take. Seems a bit bizarre, I agree, but worth a try.

Link to comment
Share on other sites

  • 2 weeks later...

An update, not sure what's going on with using PID so far. It works great as far as 1/4 wave damping and holds fairly well but I'm not able to get the critical damp desired. 1/4 wave damping is not a nice way to fly. So far my PID is a 1st order differential equation (DE) and my research seems to indicate that critical damping is 2nd order DE. This requires finding out the undamped natural frequency. WOH !!! and descreting a 2nd order DE in Excel - oh boy! I can see that the flight sim' autopilot does a good job of it though even though it seems that a person can only modify (in aircraft.cfg): nav_proportional_control, nav_integrator+control, etc. I don't' know what max_bank_acceleration/velocity does. So I'm not sure how the flight sim (FS9) is able to do this so well. When I fly in my real aircraft, I lead reducing the bank by the amount of heading difference that is left. As an example, if in my turn and I'm banking 10°, I'll begin to level off when my desired heading is within 10°. Not sure how to do this in Excel(VBA)/VB6 and use traditional PID. If there are parameters in FSUIPC that can assist, please let me know. Again, very pleased that FSUIPC allows me to test this.

--- another update in case it might help someone else. I came up with what I call "gr8guitar smoothing." Not too technical and not sure how it would work with pneumatic controllers but using Excel:

Output = p + i + d

' turn rate derived from GPS, Turn rate limit:

if abs(TurnRate)>=3 then ' 3 deg per sec

Output = -Output * .2 ' .2 seems to work well for turn rate limit

end if

' gr8guitar smoothing

if abs(Error)<= 10 then ' Error is setpoint heading vs. actual heading

Output = Error/10*Output ' thought of this after I wrote the above and works surprising well

end if ' still curious how FS does this and their PID algorithm

' aileron linkage required from stepper motor to the yoke to sufficiently move the real airplane's ailerons

Output = Output *5.2

In any case, I can at least more forward and not worry about the damping ratio, 2n order DE. <whew>

Link to comment
Share on other sites

  • 1 month later...

ah.... learned something new. After much flying, I observed the following: Using my PID, and as long as I was using heading as my setpoint, I only needed Proportional control only and it worked quite sufficiently to maintain an error of zero. I had been impressed how well flight simulator (fs2004) handled this but didn't understand why it worked so well. After learning about system "leakage", which leads to steady-state offset (honestly knew about it, just didn't get it) , I decided to just observe fs by itself when it's tracking a radial, i.e: in NAV mode instead of HDG mode and I observed that it follows more of what I thought I would see in a PID controller. In other words, it wasn't as clean as when it maintains just heading. I noticed that it does more "hunting" and especially if there is a crosswind (the system leakage) and the farther away from the VOR station. In fact, it actually does a pretty lousy job... This is what is great about FSUIPC, to be able to test. It was difficult for me to see "real world" application until now. Wow, to be honest , I'm beside myself because even working at a nuclear power plant, I was not able to "mess" with stuff and just observe (probably a good idea ;) ). Through the use of FSUIPC, this has become an amazing learning tool as well as be able to apply to real world application, my airplane. Aircraft are different than typical parameters seen at a power plant. I.E.: even after a heading change, the control variable/output (in this case, ailerons/rudder) have to be neutralized (opposite output and then no output) once in the turn (if less than 30° bank) even though there's still an error in heading as the plane continues to turn and then opposite output to level off to desired heading. What a challenge, at least for me.

Link to comment
Share on other sites

This is what is great about FSUIPC, to be able to test. It was difficult for me to see "real world" application until now. Wow, to be honest , I'm beside myself because even working at a nuclear power plant, I was not able to "mess" with stuff and just observe (probably a good idea ;) ). Through the use of FSUIPC, this has become an amazing learning tool as well as be able to apply to real world application, my airplane

I am pleased you are able to make such good use of FSUIPC. You seem to be well in advance of anything i know! ;-)

Regards

Pete

Link to comment
Share on other sites

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.