• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

VB.NET Simconnect Examples

re: simconnect examples

Thanks for your examples carthorse. I have created a 2 page form. Opening screen is basic switches and connection, and, clicking on a button will open form 2 which is a set of trackbars (4) which operate ailerons, elevator, and throttle - the rudder doesn't seem to want to connect however.

The problem I have is that my trackbars are only working on one side of the scale. That is... simconnect states values of -16383 to +16383 for its aileron axis etc.

If I use a trackbar min value of -16383 and max value of +16383, I receive a "divide by 0" error when I run the program in debug mode and operate the control.

If I use a trackbar min value of 0 and max value of 16383 hoewever, the control works fine through half of its range. (That is, the elevators will only go down, the ailerons will only go to the left, and the throttle will only operate between 50% and full power.

The attached file shows an image as well as the code for form 2 (it will work seperate from the main form)

the project was written in VB 2005 Express and I am in no way an expert... programing started as a hobby a year or two ago... I have a lot to learn. If anyone out there has any ideas as to how to approach my trackbar problems... it'd be great to hear from you.

Daryl Lowey
 

Attachments

Last edited:
The problem I have is that my trackbars are only working on one side of the scale. That is... simconnect states values of -16383 to +16383 for its aileron axis etc.

If I use a trackbar min value of -16383 and max value of +16383, I receive a "divide by 0" error when I run the program in debug mode and operate the control.
One potential solution is for you in your code to add 16384 to the values returned from SimConnect before you use them in your program. This means that the values will go from a minimum of +1 to maximum of +32767 (rather than -16383 to +16383) and as they are all postive you will not get a divide by zero. You obviously reverse the process if you are writing back to SimConnect i.e. you do your calculations and then subtract 16384 before you write it back.

Jeff
 
Thanks QuantumLeap, but I've already tried that. Problem is, the end value being passed on to Simconnect is still in a range of 1 to 16383 which will only pass one half of the range of motion for throttle, aileron etc.

Problem I think is that the statement used "fsx_simconnect.transmit client event" will only accept a uinteger which will only pass a range of values between 0 and 4,9xx,xxx,xxx. No matter how I calculate prior to the statement.. the end value going to simconnect must be posetive.

The fsx_simconnect.transmit client event works well though for passing boolean values (such as lights or gear toggle) which only require that I pass a value of 0 or 1.

I will have to run through the documentation to see if i can find a statement that will pass a wider range of values to operate ailerons etc.
 
Freshly developed

Good Day all;
I thought I would pass along my program to gather opinions.

Written in Visual Basic, the program will connect to FSX and provide gear up down, mixture, master on, alternator/generator on, avionics on, full flaps sequence, lighting, and Camera Views.

Once started, the program runs in 'always on top' mode however I have placed an opacity selection on it. At 20% opacity, you can barely see it however it remains functional and your FSX screen is fully visible.

My pride in the program has to be the camera views. Views provided are front, front left, front right, left, right, rear, rear left, rear right; and function with a mouse over event. (Directional views work in all modes) Eventually, I will convert all 'buttons' to mouse hover events so that focus is not taken away from the FSX program.

Due to the always on top function of the program, and the mouse over events, all view selection works without taking 'focus' away from the Flight simulator.

I don't have a view hat, so its nice to have the view commands readily available just by moving my mouse a bit. If you like, the program screen can be re-sized so that only the view functions are visible. This will leave you with a transparent window on screen approximately 2.5 inches tall by 2 inches wide.

I have the program installed and working on my laptop (Windows Vista) as well as my desktop (windows XP).

The program will continue to grow as I become more familiar with Simconnect and Visual Basic. Eventually, I will be putting slide controls on to operate control surface axis etc. Once I've figured that out... I will be writing phidget components into it so that switches, axis etc will all be operated externally through Phidgets.

Installs with the setup program, and uninstalls through your control panel. It will be in the control panel titled "PhidgetConnect"

Enjoy...
Daryl Lowey
 

Attachments

Last edited:
"fsx_simconnect.transmit client event" will only accept a uinteger which will only pass a range of values between 0 and 4,9xx,xxx,xxx. No matter how I calculate prior to the statement.. the end value going to simconnect must be posetive.

Ran into a similar problem in C# and I now use this trick:

Int32 valueToSet;

if ( valueToSet >= 0 )
{
ClientEvent(...., (Uint32)valueToSet, ...)
}
else
{
UInt32 valueAbs = (UInt32)Math.Abs(valueToSet)
ClientEvent(...., UInt32.MaxValue-valueAbs, ...)
}

This way the compiler sees a nice UInt32, but the internal representation matches the Int32 you need and this is what FSX will see.

Daniel
 
Hi Denial... tried your code (converted to vb express) and a number of variations to it, but nothing seemed to work.

Not a reflection on your information, but rather, on my own understanding and abilities.

I probably have to add a function in somewhere and then call that. I'll keep working on it.

Thanks

Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.Scroll
Dim valueToSet As Int32

If valueToSet >= 0 Then
ClientEvent(...., CType(valueToSet, Uint32),...)
Else
Dim valueAbs As UInt32 = CUInt(Math.Abs(valueToSet))
ClientEvent(...., UInt32.MaxValue-valueAbs,...)
End If
fsx_simconnect.TransmitClientEvent(1, SimEvents.Elevator_0, valueToSet, NOTIFICATION_GROUPS.GROUP0, SIMCONNECT_EVENT_FLAG.DEFAULT)

End Sub
 
Ah, I see where I was a bit too cryptical :) Here are my actual calls in C#:

Code:
// Pass +10 as parameter:
simconnect.TransmitClientEvent(0, EventEvent.SomeEvent, 10, EventGroup.FollowMe, 0);

// Pass -10 as parameter:
simconnect.TransmitClientEvent(0, EventEvent.SomeEvent, UInt32.MaxValue - 10, EventGroup.FollowMe, 0);

I see I'm using 0 (SIMCONNECT_OBJECT_ID_USER) as the first parameter in my calls versus your 1.

Daniel
 
Back
Top