Jump to content
Sign in to follow this  
Guest DaveC3

VB6 example

Recommended Posts

Guest DaveC3

I wanted to share some code I used to drive 6 servo gauges using VB6 and SimConnect. This program also has USB connection. The snipit below is just the SimConnect communication. Hope it will help someone out.Private Sub SimConnect_Opened(ByVal ApplicationName As String, ByVal ApplicationVersionMajor As Long, ByVal ApplicationVersionMinor As Long, ByVal ApplicationBuildMajor As Long, ByVal ApplicationBuildMinor As Long, ByVal SimConnectVersionMajor As Long, ByVal SimConnectVersionMinor As Long, ByVal SimConnectBuildMajor As Long, ByVal SimConnectBuildMinor As Long, ByVal Reserved1 As Long, ByVal Reserved2 As Long) SimConnect.AddDataDefinitionEx 1001, "TURB ENG ITT:1", "Rankine", SIMCONNECT_DATATYPE_FLOAT64, 20, 0 SimConnect.AddDataDefinitionEx 1001, "PROP RPM:1", "RPM", SIMCONNECT_DATATYPE_FLOAT64, 20, 0 SimConnect.AddDataDefinitionEx 1001, "TURB ENG MAX TORQUE PERCENT:1", "percent", SIMCONNECT_DATATYPE_FLOAT64, 2, 0 SimConnect.AddDataDefinitionEx 1001, "TURB ENG ITT:2", "Rankine", SIMCONNECT_DATATYPE_FLOAT64, 20, 0 SimConnect.AddDataDefinitionEx 1001, "PROP RPM:2", "RPM", SIMCONNECT_DATATYPE_FLOAT64, 20, 0 SimConnect.AddDataDefinitionEx 1001, "TURB ENG MAX TORQUE PERCENT:2", "percent", SIMCONNECT_DATATYPE_FLOAT64, 2, 0 'This will update the data every second 'SimConnect.RequestDataOnSimObject 9999, 1001, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SECOND, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED, 0, 0, 0 'This will update the data when one of the trigger values is exceeded SimConnect.RequestDataOnSimObject 9999, 1001, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SIM_FRAME, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED, 0, 0, 0End SubPrivate Sub SimConnect_SimObjectData(ByVal RequestId As Long, ByVal ObjectId As Long, ByVal DefineId As Long, ByVal Flags As FSCSIMCONNECTLib.SIMCONNECT_DATA_REQUEST_FLAG, ByVal EntryIndex As Long, ByVal EntryCount As Long) pITT1.Caption = Format(((SimConnect.GetDataDouble(0, 0) / 1.8) - 273.15), "000") 'Rankine to celsius RPM1.Caption = Format((SimConnect.GetDataDouble(0, 1)), "000") pTorque1.Caption = Format((SimConnect.GetDataDouble(0, 2)), "000") pITT2.Caption = Format(((SimConnect.GetDataDouble(0, 3) / 1.8) - 273.15), "000") 'Rankine to celsius RPM2.Caption = Format((SimConnect.GetDataDouble(0, 4)), "000") pTorque2.Caption = Format((SimConnect.GetDataDouble(0, 5)), "000")'************** This section normalizes the data to drive the servos 0 to 255 range************************'******************* RPM ********************************************************PRPM1 = 225 - ((RPM1.Caption / 1000) * 112)If PRPM1 > 225 Then PRPM1 = 225If PRPM1 < 0 Then PRPM1 = 0PRPM2 = 225 - ((RPM2.Caption / 1000) * 112)If PRPM2 > 225 Then PRPM2 = 225If PRPM2 < 0 Then PRPM2 = 0'***************** Torque ***************************************************If pTorque1.Caption < 0 Then pTorque1.Caption = 0Torque1 = 255 - (pTorque1.Caption * 2.215) '* 100If Torque1 > 240 Then Torque1 = 240If Torque1 < 0 Then Torque1 = 0If pTorque2.Caption < 0 Then pTorque2.Caption = 0Torque2 = 255 - (pTorque2.Caption * 2.215) '* 100If Torque2 > 255 Then Torque2 = 255If Torque2 8)If ITT1 > 200 Then ITT1 = 200If ITT1 8)If ITT2 > 200 Then ITT2 = 200If ITT2 < 0 Then ITT2 = 0'*******************************************************************************WriteSomeData 'Send the servo values to USBEnd Sub

Share this post


Link to post
Share on other sites
Guest djmarius

How does your code talk to the usb device? I assume the RPM values are sent to your USB device... but how?

Share this post


Link to post
Share on other sites
Guest DaveC3

I make my own USB devices using Microchip 18F2455 micro controllers. They have built in USB receiver and transmitter. I use Bicbasic Pro to program the devise. In VB6 I use a USB interface to receive and send data to the USB device. Most recently I use EasyHid. It is a free program from http://www.mecanique.co.uk/products/usb/easyhid.html.It automatically produces a VB project based on the paramiters you set for your device.Hope that helpsDave

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  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...