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

[Initial Bit RESOLVED] VB.net and Simconnect

Angelus1971

Resource contributor
Messages
195
Country
scotland
Hi

I've been struggling for days over this one.

I've managed to get the Managed Data Request to work but what I cant do is even start to get code to insert an Object a/c or otherwise into the sim using Simconnect and VB.net.

Would anyone be able to drop me a few lines of code which would place an object in the sim. Some code that would help me learn and build on would be highly appreciated.

Thank You
 
Here is the C# Waypoint example in VB. You should try one of the other C# ones and convert them to VB. I just took the VB managed data and added the waypoint parts to it.

It is VS 2010 using NET 2

enjoy.
 

Attachments

Thanks for the file. It helped a lot. Just got to figure out a way of stopping the a/c from dropping 12000ft after adding which will allow a new heading and possibly altitude change to work properly. Cant use waypoints, data is live.
 
There are two parts to creating AI.

The Init part where you create the AI and give it initial position speed heading altitude. There is a parameter OnGround. Set it to false 0.

After you get the response that the AI is created - you get a SIMID - use that to set the way points.


Set the Init

Code:
        ' Initialize Extra300S aircraft just in front of user aircraft, at 47 25.89 N, 122 18.48 W

        Init.Altitude = 1433.0                   ' Altitude of Sea-tac is 1433 feet  <<---------------------------
        Init.Latitude = 47 + (25.91 / 60)       ' Convert from 47 25.90 N
        Init.Longitude = -122 - (18.48 / 60)    ' Convert from 122 18.48 W
        Init.Pitch = 0.0
        Init.Bank = 0.0
        Init.Heading = 360.0
        Init.OnGround = 0  <<---------------------------------------
        Init.Airspeed = 100  <<---------------------------------------

        fsx_simconnect.AICreateNonATCAircraft("Extra 300S Paint1", "N1001", Init, DATA_REQUESTS.REQUEST_Extra300S)

then set the waypoints

Code:
            ' Extra300S aircraft should fly in circles across the North end of the runway

            wp(0).Flags = CType(SIMCONNECT_WAYPOINT_FLAGS.SPEED_REQUESTED, UInteger)
            wp(0).Altitude = 800
            wp(0).Latitude = 47 + (27.79 / 60)
            wp(0).Longitude = -122 - (18.46 / 60)
            wp(0).ktsSpeed = 100

            wp(1).Flags = CType(SIMCONNECT_WAYPOINT_FLAGS.SPEED_REQUESTED, UInteger)
            wp(1).Altitude = 600
            wp(1).Latitude = 47 + (27.79 / 60)
            wp(1).Longitude = -122 - (17.37 / 60)
            wp(1).ktsSpeed = 100

            wp(2).Flags = CType(SIMCONNECT_WAYPOINT_FLAGS.WRAP_TO_FIRST Or SIMCONNECT_WAYPOINT_FLAGS.SPEED_REQUESTED, UInteger)
            wp(2).Altitude = 800
            wp(2).Latitude = 47 + (27.79 / 60)
            wp(2).Longitude = -122 - (19.92 / 60)
            wp(2).ktsSpeed = 100

            ' Create a polymorphic array

            Dim objv1 As Object = New Object(wp.Length - 1) {}
            wp.CopyTo(objv1, 0)

            ' Send the three waypoints to the Extra300S
            fsx_simconnect.SetDataOnSimObject(DEFINITIONS.Extra300SWaypoints, Extra300SID, 0, objv1)

My livingworld program basically does that.
 
Thanks

My program seems to be OK but I need better control over the a/c.

How do I use FREEZE_Events in vb. I cant seem to find the FREEZE_ALTITUDE_SET or figure out how to us

What I'm looking for is

setUpSimObjects();
/* action in callback */
hr = SimConnect_TransmitClientEvent(hSimConnect, SIMCONNECT_OBJECT_ID_USER, KEY_FREEZE_LATITUDE_LONGITUDE_TOGGLE, 0, SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
hr = SimConnect_TransmitClientEvent(hSimConnect, SIMCONNECT_OBJECT_ID_USER, KEY_FREEZE_ATTITUDE_TOGGLE, 0, SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
hr = SimConnect_TransmitClientEvent(hSimConnect, SIMCONNECT_OBJECT_ID_USER, KEY_FREEZE_LATITUDE_LONGITUDE_SET, 0, SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
hr = SimConnect_TransmitClientEvent(hSimConnect, SIMCONNECT_OBJECT_ID_USER, KEY_FREEZE_ALTITUDE_SET, 0, SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
hr = SimConnect_TransmitClientEvent(hSimConnect, SIMCONNECT_OBJECT_ID_USER, KEY_FREEZE_ATTITUDE_SET, 0, SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);

in managed vb code please
 
Last edited:
Not sure what you mean. The altitude is set via the waypoint.

wp(1).Altitude = 6000

It will fly to that waypoint at 6000 feet.

You can also give your aircraft a flight plan. You create a flight plan with your user aircraft - save it. You can then use it via

SimConnect_AICreateEnrouteATCAircraft

This will start the aircraft at location A taxi, take-off and land (or TNG and return), taxi to gate per the flight plan.
 
I'm pulling data for the next waypoint from a LIVE system. Actual speeds, headings, locations are not filed. Cant use a flightplan or anything as each flight is dynamic.
Each Latitude and Longitude is transmitted to the FSX a/c with 1 second of it getting transmitted from the REAL a/c.

At the moment, I've got FSX being injected with the initial locations and have managed to get the altitude to now remain stable. The pitch goes kind of crazy but it does revert back to normal flight.

What I'm looking for it to get the plane to move to the next waypoint by not moving under the control of the AI. Not sure how to move it to the next position. Do I use waypoints as per the other AI controlled method?

All I get when I send the waypoint data is

SIMCONNECT Exception 19 which is SIMCONNECT_EXCEPTION_INVALID_DATA_SIZE = 19

Not sure what data size is wrong as I'm only feeding the data which your and other people examples transfer
 
Last edited:
Back
Top