Jump to content
The simFlight Network Forums

Code problems with connecting QT to FSUIPC

Recommended Posts

I am getting some problems in my Main.cpp file, I have attached my whole fime, if someone could help me out, it would be really appreciated. 

Here's mu main.cpp file :




#include "mainwindow.h"
#include <QApplication>
#include <QDebug>

#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

// Universal data
#include "universal.h"

// FS interface
#include "FSinterface.h"

#include "FSUIPC_User.h"

// for setting the timer
#include "timer.h"

// for Serial RS232
#include "tserial.h"
#include "types.h"


const char *pszErrors[] =
    {	"Okay",
        "Attempt to Open when already Open",
        "Cannot link to FSUIPC or WideClient",
        "Failed to Register common message with Windows",
        "Failed to create Atom for mapping filename",
        "Failed to create a file mapping object",
        "Failed to open a view to the file map",
        "Incorrect version of FSUIPC, or not FSUIPC",
        "Sim is not version requested",
        "Call cannot execute, link not Open",
        "Call cannot execute: no requests accumulated",
        "IPC timed out all retries",
        "IPC sendmessage failed all retries",
        "IPC request contains bad data",
        "Maybe running on WideClient, but FS not running on Server, or wrong FSUIPC",
        "Read or Write request cannot be added, memory for Process is full",

char buffer_fsupc[25000];
char buffer_reception[12];
char bufftx[40];
int main(int argc, char *argv[])


        QApplication a(argc, argv);
        MainWindow w;
        double Attitude[NROT];
            FSAttitudeType FSAtt;
            DWORD dwResult;// a pointer to receive an error number if the operation fails.
            Tserial *com; // Serial declaration
            int SampleTime; // Sample Time in ms
            Timer timer;
            int capsam=0;
            int pousseeL, pousseeR;
            int pousseeOldL = 0, pousseeOldR = 0;
            char car;
            int vret,index=0;
            int oktrame=0;
            int pousseeTmp;
            char   x[]=" \\\\.\\com3";

                // Declaration des variables locales
                 const char *pFS[] = { "FS98", "FS2000", "CFS2", "CFS1", "Fly!", "FS2002", "FS2004" };  // Change made 060603

                // Okay, we're linked, and already the FSUIPC_Open has had an initial
                // exchange with FSUIPC to get its version number and to differentiate
                // between FS's.
                printf ("CapSim: Link established to FSUIPC\n") ;
            //	printf ("Sim is %s,FSUIPC Version = %c.%c%c%c%c\r%s\n",(FSUIPC_FS_Version && (FSUIPC_FS_Version <= 7)) ? pFS[FSUIPC_FS_Version - 1] : "Unknown FS",'0' + (0x0f & (FSUIPC_Version >> 28)),'0' + (0x0f & (FSUIPC_Version >> 24)),'0' + (0x0f & (FSUIPC_Version >> 20)),'0' + (0x0f & (FSUIPC_Version >> 16)),(FSUIPC_Version & 0xffff) ? 'a' + (FSUIPC_Version & 0xff) - 1 : ' ');


                /* ///////////////////////////// une autre maniere de faire ///////////////////////////// */

                // Timer

                //printf("\nEnter the Sample Time in miliseconde\n");

                // RS232
                        com=new Tserial();
                        if( com!=0 )
                            com->connect (x,9600,spNONE); // com Initialisation
                            printf("Error Setting COM");
               }else{  //Openninig FSUIPC failed
                printf ("CapSim: Failed to open link to FSUIPC:%s\n", pszErrors[dwResult]) ;
                FSUIPC_Close(); // Closing when it wasn't open is okay, so this is safe here
            //    com->disconnect(); // Closing the port
                return 0;
            while(true) {

                            /* -------------------------------------- Sending Data --------------------------------------  */

                            // Read from FS data structure
                            FSUIPC_Process(&dwResult); // Process all the request(s)

                    //		sprintf(bufftx,"%4u %3u %6u %3u",*((unsigned int*)(buffer_fsupc+0x2BC))/128,(unsigned int)(*((double*)(buffer_fsupc+0x2CC))),
                //				(unsigned int)floor((double)(((unsigned int)*((__int64 *)(buffer_fsupc+0x570))*(double)3.2808)/((double)65536.)+0.5)),0);
                                /*(unsigned int)floor(((unsigned int)*((unsigned short  int*)(buffer_fsupc+0xcc))*360.)/65536.+0.5),(unsigned int)*((unsigned short  int*)(buffer_fsupc+0xe2)),
                                    (unsigned int)floor((double)(((unsigned int)*((unsigned int*)(buffer_fsupc+0xd4))*3.2808)/65536.+0.5)));*/

                    /*		sprintf(bufftx,"%6u  %01u  %01u\n", *((unsigned short*)(buffer_fsupc+0x5682))&0xffff,
                                                                *((unsigned char*)(buffer_fsupc+ 0x568A))&0xff,
                                                                *((unsigned char*)(buffer_fsupc+ 0x568E))&0xff);
                                switch(car) {
                                case ui->Alt : printf("To change Altitude turn the Dial");
                                    capsam= (capsam*(65536./3.2808));
                                    *((unsigned int*)buffer_fsupc)= capsam;
                                case ui-> Spd:
                                                            printf("To change Speed turn the Dial:");
                                                            capsam = (capsam*16384)/100;
                                                            *((unsigned int*)buffer_fsupc)= (unsigned short int) capsam;
                                case ui-> Hdg :
                                                                printf("To Change Heading , turn the Dial");
                                                                capsam= (capsam*65536)/36;
                                                                capsam += ((capsam%10)>=5 ? 10 : 0);
                                                                capsam= capsam/10;

                                                                *((unsigned short int*)buffer_fsupc)= (unsigned short int )capsam;
                                                                FSUIPC_Process(&dwResult); // Process all th






       return a.exec();
The errors I am getting are these: 


Tserial: undeclared variable. line 59 

com undeclared variable. line 91,93,  syntax error; identifier ' Tserial'. Ui  undeclared variable., Alt  undeclared variable.





Edited by Mohammad Sufyan Palwala
attach more attachments
Link to comment
Share on other sites


why do you think there is a problem with FSUIPC? The errors you get are not linked to FSUIPC but the COM you try to open.


Tserial: undeclared variable. line 59 

com  undeclared variable. line 91,93,  syntax error; identifier ' Tserial'. Ui  undeclared variable., Alt  undeclared variable.

Also it seems you used an very old SDK example, I would strongly recommend to use the latest SDK examples useful-additional-programs

In addition you want to read a big amount of data into a structure per Process? I would only read what is needed.


// Read from FS data structure                            
FSUIPC_Process(&dwResult); // Process all the request(s)


Link to comment
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
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.