A320_Pilot Posted December 22, 2013 Report Posted December 22, 2013 Good afternoon, my name is George! I'm here right now, I want to write a program for FS9 and FSS, which outputs to the data from the simulator, such as the speed of the airplane, the airplane rate, height, lights, vertical! But I don `t know where to start! Help please, where to start?
Paul Henty Posted December 22, 2013 Report Posted December 22, 2013 Welcome George, 1. Download the DLL Package from the sticky thread at the top of this sub forum: http://forum.simflight.com/topic/74848-fsuipc-client-dll-for-net-version-24/ 2. In the Docs folder open "UserGuide.pdf" and read the sections called 'Introduction' and 'Getting Started' 3. Load the Sample C# Project in Visual Studio. Run it and see what it does (It does quite a lot of what you want). Study the code to see how it works. You will need to refer to the document called "FSUIPC4 Offsets Status.pdf" which gives details of all the information that you can get from FSUIPC. This is found under your main FSX folder in a sub folder called "\Modules\FSUIPC Documents". If you have any questions about using the DLL, ask here. If you have questions about FSUIPC in general please ask Pete in the main forum. Unfortunately I cannot teach C# or programming here so if you need to learn to program you'll have to find some other resources for that. Paul 1
A320_Pilot Posted December 22, 2013 Author Report Posted December 22, 2013 Can i write in russian language here?
Paul Henty Posted December 22, 2013 Report Posted December 22, 2013 I don't understand Russian so I wouldn't be able to read it. Paul
A320_Pilot Posted December 22, 2013 Author Report Posted December 22, 2013 private void displayCurrentPosition() { FSUIPCConnection.Process(); FsLongitude lon = new FsLongitude(playerLongitude.Value); FsLatitude lat = new FsLatitude(playerLatitude.Value); this.textBox1.Text = lon.ToString(); this.textBox2.Text = lat.ToString(); } Where is error? data does not appear!
Paul Henty Posted December 22, 2013 Report Posted December 22, 2013 I can't see anything wrong there. Please show me: 1. Where you declare playerLongitude and playerLatitude 2. What does appear in the text boxes? You can also try inspecting the value of playerLatitude.Value while the program is running using a breakpoint. Paul 1
A320_Pilot Posted December 23, 2013 Author Report Posted December 23, 2013 (edited) This is a full code Edited December 23, 2013 by A320_Pilot
A320_Pilot Posted December 23, 2013 Author Report Posted December 23, 2013 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using FSUIPC; namespace FSClient { public partial class FSClient : Form { private static readonly string AppTitle = "FSClient"; private Offset<long> playerLatitude = new Offset<long>(0x0560); private Offset<long> playerLongitude = new Offset<long>(0x0568); public FSClient() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { try { FSUIPCConnection.Open(); } catch (Exception ex) { MessageBox.Show(ex.Message, AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { FSUIPCConnection.Close(); } private void displayCurrentPosition() { FSUIPCConnection.Process(); FsLongitude lon = new FsLongitude(playerLongitude.Value); FsLatitude lat = new FsLatitude(playerLatitude.Value); this.textBox1.Text = lon.ToString(); this.textBox2.Text = lat.ToString(); } } }
Paul Henty Posted December 23, 2013 Report Posted December 23, 2013 I can't see much wrong with the code except that you don't call displayCurrentPosition() anywhere so it's never run. You need to call this from a button press, or a timer if you want regular updates. Paul
A320_Pilot Posted December 24, 2013 Author Report Posted December 24, 2013 Give me please code with a call function with timer!Thanks
A320_Pilot Posted December 26, 2013 Author Report Posted December 26, 2013 (edited) using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Globalization; using System.Threading; using FSUIPC; namespace FSClient { //---------------------------------------------------------------------------------// public partial class FSClient : Form { private static readonly string AppTitle = "FSClient"; private Offset<long> playerLongitude = new Offset<long>(0x0568); private Offset<long> playerLatitude = new Offset<long>(0x0560); private Offset<int> verticalSpeed = new Offset<int>(0x02C8); private Offset<long> altitude = new Offset<long>(0x0570); private Offset<int> airspeed = new Offset<int>(0x02BC); //---------------------------------------------------------------------------------// public FSClient() { InitializeComponent(); FsLatitude lat = new FsLatitude(playerLatitude.Value); FsLongitude lon = new FsLongitude(playerLongitude.Value); FsLatLonPoint currentPosition = new FsLatLonPoint(lat, lon); } //---------------------------------------------------------------------------------// private void Form1_Load(object sender, EventArgs e) { this.timer1.Enabled = false; this.endfl.Enabled = false; this.label2.Text = ("We expect connection!"); } //---------------------------------------------------------------------------------// private void startfl_Click(object sender, EventArgs e) { try { FSUIPCConnection.Open(); this.startfl.Enabled = false; this.endfl.Enabled = true; this.timer1.Interval = 100; this.timer1.Enabled = true; this.label2.Text = ("Connection is established!"); } catch (Exception ex) { MessageBox.Show(ex.Message, AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } } //---------------------------------------------------------------------------------// private void endfl_Click(object sender, EventArgs e) { try { FSUIPCConnection.Close(); this.startfl.Enabled = true; this.endfl.Enabled = false; this.timer1.Interval = 100; this.timer1.Enabled = false; this.label2.Text = ("Flight is completed, the data is saved!"); } catch (Exception ex) { MessageBox.Show(ex.Message, AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } } //---------------------------------------------------------------------------------// public void displayLocation() { FSUIPCConnection.Process(); FsLatitude lat = new FsLatitude(playerLatitude.Value); FsLongitude lon = new FsLongitude(playerLongitude.Value); this.label13.Text = lon.ToString(); this.label12.Text = lat.ToString(); FsLatLonPoint currentPosition = new FsLatLonPoint(lat, lon); } //---------------------------------------------------------------------------------// private void timer1_Tick(object sender, EventArgs e) { try { //---------------------------------------------------------------------------------// FSUIPCConnection.Process(); //---------------------------------------------------------------------------------// //Verticall speed in meters double verticalSpeed_MetresPerSecond = (double)verticalSpeed.Value / 256d; //---------------------------------------------------------------------------------// //Vertical speed in feets double verticalSpeed_FeetPerMinute = (double)verticalSpeed.Value * 60d * 3.28084d / 256d; //---------------------------------------------------------------------------------// //Altitude in meters double altitude_Metres = (double)altitude.Value / (65536d * 65536d); //---------------------------------------------------------------------------------// //Altitude in feets double altitude_Feet = (double)altitude.Value / (65536d * 65536d) * 3.28084d; //---------------------------------------------------------------------------------// //Airspeed in knots double airpeedKnots = ((double)airspeed.Value / 128d); //---------------------------------------------------------------------------------// this.displayLocation(); } catch (FSUIPCException ex) { if (ex.FSUIPCErrorCode == FSUIPCError.FSUIPC_ERR_SENDMSG) { this.timer1.Enabled = false; this.startfl.Enabled = true; FSUIPCConnection.Close(); MessageBox.Show("The connection to Flight Sim has been lost.", AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { throw ex; } } } //---------------------------------------------------------------------------------// } } This is my new code, but it is not working((((!!!!! How does all this display? Do as in the example, but does not work! Edited December 26, 2013 by A320_Pilot
Paul Henty Posted December 27, 2013 Report Posted December 27, 2013 Your code works well for me. If you are not seeing the Longitude and Latitude updating then make sure you have your events linked properly: On the visual form designer, click on the timer1. In the properties grid, click on the lightning button to see the list of events. There is only one called Tick. Make sure it has 'timer1_Tick' next to it. If it's blank select timer1_Tick from the dropdown box. Do the same for the buttons. Look for an event called 'click' and make sure the correct _Click event is selected from the dropdown box. I notice that you are calculating things like Airpeed, but not displaying them. You need to create a label or textbox in which to display this information. Then you need to assign the calculated values to these labels or textboxes. For example to display the airspeed, create a label on the form designer called lblAirspeed. Then add a line of code after you calculate the airspeed to display the value: double airpeedKnots = ((double)airspeed.Value / 128d); this.lblAirspeed.Text = airpeedKnots.ToString("F0") + " Kts"; The ToString() method converts the numeric value into a string so it can be displayed as text. The F0 rounds the value to 0 decimal places. For 2 decimal places you would use ToString("F2"). These are very very basic C# programming concepts. You should learn C# before you attempt something more complicated like getting data from FSUIPC. I really cannot teach C# here. Paul 1
A320_Pilot Posted December 27, 2013 Author Report Posted December 27, 2013 Thanks Paul, code is worked :) Where i can find ofssets fsuipc 4 for FS9???
Pete Dowson Posted December 27, 2013 Report Posted December 27, 2013 Thanks Paul, code is worked :) Where i can find ofssets fsuipc 4 for FS9??? FSUIPC4 does not work in FS9. You need to install FSUIPC3. Within the FSUIPC Documents folder you'll then find a "Programmer's Guide" document which contains the offset list and more information, much of which also applies to FSX. These documents are also provided in the FSUIPC SDK. Pete 1
A320_Pilot Posted December 27, 2013 Author Report Posted December 27, 2013 How to derive GS? Do so, but not out! double airpeedKnotsGround = (double)airspeed_gs.Value / (65536d * 3.28084); this.label18.Text = airpeedKnotsGround.ToString("F0") + " Knots";
Paul Henty Posted December 27, 2013 Report Posted December 27, 2013 The ground speed in offset 02B4 is in metres/second. To convert to knots you need to multiply by 1.943844492: double airpeedKnotsGround = (double)airspeed_gs.Value / (65536d * 1.943844492); this.label18.Text = airpeedKnotsGround.ToString("F0") + " Knots"; You have not shown me the offset declaration. You always need to show it. This offset should be declared as an 'int' like this: Offset<int> airspeed_gs = new Offset<int>(0x02B4); Paul 1
A320_Pilot Posted December 27, 2013 Author Report Posted December 27, 2013 Thanks for the answer Paul, and the last two questions: 1. How to deduce the state of the gear (Up, Down)? 2.How to deduce the state of the wing (degrees slats and flaps)?
Paul Henty Posted December 28, 2013 Report Posted December 28, 2013 1. How to deduce the state of the gear (Up, Down)? Use offset 0BEC. This is for the nose gear. It is possible to get values for all three wheels if you want. Or just use one of them like my example: Declare the offset as follows: private Offset<int> gearPositionNose = new Offset<int>(0x0BEC); Test the value to determine gear up (0), down (16383) or in transit (a value in between). if (gearPositionNose.Value == 0) { this.lblGear.Text = "Gear Up"; } else if (gearPositionNose.Value == 16383) { this.lblGear.Text = "Gear Down"; } else { this.lblGear.Text = "Gear In Transit"; } 2.How to deduce the state of the wing (degrees slats and flaps)? Below is an example for left wing inboard flaps using offset 30F0. You can do the same for other flaps and slats at offsets 30F0 to 30FE. Not all of these offsets will have values. It depends on the aircraft. Declare the offset as follows: private Offset<short> leftInboardFlap = new Offset<short>(0x30F0); Calculate the flap angle and display: double flapsDegrees = (double)leftInboardFlap.Value / 256d; this.lblFlaps.Text = flapsDegrees.ToString("F0"); For details of the other offsets I have mentioned, please look in the FSUIPC4 Offsets Status.pdf. Paul
A320_Pilot Posted December 29, 2013 Author Report Posted December 29, 2013 I have a problem, flaps are displayed correctly, but the slats are not, either 0 or 1 degree! //Flaps position double flapLL = (double)inbFlapLL.Value / 256d; double flapLR = (double)inbFlapLR.Value / 256d; double flapTL = (double)inbFlapTL.Value / 256d; double flapTR = (double)inbFlapTR.Value / 256d; this.flapsPos.Text = flapLL.ToString("F0") + "° " + flapLR.ToString("F0") + "° " + flapTL.ToString("F0") + "° " + flapTR.ToString("F0") + "°"; private Offset<short> inbFlapTL = new Offset<short>(0x30F0); private Offset<short> inbFlapTR = new Offset<short>(0x30F4); private Offset<short> inbFlapLL = new Offset<short>(0x30F8); private Offset<short> inbFlapLR = new Offset<short>(0x30FC);
A320_Pilot Posted December 29, 2013 Author Report Posted December 29, 2013 (edited) And another question! Why do we need file: FSUIPCClient.XML Edited December 29, 2013 by A320_Pilot
Paul Henty Posted December 29, 2013 Report Posted December 29, 2013 I have a problem, flaps are displayed correctly, but the slats are not, either 0 or 1 degree! I also get 0 or 1 on the default Boeing 737 and 747. But on the default A320 I get more sensible values. There is nothing wrong with your code. These are just the values that FSUIPC/FSX gives us. Try on different aircraft. If you think they are wrong then ask Pete about these values in the main support forum. And another question! Why do we need file: FSUIPCClient.XML This file holds the text for the Intellisense. This appears when you are programming inside Visual Studio. It gives information about the method calls and parameters for my DLL. You only need this while coding. You do not need to give this file to users. Paul
A320_Pilot Posted December 30, 2013 Author Report Posted December 30, 2013 Hello Paul, 1. What offset use for lights (landing, taxi, navigation, strobes for Read)? 2.What is the difference in the offset value "int", "Long", "short", "double", "string"? Where i can read about it? 3.Whether correctly I convert ground speed? double gsKMH = ((double)airspeed_gs.Value / 65536d * 3.28084d); double gsKnots = ((double)airspeed_gs.Value / 65536d * 1.943844492); this.gsAir1.Text = gsKnots.ToString("F0") + " (Knots)" + " / " + gsKMH.ToString("F0") + " (Km/h)"; 4.And how convert Zero fuel weight, empty weight and payload? I write this: //Empty weight in lbs & kgs double fw_ew_lbs = ((double)fw_ew.Value / 256d); double fw_ew_kgs = ((double)fw_ew.Value / 256d); this.emw1.Text = fw_ew_lbs.ToString("F0") + " (Lbs)" + " / " + fw_ew_kgs.ToString("F0") + " (Kgs)"; //---------------------------------------------------------------------------------// //Zero fuel weight in lbs & kgs double fw_zfw_lbs = ((double)fw_zfw.Value / 256d); double fw_zfw_kgs = ((double)fw_zfw.Value / 256d); this.zfw1.Text = fw_zfw_lbs.ToString("F0") + " (Lbs)" + " / " + fw_zfw_kgs.ToString("F0") + " (Kgs)"; //---------------------------------------------------------------------------------// //Weight payload in lbs & kgs double fw_pl_lbs = ((double)fw_payload.Value / 256d); double fw_pl_kgs = ((double)fw_payload.Value / 256d); this.payload1.Text = fw_pl_lbs.ToString("F0") + " (Lbs)" + " / " + fw_pl_kgs.ToString("F0") + " (Kgs)";
Recommended Posts