Jump to content

[RED] Compile From Source in Pascal ?


Nic

Recommended Posts

Verdammt, noch ein Bug den wir uns durch eine Last-Minute-Änderung eingefangen haben :(. Wochenlanges Testen und dann sowas...

 

Die aktuell Veröffentlichen FPC Bindings lassen sich nicht mit dem Makefile compilieren, das ist beim bauen des Images fehlgeschlagen aber nicht aufgefallen. Dadurch ist die FPC Library gar nicht installiert auf dem RED Brick :o.

 

Du kannst das wie folgt über die Console fixen:

 

sudo su
# password = tf

cd /usr/tinkerforge/bindings/delphi/source/
sed -i -e 's/BrickRED//g' Makefile.fpc
export FPCDIR=/usr/lib/fpc/`ls /usr/lib/fpc/ | grep -E [0-9].[0-9].[0-9] | head -n1`
fpcmake
make
make install

 

Danach funktioniert dann alles wie erwartet, getest hab ich mit folgendem Beispiel:

 

Makefile.fpc:

[target]
programs=ExampleEnumerate

[require]
packages=tinkerforge

 

ExampleEnumerate.pas:

program ExampleEnumerate;

{$ifdef MSWINDOWS}{$apptype CONSOLE}{$endif}
{$ifdef FPC}{$mode OBJFPC}{$H+}{$endif}

uses
  SysUtils, IPConnection, Device;

type
  TExample = class
  private
    ipcon: TIPConnection;
  public
    procedure EnumerateCB(sender: TIPConnection;
                          const uid: string; const connectedUid: string; const position: char;
                          const hardwareVersion: TVersionNumber; const firmwareVersion: TVersionNumber;
                          const deviceIdentifier: word; const enumerationType: byte);
    procedure Execute;
  end;

const
  HOST = 'localhost';
  PORT = 4223;

var
  e: TExample;

{ Print incoming enumeration }
procedure TExample.EnumerateCB(sender: TIPConnection;
                               const uid: string; const connectedUid: string; const position: char;
                               const hardwareVersion: TVersionNumber; const firmwareVersion: TVersionNumber;
                               const deviceIdentifier: word; const enumerationType: byte);
begin
  WriteLn('UID:               ' + uid);
  WriteLn('Enumerate Type:    ' + IntToStr(enumerationType));

  if (enumerationType <> IPCON_ENUMERATION_TYPE_DISCONNECTED) then begin
    WriteLn('Connected UID:     ' + connectedUid);
    WriteLn('Position:          ' + position);
    WriteLn('Hardware Version:  ' + IntToStr(hardwareVersion[0]) + '.' +
                                    IntToStr(hardwareVersion[1]) + '.' +
                                    IntToStr(hardwareVersion[2]));
    WriteLn('Firmware Version:  ' + IntToStr(firmwareVersion[0]) + '.' +
                                    IntToStr(firmwareVersion[1]) + '.' +
                                    IntToStr(firmwareVersion[2]));
    WriteLn('Device Identifier: ' + IntToStr(deviceIdentifier));
  end;

  WriteLn('');
end;

procedure TExample.Execute;
begin
  { Create connection and connect to brickd }
  ipcon := TIPConnection.Create;
  ipcon.Connect(HOST, PORT);

  { Register enumerate callback to "EnumerateCB" }
  ipcon.OnEnumerate := {$ifdef FPC}@{$endif}EnumerateCB;

  { Trigger enumerate }
  ipcon.Enumerate;

  WriteLn('Press key to exit');
  ReadLn;
  ipcon.Destroy; { Calls ipcon.Disconnect internally }
end;

begin
  e := TExample.Create;
  e.Execute;
  e.Destroy;
end.

 

Auszuführende Executable ist "ExampleEnumerate".

 

Ergebnis im Log:

 

2014-12-24T16:21:00.234105+0100
-------------------------------------------------------------------------------
UID:               3df8jB
Enumerate Type:    1
Connected UID:     0
Position:          0
Hardware Version:  1.0.0
Firmware Version:  2.0.0
Device Identifier: 17

UID:               3df8jB
Enumerate Type:    0
Connected UID:     0
Position:          0
Hardware Version:  1.0.0
Firmware Version:  2.0.0
Device Identifier: 17

UID:               6CtsQi
Enumerate Type:    0
Connected UID:     3df8jB
Position:          1
Hardware Version:  2.1.0
Firmware Version:  2.3.0
Device Identifier: 13

UID:               fobar
Enumerate Type:    0
Connected UID:     6CtsQi
Position:          c
Hardware Version:  1.0.0
Firmware Version:  2.0.1
Device Identifier: 246

Link to comment
Share on other sites

Prima und danke, hat geklappt.

Allerdings scheint es erst beim 2 Versuch der Programmstart (Always) zu klappen, anbei das log:

2014-12-11T14:44:17.899223+0100
-------------------------------------------------------------------------------
An unhandled exception occurred at $00037794 :
ETimeoutException : Did not receive response in time for function ID 2
  $00037794
  $0001FF94
  $000087C0
  $000088A8



2014-12-11T14:44:21.468739+0100
-------------------------------------------------------------------------------

 

Das Programm was ich ausführe ist recht banal, siehe Attachment. Falls das o.g. ein Bug ist, reicht eine Behebung auch im nächsten Jahr ;)

ExampleCallback.pas

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.

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.

×
×
  • Create New...