If you have full realistic mode on FSX make sure you are 3000 feet and less altitude. Get out of full screen and set the option in settings general pause on task switch so FSX will not pause when you click away.Īfter you connect your Arduino to your pc and you lunch the application you should have a fully functional system. Open FSX and load a simple flight making sure you are airborne, also make sure that your aircraft supports landing gear function :)
Testing You can get the full code by clicking here Now let's test our application
Lastly we are going to create a control mechanism to close the serial port when we want.īntConnect_to_serial.Text = "Read Serial port"īntConnect_to_serial.Text = "stop serial port" To use this code put the name of the sub with the number 0 or 16383 the sub will check if the system already has it set or else will set the new value. Let's make a new sub process to handle the change and send it to the API So when offset gives 0 then the gear is up and 16383 is down. If we start our application without FSX running we will get the following exception You can also see the exception handling try catch. You can see that I set a variable called landing Gear in the main class so our code can use it. We will use the form load to call a small procedure (sub) Now we have to set our program to read when it starts the value from FSX. The guide specifies this as an offset.Īnd because the offset in the API guide is 0BE8 we replace the 0 with an H. In this tutorial we want to read and write a value to FSX.
We are going to use our documents to learn how to write the API call.
We are going to use 2 documents found in the SDK the user guide as PDF and the FSUIPC4 Offsets Status PDF. Next thing to do is to talk about the API and how we will make it work. We then check if the Arduino sends the GEAR1 or GEAR0 that represent down and up. We make sure that our thread can interact with the main form. Because the new thread cannot interact directly with the main form we have to set a callback function, so as you noted the following code The thread will read the serial stream and send it for processing into the sub process processReadings () that takes as arguments the last reading. What this code does is to open the serial port and start a new thread
If messageFromSerial = "GEAR1" & vbCr ThenĮlseIf messageFromSerial = "GEAR0" & vbCr Then TxtDATA_FROM_SERIAL.Text = messageFromSerial If txtDATA_FROM_SERIAL.InvokeRequired Then Sub processReadings( ByVal readingText As 'open the port, read the stream, send the stream to the thread SerialPort( My.Settings.ComPort, My.Settings.BaudRate) EventArgs) Handles bntConnect_to_serial.Click Sub bntConnect_to_serial_Click( ByVal sender As System. Now let's double click our connect button and write the following code Using this code we declare our serial port and the thread that we are going to use, put this code in the main class of your program. The new thread will allow the user to have control of the form and allow him or her to stop the process. We are going to make our program to create a new thread for this purpose. Our program works by reading the serial port and when our program finds a difference in the readings it will transmit the appropriate command to the API. It's a simple operation and we will use the button sub to handle the process. MsgBox( "Please type your connection settings") Sub btnSAVESETTINGS_Click( ByVal sender As System. Run your application and check that everything is ok EventArgs) Handlesįor simple operations we can always use the load method of our form but I prefer to split the code because I'm planning to extend the code later and easier to handle and understand. And create a new sub to handle the loading into the form. Get the user settings Now let's write up a bit of code to get and save the settings.ĭouble click on your form in order to get the form load code. Note that we can change the settings later in our code.
You can set the user settings using the project properties as we did above when we referenced the API. NET framework allow us to do with the Application settings. Now I like to have the program remember my com port and my baud rate so I don't have to type them all the time.