• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

How to send/receive data to and from a port?

Messages
11
Country
unitedstates
Hi

I was wondering if there are any examples, or instructions anywhere which show exactly how transmit and receive sim data ie altitude, lon, lat, plane roll etc to and from a port using UDP or TCP?

Basically I need to know how to take SIM data send it to a port in a udp or tcp packet and receive packet data from a port. Thanks for your help in advance.
 
1) Are you aware that SimConnect includes a communication feature using Windows ports (I guess it is with TCP but I'm not sure) ?
In other words, you can have a computer running FSX and an other one running your application (a SimConnect client) and they will communicate via the LAN without you having to do any TCP or UDP programming. You just have to use the standard APIs of SimConnect. It works as long as you are using Microsoft Windows OS.

2) If this is not sufficient for your project, you can develop your own data exchange process. Before thinking of samples of code, you must define :
  • the programming language,
  • the protocol, TCP or UDP,
  • synchroneous or asynchroneous mode.

If you haven't done these choices yet, I would recommend the use of a language from the .NET environment (C# my favourite) because the .NET libraries for communication via TCP or UDP are "easy" to use and well documented.

Regards,
Patrick.
 
Hi Thanks for you response.

What I am attempting to do is to code up a HiL simulation for an autopilot I have designed. I am writing up some code to use in SimConnect, to grab some of the important data I need from the plane running in SIM. I need a way to take those values and transmit them to a UDP/TCP port to the waiting hardware boad and also receive some values from a UDP/TCP port ( the hardware board) and pass them back to the simulation.

I think I understand how to capture the simulation values I need and I think I understand how to set/update values in the sim. I do not know how to transmit and receive to a UDP/TCP port from SIMConnect. This is what I need help with, I hope this clears it up a bit.
 
Hi,

Considering your project, I suggest using UDP that is easier to implement. You probably will have to use an asynchronous receive on the UDP port to avoid the blocking of your program while listening.

I doubt you will find a ready-make sample for this. I have done that sort of thing in one of my project but it was a complex program that you cannot use as sample.

I suggest the following approach :
1) download this little program :
http://www.mediafire.com/download.php?u5fzt2vu79vg72y
It is a very simple C# program that read periodically data from SimConnect. I wrote it as a sample for another guy.

2) Visit the site Code Project (codeproject.com).
Type UDPClient in the search box and you will get a bunch of programs exchanging data via UDP. Here is a link to one of them :
http://www.codeproject.com/Articles/96675/How-to-easily-exchange-data-among-NET-applications
Choose an article that do what you need, download the program and study how it works. You may have to download several programs before finding something that fit your requirements.

3) Then you will have to merge the two programs. Use the SimConnect program as a basis and add the UDP communication commands in it.
If you need some help at this point, come back here.

Patrick.
 
I'm working on an open-source project at vatconnect.codeplex.com that extracts plane info using SimConnect, and sends it via UDP to a receiver. Maybe you can use some of that code. The receiver happens to be on the same machine, but you can change the IP to whatever you need.

At that site, click on Source Code, then in the left pane open up "src", then "shared," and there are two C++ classes that might help you, CPacketSender and CPacketReceiver. They initialize Windows sockets and have methods to send or receive blocks of data (packets) on a UDP port. The packets are defined in the "Include" folder in packets.h, but really you can send any block of data known by both sender and receiver.

On the receiver end (CPacketReceiver), the idea is you have to constantly poll it by calling GetNextPacket, and it returns NULL if nothing was received since the last call, or a packet if there was something received.
 
Back
Top