Delphi Help

Interested in integrating USB-UIRT support into an application? Look here!

Moderator: jrhees

Delphi Help

Postby isi4h » Tue Apr 15, 2008 11:49 pm

Is there any chance of source of a Delphi example app.
i'm happy to use irnhelper to 'learn' the ir code i want to transmit.
but i want my own app to be able to transmit the learned ir code.

is there a simple function i can call from uuirt.dll

eg Function TransmitCode(TheStringShownInInhelper);
:) thanks
i can't compile the example i found on the forum :(
thanks
isi4h
 
Posts: 2
Joined: Tue Apr 15, 2008 11:27 pm

I Did It !!

Postby isi4h » Thu Apr 24, 2008 7:06 pm

Here's some delphi code that you can just copy and paste for anyone who needs it.



Code: Select all
////////////////////////////////////////////
//THANKS JON FOR MAKING THE CODE AVAILABLE//
////////////////////////////////////////////
//Copy & Paste Code,Compiles with Delphi 7//
//   Put 2 Buttons & 3 Memos on a form    //
// Create OnClick events for both buttons //
//    Create OnCreate event for Form      //





unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, SyncObjs, StdCtrls;




const

CRLF: string = '\r\n';
INVALID_HANDLE_VALUE: integer = -1;
ERROR_IO_PENDING: integer = 997;
UUIRTDRV_ERR_NO_DEVICE: integer = $20000001;
UUIRTDRV_ERR_NO_RESP: integer = $20000002;
UUIRTDRV_ERR_NO_DLL: integer = $20000003;
UUIRTDRV_ERR_VERSION: integer = $20000004;
UUIRTDRV_CFG_LEDRX: integer = $1;
UUIRTDRV_CFG_LEDTX: integer = $2;
UUIRTDRV_CFG_LEGACYRX: integer = $4;
UUIRTDRV_IRFMT_UUIRT: integer = $0;
UUIRTDRV_IRFMT_PRONTO: integer = $10;
UUIRTDRV_IRFMT_LEARN_FORCERAW: integer = $100;
UUIRTDRV_IRFMT_LEARN_FORCESTRUC: integer = $200;
UUIRTDRV_IRFMT_LEARN_FORCEFREQ: integer = $400;
UUIRTDRV_IRFMT_LEARN_FREQDETECT: integer = $800;
UUIRTDRV_IRFMT_TRANSMIT_DC: integer = $80;

  type
  tIRCode = record
  codeData: array[0..15] of byte;
  end;

  type
  tUuInfo = record
  fwVersion: longint;
  protVersion: longint;
  fwDateDay: byte;
  fwDateMonth: byte;
  fwDateYear: byte;
  end;


  type
  TUIRT = class
  private
  FDrvHandle: longint;
  udata: integer;
  protected
  procedure openUIRT;
  procedure closeUIRT;
  public
  Info: tUuInfo;
  constructor Create;
  destructor Destroy; override;
  procedure transmit(IRCode: string);
  function GetConfig: integer;
  function SetConfig(config: integer): integer;
  end;

   TDynamicIRCodeArray = tIRCode;
   TDynamicUuInfoArray = tUuInfo;

    type
    TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    Memo2: TMemo;
    Memo3: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    private
    FDrvHandle: longint;
    udata: integer;
    Info: tUuInfo;
    public
    end;







var
   Form1: TForm1;
   TransmitCode:boolean;
   CodeToTransmit:String;

   function UUIRTGetDrvInfo(var uVersion: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTGetDrvInfo';

   function UUIRTGetDrvVersion(var uVersion: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTGetDrvVersion';

   function UUIRTOpen : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTOpen';

   function UUIRTClose(hHandle: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTClose';

   function UUIRTGetUUIRTInfo(hHandle: longint; var UuInfo: tUuInfo) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTGetUUIRTInfo';

   function UUIRTGetUUIRTConfig(hHandle: longint; var uConfig: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTGetUUIRTConfig';

   function UUIRTSetUUIRTConfig(hHandle: longint; uConfig: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTSetUUIRTConfig';

   function UUIRTTransmitIR(hHandle: longint; sIRCode: PChar; uCodeFormat: longint; uRepeatCount: longint; uInactivityWaitTime: longint; hEvent: longint; reserved0: longint; reserved1: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTTransmitIR';

   function UUIRTLearnIR(hHandle: longint; uCodeFormat: longint; szIRCode: longint; pProgressProc: longint; userData: longint; var pAbort: boolean; uParam1: longint; hEvent: longint; reserved0: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTLearnIR';

   function UUIRTSetReceiveCallback(hHandle: longint; pReceiveProc: longint; userData: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTSetReceiveCallback';

   procedure Rcv(p: pChar; userData: longint); stdcall;


implementation

{$R *.dfm}




  constructor TUIRT.Create;
  begin
  inherited Create;
  openUIRT;
  end;

  destructor TUIRT.Destroy;
  begin
  inherited Destroy;
  end;

// ---------------------------------------------------------------

  procedure TUIRT.openUIRT;

var

  drvAPIVersion: longint;
  drvDLLVersion: longint;
  res: longint;
  dllErr: longint;
  sErrMsg: string;
  begin

  ShowMessage('TUIRT.OpenUIRT');
  udata := 166;
  res := UUIRTGetDrvInfo(drvAPIVersion);

  if res = 0 then
  raise Exception.Create('(TUIRT.open) Unable to retrieve uuirtdrv version!');
  if drvAPIVersion <> $100 then
  raise Exception.Create('(TUIRT.open) Invalid uuirtdrv version!');
  res := 0;

  try
  res := UUIRTGetDrvVersion(drvDLLVersion);
  except
  On E: Exception do;
  end;

  if (res = 0) or (drvDLLVersion < 2610) then
  raise Exception.Create('(TUIRT.open) This application requires USB-UIRT API driver DLL (UUIRTDRV.DLL) version 2.6.1 or later. ' +
CRLF +'Please verify you are running the latest API DLL and that you''re using the latest version of USB-UIRT firmware!' +

CRLF +'If the problem persists, contact Technical Support!');

  FDrvHandle := UUIRTOpen();

  if FDrvHandle = INVALID_HANDLE_VALUE then begin
  dllErr := GetLastError();
  if dllErr = UUIRTDRV_ERR_NO_DLL then
  sErrMsg := ('Unable to find USB-UIRT Driver. Please make sure driver is Installed!')

  else if dllErr = UUIRTDRV_ERR_NO_DEVICE then
  sErrMsg := ('Unable to connect to USB-UIRT device! Please ensure device is connected to the computer!')

  else if dllErr = UUIRTDRV_ERR_NO_RESP then
  sErrMsg := ('Unable to communicate with USB-UIRT device! Please check connections and try again. if you still have problems, try unplugging and reconnecting your USB-UIRT. if problem persists, contact Technical Support!')

  else if dllErr = UUIRTDRV_ERR_VERSION then
  sErrMsg := ('Your USB-UIRT//s firmware is not compatible with this API DLL. Please verify you are running the latest API DLL and that you//re using the latest version of USB-UIRT firmware! if problem persists, contact Technical Support!')

else

  sErrMsg := ('Unable to initialize USB-UIRT (unknown error)!');
  raise Exception.Create('(TUIRT.open) ' + sErrMsg);
  end else begin

  res := UUIRTGetUUIRTInfo(FDrvHandle, Info);
  if res = 0 then
  raise Exception.Create('GetUUIRTInfo falied!');
  res := UUIRTSetReceiveCallback(FDrvHandle, integer(@Rcv), integer(self));
  end;

  if TransmitCode=True then
  begin
  UUIRTTransmitIR(FDrvHandle, Pchar(CodeToTransmit), UUIRTDRV_IRFMT_PRONTO, 10, 0, 0, 0, 0);
  TransmitCode:=False;
  end;

  end;

  procedure TUIRT.closeUIRT;
  begin
  if FDrvHandle <> 0 then UUIRTClose(FDrvHandle);
  end;

// ---------------------------------------------------------------

  function TUIRT.SetConfig(config: integer): integer;
  begin
  Result := UUIRTSetUUIRTConfig(FDrvHandle, config);
  end;

// ---------------------------------------------------------------

  function TUIRT.GetConfig: integer;
  var
  uconfig: longint;
  begin
  if UUIRTGetUUIRTConfig(FDrvHandle, uconfig) <> 0 then begin
  Result := uconfig;
  end else begin
  Result := -1;
  end;
  end;

// ---------------------------------------------------------------

  procedure TUIRT.transmit(IRCode: string);
  var
  res: longint;
  IRCodeFormat: longint;
  begin

  If FDrvHandle = 0 then
  raise Exception.Create('(TUIRT.transmit) UIRT communication handle is null.');
  IRCodeFormat := UUIRTDRV_IRFMT_UUIRT;
  res := UUIRTTransmitIR(FDrvHandle, PChar(IRCode), IRCodeFormat, 1, 0, 0, 0, 0);

  if res = 0 then
  raise Exception.Create('(TUIRT.transmit) UIRT transmit failed.');
  end;

// ---------------------------------------------------------------

  procedure Rcv(p: pChar; userData: longint); stdcall;
  var
  myObj: TUIRT;
  j: integer;

  begin
  myObj := TUIRT(userData);
  Form1.Memo1.Lines.Add(' udata='+IntToStr(myObj.udata));
  Form1.Memo1.Lines.Add(' IREventStr='+String(p));
  end;

// ---------------------------------------------------------------

  procedure TForm1.Button1Click(Sender: TObject);
  begin
  TUIRT.Create;
  end;

// ---------------------------------------------------------------

  procedure TForm1.Button2Click(Sender: TObject);
  begin
  TransmitCode:=True;
  CodeToTransmit:=Memo2.Text;
  TUIRT.Create;
  end;

  procedure TForm1.FormCreate(Sender: TObject);
  begin
  TransmitCode:=False;
  memo1.Clear;
  memo2.Clear;
  memo3.Clear;
  Memo2.text:='0000 006F 0000 000C 002F 0010 002F 0010 002F 0010 002F 0010 0010 002F 0010 002F 0010 002F 0010 002F 0010 002F 002F 0010 0010 002F 0010 0998';
  Memo3.Text:='Click Button 1, Then click OK in Message Box, now point your IR remote control at USB UIRT and press a button, display in memo1 should change***** Click Button 2 then click ok in message box, the code in memo 2 should be transmitted by USB UIRT';

  end;

end.
isi4h
 
Posts: 2
Joined: Tue Apr 15, 2008 11:27 pm


Return to Developers

Who is online

Users browsing this forum: No registered users and 16 guests

cron