سلام.
چون خودم خيلي عذاب كشيدم تا اين دستگاه و دستگاه RFT-23x را با خود MF_API.dll و نه با كامپوننت راه بندازم، كلاسي رو آماده كردم تا دوستان ديگه هم استفاده كنن. اين كلاس رو خودم نوشتم و به راحتي مي تونيد از اون استفاده كنيد. نحوه استفاده از اون در توضيحات فايل اومده.
موفق باشين.
{
Author: Ahmad.daneshvar (romixery@gmail.com)
Feb-2012 Fractal Technologies® group
************************************************** ********
Release Info
************************************************** ********
RFID library for RFT-23x Reader Device - V1.0
Need to 'MF_API.dll' and other DLLs:
"CC3260.dll"
"CC3260MT.dll"
"EasyD12.dll"
Passed x32 and x64 Machine test on Windows 7.
************************************************** *********
Function List
************************************************** *********
function loadDll;
destructor freeDll;
function rfGetDLL_Ver;
function rfControlBuzzer;
function rfInitComm;
function rfControlLED;
function rfRequest;
function rfAnticoll;
************************************************** *********
Example and Usage
************************************************** *********
Usage and Example:
var
dev: TDevice;
begin
dev := TDevice.create;
dev.loadDLL('MF_API.dll');
dev.rfInitComm(pnUSB, 9600);
dev.rfControlBuzzer(0, 30);
dev.freeDll;
end
************************************************** *********}
unit Device;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Dialogs, vcl.Forms;
type
TPortName = (pnUSB, pnCOM1, pnCOM2, pnCOM3, pnCOM4, pnCOM5, pnCOM6, pnCOM7, pnCOM8);
TDevice = class
private
handle : THandle;
dllLoaded : Boolean;
function byteAsString(arr : array of Byte) : String;
function byteToString(arr : array of Byte) : String;
function hexToInt(hexNum : String) : Integer;
public
constructor Create;
function loadDll(dllName : PWideChar) : Boolean;
destructor freeDll;
function rfGetDLL_Ver (var rVer : String) : Integer;
function rfControlBuzzer (DeviceAddr : Integer; BeepTime : Integer) : Integer;
function rfInitComm (portname : TPortName; baud : LongInt) : Integer;
function rfControlLED (DeviceAddr : Integer; LED1 : Integer; LED2 : Integer) : Integer;
function rfRequest (DeviceAddr : Integer; mode : Integer; var cardType : String) : Integer;
function rfAnticoll (DeviceAddr : Integer; var serialNumber : String) : Integer;
end;
TDeviceUtil = class
private
const BEEP_TIME : Integer = 10;
const DELAY_TIME_BLANK : Integer = 100;
const DELAY_TIME_LED : Integer = 2000;
public
procedure _MODE_OK(dev : TDevice);
procedure _MODE_ERROR(dev : TDevice);
end;
implementation
{ TDevice }
procedure LongDelay(DelayMs : Cardinal);
var StopTime : Cardinal;
begin
StopTime := GetTickCount + DelayMs;
while (GetTickCount < StopTime) do
begin
Application.ProcessMessages;
Sleep(1);
end;
end;
function TDevice.byteAsString(arr: array of Byte): String;
var
ind: Integer;
val: String;
begin
for ind := 0 to length(arr) do
val := val + intToStr(arr[ind]);
result := val + #0;
end;
function TDevice.byteToString(arr: array of Byte): String;
var
ind: Integer;
val: String;
begin
for ind := 0 to length(arr) do
val := val + chr(arr[ind]);
result := val + #0;
end;
constructor TDevice.Create;
begin
end;
destructor TDevice.freeDll;
begin
FreeLibrary(handle);
dllLoaded := false;
end;
function TDevice.hexToInt(hexNum: String): Integer;
begin
result := strToInt('$' + hexNum);
end;
function TDevice.loadDll(dllName: PWideChar): Boolean;
begin
handle := LoadLibrary(dllName);
if handle >= 32 then
result := true
else
result := false;
dllLoaded := result;
end;
function TDevice.rfAnticoll(DeviceAddr: Integer;
var serialNumber: String): Integer;
var
MF_Anticoll_DLL : Function (DeviceAddr : Integer;
snr : array of byte) : Integer; stdcall;
ba : array [0..3] of Byte;
begin
if (not dllLoaded) then exit;
MF_Anticoll_DLL := GetProcAddress(handle, 'MF_Anticoll');
result := MF_Anticoll_DLL(DeviceAddr, ba);
serialNumber := byteAsString(ba);
end;
function TDevice.rfControlLED(DeviceAddr, LED1, LED2: Integer): Integer;
var
MF_ControlLED_DLL : Function (DeviceAddr : Integer; LED1 : Integer;
LED2 : Integer) : Integer; stdcall;
begin
if (not dllLoaded) then exit;
MF_ControlLED_DLL := GetProcAddress(handle, 'MF_ControlLED');
result := MF_ControlLED_DLL(DeviceAddr, LED1, LED2);
end;
function TDevice.rfControlBuzzer(DeviceAddr, BeepTime: Integer): Integer;
var
MF_Control_Buzzer_DLL : Function (DeviceAddr : Integer;
BeepTime : Integer) : Integer; stdcall;
begin
if (not dllLoaded) then exit;
MF_Control_Buzzer_DLL := GetProcAddress(handle, 'MF_ControlBuzzer');
result := MF_Control_Buzzer_DLL(DeviceAddr, BeepTime);
end;
function TDevice.rfGetDLL_Ver(var rVer: String): Integer;
var
MF_GetDLL_Ver_DLL : Function (rVer : array of byte) : Integer; stdcall;
ba : array [0..31] of Byte;
begin
if (not dllLoaded) then exit;
MF_GetDLL_Ver_DLL := GetProcAddress(handle, 'MF_GetDLL_Ver');
result := MF_GetDLL_Ver_DLL(ba);
rVer := byteToString(ba) + #0;
end;
function TDevice.rfInitComm(portname: TPortName; baud: Integer): Integer;
var
MF_InitComm_DLL : Function (portname : array of Byte; baud : Integer) : Integer; stdcall;
ba: array [0..3] of Byte;
begin
if (not dllLoaded) then exit;
MF_InitComm_DLL := GetProcAddress(handle, 'MF_InitComm');
case portName of
pnUSB: begin
ba[0] := ord('U'); ba[1] := ord('S'); ba[2] := ord('B'); ba[3] := ord('');
end;
pnCOM1: begin
ba[0] := ord('C'); ba[1] := ord('O'); ba[2] := ord('M'); ba[3] := ord('1');
end;
pnCOM2: begin
ba[0] := ord('C'); ba[1] := ord('O'); ba[2] := ord('M'); ba[3] := ord('2');
end;
pnCOM3: begin
ba[0] := ord('C'); ba[1] := ord('O'); ba[2] := ord('M'); ba[3] := ord('3');
end;
pnCOM4: begin
ba[0] := ord('C'); ba[1] := ord('O'); ba[2] := ord('M'); ba[3] := ord('4');
end;
pnCOM5: begin
ba[0] := ord('C'); ba[1] := ord('O'); ba[2] := ord('M'); ba[3] := ord('5');
end;
pnCOM6: begin
ba[0] := ord('C'); ba[1] := ord('O'); ba[2] := ord('M'); ba[3] := ord('6');
end;
pnCOM7: begin
ba[0] := ord('C'); ba[1] := ord('O'); ba[2] := ord('M'); ba[3] := ord('7');
end;
pnCOM8: begin
ba[0] := ord('C'); ba[1] := ord('O'); ba[2] := ord('M'); ba[3] := ord('8');
end;
end;
result := MF_InitComm_DLL(ba, baud);
end;
function TDevice.rfRequest(DeviceAddr, mode: Integer;
var cardType: String): Integer;
var
MF_Request_DLL : Function (DeviceAddr : Integer; mode : Integer;
CardType : array of byte) : Integer; stdcall;
ba: array [0..1] of Byte;
begin
if (not dllLoaded) then exit;
MF_Request_DLL := GetProcAddress(handle, 'MF_Request');
result := MF_Request_DLL(DeviceAddr, mode, ba);
cardType := byteAsString(ba);
end;
{ TDeviceUtil }
procedure TDeviceUtil._MODE_ERROR(dev : TDevice);
begin
dev.rfControlLED(0, 0, 1);
dev.rfControlBuzzer(0, BEEP_TIME);
LongDelay(DELAY_TIME_BLANK);
dev.rfControlBuzzer(0, BEEP_TIME);
LongDelay(DELAY_TIME_LED);
dev.rfControlLED(0, 0, 0);
end;
procedure TDeviceUtil._MODE_OK(dev: TDevice);
begin
dev.rfControlLED(0, 1, 0);
dev.rfControlBuzzer(0, BEEP_TIME);
LongDelay(DELAY_TIME_LED);
dev.rfControlLED(0, 0, 0);
end;
end.