Sign in to follow this  
Guest Mikeinca

VB.Net and SimConnect TransmitClientEvent

Recommended Posts

I have been programming with VB6 for a long long time and want to make something for flight simulator X. This requires a .net language so my obvious choice is VB.Net...I took the lone sample from the FSX SDK SP1 and started tweaking it to do what I need, but I am having trouble writing something back. Specifically, I simply want to have a button on a form that when clicked will decrease the COM Freq by 1 MHz. I am having a really difficult time understanding this Object Class stuff and would appreciate a simple example that does this so I can comprehend what the heck I am supposed to do.There is an event Id of KEY_COM_RADIO_WHOLE_DEC and a variable of COM_RADIO_WHOLE_DEC, but I do not know how to make the program work. I have even looked at some of the C examples and tried to modify it for the VB code with no luck.I have added the VB code I am working on for what it is worth. Any help or direction is appreciated.Thanks! Mike

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Hi Mike,Arguably, the documentation for VB.NET isn't the greatest, but rest assured that the documentation for C# is only marginally better, and the docs are really designed for the C++ crowd. Here's a great site to convert code between C# and VB.NET and vice versa, which will allow you to view the examples in C# in VB so it's more familiar to you:http://www.developerfusion.co.uk/utilities...csharptovb.aspxNext, while I didn't run your code, I'm seeing a few potential issues so I'm making some recommendations below. I don't guarantee this will necessarily work since I'm a C# person but that should give you something to start with:Move the following code in your button click event to initDataRequest() as it only needs to be done once. I have found that registering events multiple times may not be a good thing. Also, a number of the examples register the definitions and events after the SIM_START event has been received, that's not necessarily required either.Move the codefsx_simconnect.MapClientEventToSimEvent(Radios.KEY_COM_RADIO_WHOLE_DEC, "COM_RADIO_WHOLE_DEC") fsx_simconnect.AddClientEventToNotificationGroup(RadioGroup.RadioGroup, Radios.KEY_COM_RADIO_WHOLE_DEC, False)to the init routine so it doesn't execute everytime you press your button.Next, your transmit event call seems to have three incorrect parameters: If you look at the documentation, the parameters for the call are:HRESULT SimConnect_TransmitClientEvent( HANDLE hSimConnect, SIMCONNECT_OBJECT_ID ObjectID, SIMCONNECT_CLIENT_EVENT_ID EventID, DWORD dwData, SIMCONNECT_NOTIFICATION_GROUP_ID GroupID, SIMCONNECT_EVENT_FLAG Flags);The equivalent C# code isbool TransmitClientEvent( uint ObjectID, Enum EventID, uint dwData, uint GroupID, SimConnect.SIMCONNECT_EVENT_FLAG Flags);The equivalent VB.NET code isFunction TransmitClientEvent(ByVal ObjectID As System.UInt32, ByVal EventID As Enum, ByVal dwData As System.UInt32, ByVal GroupID As System.UInt32, ByVal Flags As SimConnect.SIMCONNECT_EVENT_FLAG) As BooleanEnd FunctionIn your code, the object ID should be 0, since that's the user aircraft. The parameter to COM_RADIO_WHOLE_DEC should be 0 (possibly 1) - it's not documented but other events usually take 0 as a parameter when they are to increment or decrement a value by a known unit, in this case, 1 MHz. Lastly, because you are using a priority group flag, you must SIMCONNECT_GROUP_PRIORITY_HIGHEST or your event may not be transmitted at all.The VB.NET version of the priority values are here, extracted from the C++ header file (simconnect.h):Public Const SIMCONNECT_GROUP_PRIORITY_HIGHEST As UInt32 = 1Public Const SIMCONNECT_GROUP_PRIORITY_HIGHEST_MASKABLE As UInt32 = 10000000Public Const SIMCONNECT_GROUP_PRIORITY_STANDARD As UInt32 = 1900000000Public Const SIMCONNECT_GROUP_PRIORITY_DEFAULT As UInt32 = 2000000000Public Const SIMCONNECT_GROUP_PRIORITY_LOWEST As UInt32 = 4000000000Your transmit call in your button click handler thus looks something like this now:fsx_simconnect.TransmitClientEvent(0, Radios.KEY_COM_RADIO_WHOLE_DEC, 0, SIMCONNECT_GROUP_PRIORITY_HIGHEST, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY)In summary, I'd read the documentation and look at all the examples, especially those in C++, and cross-reference with the documentation. That's what I've done, and even with that you will find that the .NET implementation is often strange.I have also found that if you trap exceptions that SimConnect sends to you, it's a good indication of a problem with one or more of your parameters, and SimConnect is always right, where the documentation as it turns out isn't. Welcome to trial and error :)Cheers,Etienne

Share this post


Link to post
Share on other sites

Thanks... It is going to take me some time to digest all the info, but it looks like a lot of Trial and error as you put it. That conversion site should be real helpful. Thanks again!!

Share this post


Link to post
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
Sign in to follow this