Jump to content

Recommended Posts

Posted

I just finished writing an application that listens to datagrams 18, 20 and 21 for X-Plane 9 latest demo.

 

The demo was set to output to localhost (ip address 127.0.0.1) port 49001 and UDP. The listener processed these values and output them to both a flat file and the user interface.

 

I am using this application to create a protocol that does the same thing in Flight Gear 2.6.0 I order to drive OzRunways in simulator mode. There might be differences in X-Plane 10.8 but I'll worry about that when I find them.

 

If anyone wants a copy of the source code written for C# VS2013 express edition please PM me. Note that the X-Plane output is little-endian and the bit converter in .Net Framework for Windows is also little-endian. It should be that way for Mac/UNIX (Mono) too but I'm not sure. Except the datagram index. That will be different depending on X-Plane for Mac or Windows. Stupid!

 

If anyone has successfully output the NMEA GPS data from their simulator to a Bluetooth COM port please let this forum know the details because that would have been a lot easier and more generally applicable than what I am attempting. Finally the NMEA GPS output is different to the output required by the iPad but I don't know what the difference is.

 

 

  • 6 months later...
Posted
I just finished writing an application that listens to datagrams 18, 20 and 21 for X-Plane 9 latest demo.The demo was set to output to localhost (ip address 127.0.0.1) port 49001 and UDP. The listener processed these values and output them to both a flat file and the user interface.

 

I am using this application to create a protocol that does the same thing in Flight Gear 2.6.0 I order to drive OzRunways in simulator mode. There might be differences in X-Plane 10.8 but I'll worry about that when I find them.

 

If anyone wants a copy of the source code written for C# VS2013 express edition please PM me. Note that the X-Plane output is little-endian and the bit converter in .Net Framework for Windows is also little-endian. It should be that way for Mac/UNIX (Mono) too but I'm not sure. Except the datagram index. That will be different depending on X-Plane for Mac or Windows. Stupid!

 

If anyone has successfully output the NMEA GPS data from their simulator to a Bluetooth COM port please let this forum know the details because that would have been a lot easier and more generally applicable than what I am attempting. Finally the NMEA GPS output is different to the output required by the iPad but I don't know what the difference is.

Hi mnewbery,

 

I'm planning to develop an iOS and/or Android app in combination with XP11 to plot the flight track and make the autopilot and radio's available on the device.

 

I can't see how to send you a PM, so can you please can you give me a hint how to start the communication trough tcp/ip?

 

Thanks in advance, Ruud

 

 

Posted

X-Plane outputs UDP datagrams as per the configuration that the user sets. This is well documented in the x-Plane manuals and there are many examples of people outputting all sorts of values from x-Plane. I have attached some source code that listens to the datagrams.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace XPlaneListener
{
 public class DataReceivedEventArgs : EventArgs
 {
     public byte[] Data;
 }

 public class LogEventArgs : EventArgs
 {
     public string Message;
     public bool NewLine;
 }

 public delegate void DataReceivedEventHandler(object sender, DataReceivedEventArgs e);
 public delegate void LogReceivedEventHandler(object sender, LogEventArgs e);

 public class Listener
 {
     private readonly IPAddress ipAddress;
     private readonly int port;
     private bool stopped = false;
     public event DataReceivedEventHandler DataReceived;
     public event LogReceivedEventHandler LogReceived;

     public Listener(IPAddress IPAddresss, int Port, string FileName)
     {
         this.ipAddress = IPAddresss;
         this.port = Port;
         if (System.IO.File.Exists(FileName))
         {
             System.IO.File.Delete(FileName);
             CreateLogEvent("Deleted log file", true);
         }
     }

     public void Listen()
     {
         stopped = false;
         byte[] data = new byte[1024];
         IPEndPoint ipep = new IPEndPoint(ipAddress, port);
         UdpClient newsock = new UdpClient(ipep);
         // Polling the socket
         while (!stopped && newsock.Available == 0)
         {
             CreateLogEvent("Waiting for a client...", true);
             System.Threading.Thread.Sleep(100);
         }
         // Got one packet, should be more coming along soon
         //int counter1 = 0;
         while (!stopped)
         {
             CreateLogEvent("X-Plane Data Read:", true);
             data = newsock.Receive(ref ipep);
             // Analyse every 10th message packet
             //if (counter1++ % 10 == 0)
             //{
                 CreateDataReceivedEvent(data);
             //}
         }
         newsock.Close();
         newsock = null;
         CreateLogEvent("Closed", true);
     }

     private void CreateDataReceivedEvent(byte[] data)
     {
         if (DataReceived != null)
         {
             DataReceivedEventArgs e = new DataReceivedEventArgs();
             e.Data = data;
             DataReceived(this, e);
         }
     }

     private void CreateLogEvent(string message, bool newLine)
     {
         if (LogReceived != null)
         {
             LogEventArgs e
                 = new LogEventArgs() { Message = message, NewLine = newLine };
             LogReceived(this, e);
         }
     }

     public void Cancel()
     {
         stopped = true;
     }

     public void AppendToFile(string FileName, string LineText)
     {
         if (string.IsNullOrEmpty(FileName))
         {
             return;
         }
         System.IO.File.AppendAllLines(FileName, new string [] {string.Format("{0}\r\n",LineText)});
     }
 }
}

 

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
×
×
  • Create New...