H
hjchen_tx
Unregistered / Unconfirmed
GUEST, unregistred user!
1、OpenComm 函数原型:int OpenComm(HANDLE *hCom,char *com_port)
功能说明:打开计算机串口。
输入参数:
●——hCom:串口句柄
●——com_port:串口文件名
调用例程:
char comm[]="COM1";
OpenComm(&h_Com,comm);
if(h_Com != INVALID_HANDLE_VALUE)
{ AfxMessageBox("打开串口成功!"); }
else
{ AfxMessageBox("打开串口失败!"); }
2、CloseComm 函数原型:void CloseComm(HANDLE comm)
功能说明:关闭计算机串口。
输入参数: ●——comm:串口句柄
调用例程: CloseComm(h_Com);
3、TagIdentify 函数原型:int TagIdentify(HANDLE comm,unsigned char *receive)
功能说明:单标签ID识别
输入参数:
●——comm:串口句柄
●——*receive:接收ID的数组地址
返回结果:调用成功返回1,否则返回-1。
调用例程:
int flag;
unsigned char receive[20];
flag=TagIdentify(h_Com,receive);
if(flag==1) {
CString string;
string.Format("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",receive[0],receive[1],receive[2],receive[3],receive[4],receive[5],receive[6],receive[7],receive[8],receive[9],receive[10],receive[11]);
AfxMessageBox(string); }
else AfxMessageBox("Operation Error!");
头文件:
#ifndef _EPCDEMODLL_H
#define _EPCDEMODLL_H
extern "C" __declspec(dllexport) int OpenComm(HANDLE *hCom,char *com_port);
extern "C" __declspec(dllexport) void CloseComm(HANDLE comm);
extern "C" __declspec(dllexport) int InitializeTag(HANDLE comm);
extern "C" __declspec(dllexport) int TagIdentify(HANDLE comm,unsigned char *recieve);//EPC标签识别
extern "C" __declspec(dllexport) int ReadSoftwareVersion(HANDLE comm,char *receive);
extern "C" __declspec(dllexport) int StopWorkSetting(HANDLE comm);
extern "C" __declspec(dllexport) int TagRead(HANDLE comm,int length,unsigned char membank,unsigned char address,unsigned char *receive);
extern "C" __declspec(dllexport) int TagWriteSingleWord(HANDLE comm,unsigned char membank,unsigned char address,int data);
extern "C" __declspec(dllexport) int TagLock(HANDLE comm,unsigned char locktype);
extern "C" __declspec(dllexport) int TagKill(HANDLE comm,unsigned char pa1,unsigned char pa2,unsigned char pa3,unsigned char pa4);
extern "C" __declspec(dllexport) int ResetReader(HANDLE comm);
extern "C" __declspec(dllexport) int QueryReaderSingleParameter(HANDLE comm,unsigned char msb,unsigned char lsb,unsigned char *receive);
extern "C" __declspec(dllexport) int QueryReaderMultiParameter(HANDLE comm,unsigned char length,unsigned char msb,unsigned char lsb,unsigned char *receive);
extern "C" __declspec(dllexport) int SetReaderSignleParameter(HANDLE comm,unsigned char msb,unsigned char lsb,unsigned char data);
extern "C" __declspec(dllexport) int SetReaderMultiParameter(HANDLE comm,unsigned char length,unsigned char msb,unsigned char lsb,unsigned char *write_data);
extern "C" __declspec(dllexport) int ReadMultiTag(HANDLE comm,unsigned char *count,unsigned char *id_buffer);
extern "C" __declspec(dllexport) int AfreshIdentifyTag(HANDLE comm);
extern "C" __declspec(dllexport) int AfreshGetData(HANDLE comm,unsigned char *count,unsigned char *data);
#endif
我的转换
unit linkdll;
interface
uses windows;
function OpenComm(var hCom: PHandle; com_port: pChar): Integer; stdcall;
function CloseComm(comm: THANDLE): Variant; stdcall;
function InitializeTag(comm: THANDLE): Integer; stdcall;
function TagIdentify(comm: THANDLE; recieve: pchar): Integer; stdcall; //EPC标签识别
function ReadSoftwareVersion(comm:THANDLE ;receiveChar):Integer; stdcall;
function StopWorkSetting(comm: THANDLE): Integer; stdcall;
function TagRead(comm: THANDLE; length: Integer; membank: Char; address: Char; receive: PChar): Integer; stdcall;
function TagWriteSingleWord(comm: THANDLE; membank: Char; address: Char; data: Integer): Integer; stdcall;
//function TagLock(HANDLE comm,unsigned char locktype):Integer; stdcall;
//function TagKill(HANDLE comm,unsigned char pa1,unsigned char pa2,unsigned char pa3,unsigned char pa4):Integer; stdcall;
//function ResetReader(HANDLE comm):Integer; stdcall;
//function QueryReaderSingleParameter(HANDLE comm,unsigned char msb,unsigned char lsb,unsigned char *receive):Integer; stdcall;
//function QueryReaderMultiParameter(HANDLE comm,unsigned char length,unsigned char msb,unsigned char lsb,unsigned char *receive):Integer; stdcall;
//function SetReaderSignleParameter(HANDLE comm,unsigned char msb,unsigned char lsb,unsigned char data):Integer; stdcall;
//function SetReaderMultiParameter(HANDLE comm,unsigned char length,unsigned char msb,unsigned char lsb,unsigned char *write_data):Integer; stdcall;
//function ReadMultiTag(HANDLE comm,unsigned char *count,unsigned char *id_buffer):Integer; stdcall;
//function AfreshIdentifyTag(HANDLE comm):Integer; stdcall;
//function AfreshGetData(HANDLE comm,unsigned char *count,unsigned char *data):Integer; stdcall;
implementation
function OpenComm; external 'EPCDemoDll.dll' name 'OpenComm';
function CloseComm; external 'EPCDemoDll.dll' name 'CloseComm';
function ReadSoftwareVersion; external 'EPCDemoDll.dll' name 'ReadSoftwareVersion';
function InitializeTag; external 'EPCDemoDll.dll' name 'InitializeTag';
function TagIdentify; external 'EPCDemoDll.dll' name 'TagIdentify';
function StopWorkSetting; external 'EPCDemoDll.dll' name 'StopWorkSetting';
function TagRead; external 'EPCDemoDll.dll' name 'TagRead';
function TagWriteSingleWord; external 'EPCDemoDll.dll' name 'TagWriteSingleWord';
end.
主程序:
unit epc;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, linkdll, OleCtrls, MSCommLib_TLB, StrUtils;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button3: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
hCom: THandle;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//1个字节--BYTE 2个字节--WORD 4个字节---DWORD
procedure TForm1.Button1Click(Sender: TObject);
var receive: array[0..50] of Char;
resultint: Integer;
com_port: string;
resultstr: string;
phComHandle;
begin
com_port := 'COM1';
hCom:=1;
phCom:=0;
resultint := OpenComm(phcom, PChar(com_port));
if (resultint <> -1) then begin
Edit3.Text := IntToStr(hCom);
StopWorkSetting(hCom);
resultint := TagIdentify(hCom, @receive);
if (resultint <> -1) then begin
resultstr := '';
resultstr := format('%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x', [receive[0], receive[1], receive[2], receive[3], receive[4], receive[5], receive[6], receive[7], receive[8], receive[9], receive[10], receive[11]]);
Edit1.Text := resultstr;
end else begin
ShowMessage('读数失败!');
end;
end else begin
ShowMessage('打开失败!');
end;
// CloseComm(hCom);
end;
end.
功能说明:打开计算机串口。
输入参数:
●——hCom:串口句柄
●——com_port:串口文件名
调用例程:
char comm[]="COM1";
OpenComm(&h_Com,comm);
if(h_Com != INVALID_HANDLE_VALUE)
{ AfxMessageBox("打开串口成功!"); }
else
{ AfxMessageBox("打开串口失败!"); }
2、CloseComm 函数原型:void CloseComm(HANDLE comm)
功能说明:关闭计算机串口。
输入参数: ●——comm:串口句柄
调用例程: CloseComm(h_Com);
3、TagIdentify 函数原型:int TagIdentify(HANDLE comm,unsigned char *receive)
功能说明:单标签ID识别
输入参数:
●——comm:串口句柄
●——*receive:接收ID的数组地址
返回结果:调用成功返回1,否则返回-1。
调用例程:
int flag;
unsigned char receive[20];
flag=TagIdentify(h_Com,receive);
if(flag==1) {
CString string;
string.Format("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",receive[0],receive[1],receive[2],receive[3],receive[4],receive[5],receive[6],receive[7],receive[8],receive[9],receive[10],receive[11]);
AfxMessageBox(string); }
else AfxMessageBox("Operation Error!");
头文件:
#ifndef _EPCDEMODLL_H
#define _EPCDEMODLL_H
extern "C" __declspec(dllexport) int OpenComm(HANDLE *hCom,char *com_port);
extern "C" __declspec(dllexport) void CloseComm(HANDLE comm);
extern "C" __declspec(dllexport) int InitializeTag(HANDLE comm);
extern "C" __declspec(dllexport) int TagIdentify(HANDLE comm,unsigned char *recieve);//EPC标签识别
extern "C" __declspec(dllexport) int ReadSoftwareVersion(HANDLE comm,char *receive);
extern "C" __declspec(dllexport) int StopWorkSetting(HANDLE comm);
extern "C" __declspec(dllexport) int TagRead(HANDLE comm,int length,unsigned char membank,unsigned char address,unsigned char *receive);
extern "C" __declspec(dllexport) int TagWriteSingleWord(HANDLE comm,unsigned char membank,unsigned char address,int data);
extern "C" __declspec(dllexport) int TagLock(HANDLE comm,unsigned char locktype);
extern "C" __declspec(dllexport) int TagKill(HANDLE comm,unsigned char pa1,unsigned char pa2,unsigned char pa3,unsigned char pa4);
extern "C" __declspec(dllexport) int ResetReader(HANDLE comm);
extern "C" __declspec(dllexport) int QueryReaderSingleParameter(HANDLE comm,unsigned char msb,unsigned char lsb,unsigned char *receive);
extern "C" __declspec(dllexport) int QueryReaderMultiParameter(HANDLE comm,unsigned char length,unsigned char msb,unsigned char lsb,unsigned char *receive);
extern "C" __declspec(dllexport) int SetReaderSignleParameter(HANDLE comm,unsigned char msb,unsigned char lsb,unsigned char data);
extern "C" __declspec(dllexport) int SetReaderMultiParameter(HANDLE comm,unsigned char length,unsigned char msb,unsigned char lsb,unsigned char *write_data);
extern "C" __declspec(dllexport) int ReadMultiTag(HANDLE comm,unsigned char *count,unsigned char *id_buffer);
extern "C" __declspec(dllexport) int AfreshIdentifyTag(HANDLE comm);
extern "C" __declspec(dllexport) int AfreshGetData(HANDLE comm,unsigned char *count,unsigned char *data);
#endif
我的转换
unit linkdll;
interface
uses windows;
function OpenComm(var hCom: PHandle; com_port: pChar): Integer; stdcall;
function CloseComm(comm: THANDLE): Variant; stdcall;
function InitializeTag(comm: THANDLE): Integer; stdcall;
function TagIdentify(comm: THANDLE; recieve: pchar): Integer; stdcall; //EPC标签识别
function ReadSoftwareVersion(comm:THANDLE ;receiveChar):Integer; stdcall;
function StopWorkSetting(comm: THANDLE): Integer; stdcall;
function TagRead(comm: THANDLE; length: Integer; membank: Char; address: Char; receive: PChar): Integer; stdcall;
function TagWriteSingleWord(comm: THANDLE; membank: Char; address: Char; data: Integer): Integer; stdcall;
//function TagLock(HANDLE comm,unsigned char locktype):Integer; stdcall;
//function TagKill(HANDLE comm,unsigned char pa1,unsigned char pa2,unsigned char pa3,unsigned char pa4):Integer; stdcall;
//function ResetReader(HANDLE comm):Integer; stdcall;
//function QueryReaderSingleParameter(HANDLE comm,unsigned char msb,unsigned char lsb,unsigned char *receive):Integer; stdcall;
//function QueryReaderMultiParameter(HANDLE comm,unsigned char length,unsigned char msb,unsigned char lsb,unsigned char *receive):Integer; stdcall;
//function SetReaderSignleParameter(HANDLE comm,unsigned char msb,unsigned char lsb,unsigned char data):Integer; stdcall;
//function SetReaderMultiParameter(HANDLE comm,unsigned char length,unsigned char msb,unsigned char lsb,unsigned char *write_data):Integer; stdcall;
//function ReadMultiTag(HANDLE comm,unsigned char *count,unsigned char *id_buffer):Integer; stdcall;
//function AfreshIdentifyTag(HANDLE comm):Integer; stdcall;
//function AfreshGetData(HANDLE comm,unsigned char *count,unsigned char *data):Integer; stdcall;
implementation
function OpenComm; external 'EPCDemoDll.dll' name 'OpenComm';
function CloseComm; external 'EPCDemoDll.dll' name 'CloseComm';
function ReadSoftwareVersion; external 'EPCDemoDll.dll' name 'ReadSoftwareVersion';
function InitializeTag; external 'EPCDemoDll.dll' name 'InitializeTag';
function TagIdentify; external 'EPCDemoDll.dll' name 'TagIdentify';
function StopWorkSetting; external 'EPCDemoDll.dll' name 'StopWorkSetting';
function TagRead; external 'EPCDemoDll.dll' name 'TagRead';
function TagWriteSingleWord; external 'EPCDemoDll.dll' name 'TagWriteSingleWord';
end.
主程序:
unit epc;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, linkdll, OleCtrls, MSCommLib_TLB, StrUtils;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button3: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
hCom: THandle;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//1个字节--BYTE 2个字节--WORD 4个字节---DWORD
procedure TForm1.Button1Click(Sender: TObject);
var receive: array[0..50] of Char;
resultint: Integer;
com_port: string;
resultstr: string;
phComHandle;
begin
com_port := 'COM1';
hCom:=1;
phCom:=0;
resultint := OpenComm(phcom, PChar(com_port));
if (resultint <> -1) then begin
Edit3.Text := IntToStr(hCom);
StopWorkSetting(hCom);
resultint := TagIdentify(hCom, @receive);
if (resultint <> -1) then begin
resultstr := '';
resultstr := format('%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x', [receive[0], receive[1], receive[2], receive[3], receive[4], receive[5], receive[6], receive[7], receive[8], receive[9], receive[10], receive[11]]);
Edit1.Text := resultstr;
end else begin
ShowMessage('读数失败!');
end;
end else begin
ShowMessage('打开失败!');
end;
// CloseComm(hCom);
end;
end.