Pascal eXtended Libraryの使い方メモ

ラズパイ3上のLazarus1.7環境にPascal eXtended Libraryをセットアップしたときのメモ。

PXLのサイト → http://asphyre.net/platformextendedlibrary
1)Pascal eXtended Libraryの入手
https://github.com/zyhh/pxl から zip形式でDL
入手したのは V4L2 Fix

2)解凍してラズパイ内のPascal用ライブラリにコピー

今回は /home/pi/Development/FreePascal/kklib/pxl にコピー
というわけで ライブラリパスは
/home/pi/Development/FreePascal/kklib/pxl/Source になるので
「プロジェクト(P)」 – 「プロジェクトオプション」の設定画面で「コンパイラオプション」の「パス」から
「Other init files (-Fu)」項にライブラリパスを設定


3)usesにユニットを登録してPXLを利用可能


4)用途別 ライブラリの使い方メモ

4-1)UART用ライブラリ PXL.Sysfs.UART

型 = TSysfsUART
protected
  function GetBaudRate: Integer; override;
  procedure SetBaudRate(const Value: Integer); override;
  function GetBitsPerWord: Integer; override;
  procedure SetBitsPerWord(const Value: Integer); override;
  function GetParity: TParity; override;
  procedure SetParity(const Value: TParity); override;
  function GetStopBits: TStopBits; override;
  procedure SetStopBits(const Value: TStopBits); override;
public
  constructor Create(const ASystemPath: StdString);
  destructor Destroy; override;
  function Read(const Buffer: Pointer; const BufferSize: Integer): Integer; override;
  function Write(const Buffer: Pointer; const BufferSize: Integer): Integer; override;
  procedure Flush; override;
  property SystemPath: StdString read FSystemPath;
  property Handle: TUntypedHandle read FHandle;
  property BaudRate: Integer read FBaudRate write SetBaudRate;
  property BitsPerWord: Integer read FBitsPerWord write SetBitsPerWord;
  property Parity: TParity read FParity write SetParity;
  property StopBits: TStopBits read FStopBits write SetStopBits;

4-2) GPIO用ライブラリ PXL.Sysfs.GPIO

型 = TSysfsGPIO
protected
  function GetPinMode(const Pin: Integer): TPinMode; override;
  procedure SetPinMode(const Pin: Integer; const Mode: TPinMode); override;
  function GetPinValue(const Pin: Integer): TPinValue; override;
  procedure SetPinValue(const Pin: Integer; const Value: TPinValue); override;
public
  constructor Create(const ASystemPath: StdString = DefaultSystemPath);
  destructor Destroy; override;
  function TrySetPinMode(const Pin: Integer; const Mode: TPinMode): Boolean;
  property PinDrive[const Pin: Integer]: TPinDrive read GetPinDrive write SetPinDrive;

4-3) I2C用ライブラリPXL.Sysfs.I2C

型 = TSysfsI2C
public
  constructor Create(const ASystemPath: StdString);
  destructor Destroy; override;
  procedure SetAddress(const Address: Integer); override;
  function Read(const Buffer: Pointer; const BufferSize: Integer): Integer; override;
  function Write(const Buffer: Pointer; const BufferSize: Integer): Integer; override;
  function ReadByte(out Value: Byte): Boolean; override;
  function WriteByte(const Value: Byte): Boolean; override;
  function WriteQuick(const Value: Byte): Boolean;
  function ReadByteData(const Command: Byte; out Value: Byte): Boolean; override;
  function WriteByteData(const Command, Value: Byte): Boolean; override;
  function ReadWordData(const Command: Byte; out Value: Word): Boolean; override;
  function WriteWordData(const Command: Byte; const Value: Word): Boolean; override;
  function ReadBlockData(const Command: Byte; const Buffer: Pointer;
  const BufferSize: Integer): Integer; override;
  function WriteBlockData(const Command: Byte; const Buffer: Pointer; const BufferSize: Integer):
            Integer; override;
  function ProcessCall(const Command: Byte; var Value: Word): Boolean;
  function ProcessBlockCall(const Command: Byte; const Buffer: Pointer;
  const BufferSize: Integer): Integer;
  property SystemPath: StdString read FSystemPath;
  property Handle: TUntypedHandle read FHandle;

4-4) SPI用ライブラリ PXL.Sysfs.SPI

型 = TSysfsSPI
protected
  function GetMode: Integer; override;
  procedure SetMode(const Value: Integer); override;
  function GetBitsPerWord: Integer; override;
  procedure SetBitsPerWord(const Value: Integer); override;
  function GetFrequency: Integer; override;
  procedure SetFrequency(const Value: Integer); override;
  function GetChipSelectAttributes: TChipSelectAttributes; override;
  procedure SetChipSelectAttributes(const Value: TChipSelectAttributes); override;
public
  constructor Create(const ASystemPath: StdString; const AFrequency: Integer = DefaultFrequency;
  const AMode: Integer = DefaultMode; const ABitsPerWord: Integer = DefaultBitsPerWord);
  destructor Destroy; override;
  function Read(const Buffer: Pointer; const BufferSize: Integer): Integer; override;
  function Write(const Buffer: Pointer; const BufferSize: Integer): Integer; override;
  function Transfer(const ReadBuffer, WriteBuffer: Pointer; const BufferSize: Integer): Integer; override;
  property SystemPath: StdString read FSystemPath;
  property Handle: TUntypedHandle read FHandle;
  property Mode: Integer read FMode write SetMode;
  property BitsPerWord: Integer read FBitsPerWord write SetBitsPerWord;
  property Frequency: Integer read FFrequency write SetFrequency;
  property ChipSelectAttributes: TChipSelectAttributes read FChipSelectAttributes write
           SetChipSelectAttributes;

4-5) PWM用ライブラリ PXL.Sysfs.PWM

型 = TSysfsPWM
protected
  function GetEnabled(const Channel: Integer): Boolean; override;
   procedure SetEnabled(const Channel: Integer; const Value: Boolean); override;
   function GetPeriod(const Channel: Integer): Integer; override;
  procedure SetPeriod(const Channel, Value: Integer); override;
   function GetDutyCycle(const Channel: Integer): Integer; override;
   procedure SetDutyCycle(const Channel, Value: Integer); override;
public
   constructor Create(const ASystemPath: StdString);
   destructor Destroy; override;

 

kabekin