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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

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