Jump to content
The simFlight Network Forums

FSUIPC delphi code.


Recommended Posts

Hi guys.

I'm trying to build something small , that can lower the gear, set flaps, spoilers, and some rotary encoders to set the autopilot.

I'm a developer , and somethimes in delphi. Therefor i tried to write some code to read/write to and from FSX.

I started with the UIPCHello that is in the FSUIPC SDK. the only thing i could get out of fsx was the speed. And with a conversion

that doesn't make any sense to me. The writing i tried in this example (turn on the autopilot) ends in a crash of the delphi prog.

procedure TFormMain.TimerUpdateTimeTimer(Sender: TObject);
var
  dwResult: DWORD;
  deger:int64;
  Velocidade: longint;
  Ap_Alt,Ap_Crs:integer;
  Calculo: Double;

begin

  if FSUIPC_Read($02BC, 4, @Velocidade, dwResult)  then begin
   if FSUIPC_Process(dwResult) then begin
       Calculo := Round(Velocidade / 128);
      LabelFSclock.Caption := FloatToStr(Calculo);
     end else begin
       LabelFSclock.Caption := 'Processing: ' + ResultText[dwResult];
    end;
  end else begin
     LabelFSclock.Caption := 'Reading: ' + ResultText[dwResult];
  end;

  if FSUIPC_Read($07D4, 4, @Ap_Alt, dwResult)  then begin
   if FSUIPC_Process(dwResult) then begin
      Label5.Caption := floattostr(round(AP_Alt/65536*3.281));
     end else begin
       Label5.Caption := 'Processing: ' + ResultText[dwResult];
    end;
  end else begin
     Label5.Caption := 'Reading: ' + ResultText[dwResult];
  end;

  if FSUIPC_Read($07CC, 4, @Ap_Crs, dwResult)  then begin
   if FSUIPC_Process(dwResult) then begin
      Label7.Caption := floattostr(round(Ap_Crs/65536*3.281));
     end else begin
       Label7.Caption := 'Processing: ' + ResultText[dwResult];
    end;
  end else begin
     Label7.Caption := 'Reading: ' + ResultText[dwResult];
  end;

  end;

procedure TFormMain.Button1Click(Sender: TObject);
var dwResult: DWORD;
    offset,size:longint;
    waarde:byte;
begin
offset:=$7BC;
size:=4;
waarde:=1;
if FSUIPC_Write(offset, size, ptr(waarde), dwResult)  then begin
if FSUIPC_Process(dwResult) then begin
button1.caption:='CMD A ON'
end;
end;
end;

doesn't anyone has an explanation why it doesn't work, or does anyone has some sample code ?

thanx allot !!!!!!

Link to comment
Share on other sites

I'm a developer , and somethimes in delphi. Therefor i tried to write some code to read/write to and from FSX.

Delphi shouldn't present any problems. FSInterrogate, supplied in the FSUIPC SDK, is all in Delphi.

the only thing i could get out of fsx was the speed. And with a conversion

that doesn't make any sense to me.

What values were you getting which made no sense to you? Is "longint" a 32-bit integer as it should be?

You should compare what you are getting with what FSInterrogate2 gets. You should also be using the FSUIPC IPC read/write logging to see what your program is actually achieving.

The writing i tried in this example (turn on the autopilot) ends in a crash of the delphi prog.

Surely the Delphi development system comes with a debugger, so you should be able to debug that yourself?

With the AP altitude value, you seem to define "AP_Alt" as an "integer". Is that another 32-bit integer type like longint? Why the different types?

With the AP heading value your conversion is completely wrong:

  • Label7.Caption := floattostr(round(Ap_Crs/65536*3.281));

Headings are not in "metres" so why the 3.281?
And in the case where you are trying to switch on the autopilot:
  • FSUIPC_Write(offset, size, ptr(waarde), dwResult) (why not "FSUIPC_Write($7BC, 4, ptr(waarde), dwResult)"?)

why have you used "ptr(...)" instead of "@..." as in the read examples? Considering the FSUIPC_Read and FSUIPC_Write functions are identical in their requirements for these parameters, why are you doing things so differently.

Could the crash just possibly be because you've defined "waarde" as a single byte and then used it as a 32-bit (4 byte) value? Why are you suddenly switching to byte in any case?

I don't know Delphi, but I suspect you've not been looking carefully enough at your own code? The FSUIPC interface is straight-forward enough (and you have the source code in any case). I think all your problems may be in understanding the Delphi stuff more than anything to do with the interface.

If you think you have things right (and you may well have, as I don't know Delphi), then please tell me what the values you ARE getting look like. Compare them with FSInterrogate, and look to the FSUIPC logging facilities to help you do your debugging.

For crashes in your own program ALWAYS use your debugger to determine what value or pointer you have wrong.

Regards

Pete

Link to comment
Share on other sites

Hi Pete,

thanks for the answer. I just found out that the Ptr issue was the problem. I was converting sample VB code (charptr) to delphi and

that caused the problem. I found it , came here to let all people know and now i see your post !

Anyhow, thanks allot Pete !

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.