procedure TUIRT.openUIRT;
var
drvAPIVersion: longint;
drvDLLVersion: longint;
res: longint;
dllErr: longint;
sErrMsg: string;
// tlp: TLongPtr;
begin
// Get USB-UIRT *driver* information. Note that this call does not actually
// communicate with the USB-UIRT hardware. Instead, its purpose is solely to
// retrieve version information about the API *driver*. This and GetDrvVersion are
// the only API calls (besides UUIRTOpen) which can be performed without a driver
// handle (prior to opening the driver via UUIRTOpen).
res := UUIRTGetDrvInfo(drvAPIVersion);
if res = 0 then
raise Exception.Create('(TUIRT.open) Unable to retrieve uuirtdrv version!');
// Check the API version. This Application is written to be compatible with
// driver API version 1.0 (0x100)
if drvAPIVersion <> $100 then
raise Exception.Create('(TUIRT.open) Invalid uuirtdrv version!');
// Get the Driver DLL Revision #. This is necessary for this VB app since it this
// app relies on a newer feature of the LearnIR() function which does not block. This
// new non-blocking ability is only available in DLL versions 2.6.1 or later.
// note: This API call does not exist in versions prior to 2.6.1, so we use try/except
// to trap this condition.
res := 0;
try
res := UUIRTGetDrvVersion(drvDLLVersion);
except
On E: Exception do; // Swallow exception.
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!');
// Open a communications link with the USB-UIRT...
// Obtain a handle to the USB-UIRT via the UUIRTOpen call. if successful, a handle
// is returned which we *must* use in all subsequent APi calls.
FDrvHandle := UUIRTOpen();
// if Open call failed, we will be returned an INVALID_HANDLE_VALUE and need to look
// at the error to determine what went wrong...
if FDrvHandle = INVALID_HANDLE_VALUE then
begin
// Get the last DLL error using the WIN API GetLastError() call.
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
// NOTE!!!: Learn function sample code and associated callback usage is not implemented yet.
// if Open was successful, we//ll want to register a receive callback function
// for the USB-UIRT API to call each time an IR code is received.
// res = UUIRTSetReceiveCallback(hDrvHandle, AddressOf IRReceiveCallback, Me);
end;
end;
type
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Structure definitions:
// Define a structure for received IR codes.
// Received IR codes are 12-ASCII bytes longint, and are passed via a callback
// as a null-terminted string. Since VB handles strings differently, we
// define a byte array and convert it to a VB string inside the callback function.
tIRCode = record
codeData: array[0..15] of byte;
end;
TDynamicIRCodeArray = array of tIRCode;
// Define a structure to hold UUINFO data for the UUIRTGetUUIRTInfo function call...
tUuInfo = record
fwVersion: longint;
protVersion: longint;
fwDateDay: byte;
fwDateMonth: byte;
fwDateYear: byte;
end;
TDynamicUuInfoArray = array of tUuInfo;
TUIRTCommThread = class;
TUIRT = class
private
FDrvHandle: longint; // Handle used to communicate with the UIRT.
FUIRTCommThread: TUIRTCommThread;
protected
// Open the UIRT and get version information from it.
procedure openUIRT;
procedure closeUIRT;
public
constructor Create;
destructor Destroy; override;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// USB-UIRT DLL API Function Declarations....
// function UUIRTGetDrvInfo(var uVersion: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTGetDrvVersion';
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 UUIRTOpen : TLongPtr; 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';