常见磁卡读写问题 ( 积分: 50 )

  • 主题发起人 主题发起人 slqbs-gy
  • 开始时间 开始时间
S

slqbs-gy

Unregistered / Unconfirmed
GUEST, unregistred user!
大家好!
这两天我在学习怎么使用磁卡,我手上的读写器是‘YD-602’系列的。
我用这个产品自带的动态连接库,进行读写。但在用的过程中遇到一个郁闷的问题:就是数据可以写到磁卡上但却不能读出来,代码如下:
unit unitcikacard;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ComCtrls, ToolWin, StdCtrls, SPComm;

type
TForm1 = class(TForm)
CoolBar1: TCoolBar;
ToolBar1: TToolBar;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
Edit1: TEdit;
Comm1: TComm;
SpeedButton4: TSpeedButton;
Edit2: TEdit;
Edit3: TEdit;
SpeedButton5: TSpeedButton;
ListBox1: TListBox;
Edit4: TEdit;
Edit5: TEdit;
Label1: TLabel;
Label2: TLabel;

procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
//WTr23card(char* comn,char* inTr2str,char* inTr3str)
procedure TForm1.SpeedButton1Click(Sender: TObject);//写卡
type
TIntFunc=function(comn:string;inTr2str:string):integer;stdcall;
var
Th:Thandle;
Tf:TIntFunc;
Tp:TFarProc;
begin
Th:=LoadLibrary('rwcommnew.dll'); {装载DLL}
if Th>0 then
try
Tp:=GetProcAddress(Th,PChar('WTr2card'));
if Tp<>nil
then begin
Tf:=TIntFunc(Tp);
Edit1.Text:=IntToStr(Tf('COM1',Edit2.Text)); {调用WTr2card函数}
showmessage(Edit2.Text);
showmessage('写卡成功!');
end
else
ShowMessage('WTr2card函数没有找到');
finally
FreeLibrary(Th); {释放DLL}
end
else
ShowMessage('rwcommnew.dll没有找到');
end;

procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
comm1.StartComm; //打开comm; 退出是应用comm1.StopComm结束
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
Comm1.StopComm;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);//读卡
type
TIntFunc1=function(comn:string;inTr2str:string):integer;stdcall;
var
Th:Thandle;
Tf:TIntFunc1;
Tp:TFarProc;
s1,s2:string;
begin
Th:=LoadLibrary('rwcommnew.dll'); {装载DLL}
if Th>0 then
try
Tp:=GetProcAddress(Th,PChar('RTr2card'));
if Tp<>nil
then begin
Tf:=TIntFunc1(Tp);
Edit1.Text:=IntToStr(Tf('COM1',s1)); {调用RTr2card函数}
showmessage(s1);
if s1='' then begin showmessage('读卡不成功!');exit; end
else
showmessage('读卡成功!');
Edit2.Text:=s1;
end
else
ShowMessage('RTr2card函数没有找到');
finally
FreeLibrary(Th); {释放DLL}
end
else
ShowMessage('rwcommnew.dll没有找到');

end;

procedure TForm1.SpeedButton5Click(Sender: TObject); //写进的卡数据
begin
Edit2.Text:=Edit4.Text+Edit5.Text;
end;

end.
 
大家好!
这两天我在学习怎么使用磁卡,我手上的读写器是‘YD-602’系列的。
我用这个产品自带的动态连接库,进行读写。但在用的过程中遇到一个郁闷的问题:就是数据可以写到磁卡上但却不能读出来,代码如下:
unit unitcikacard;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ComCtrls, ToolWin, StdCtrls, SPComm;

type
TForm1 = class(TForm)
CoolBar1: TCoolBar;
ToolBar1: TToolBar;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
Edit1: TEdit;
Comm1: TComm;
SpeedButton4: TSpeedButton;
Edit2: TEdit;
Edit3: TEdit;
SpeedButton5: TSpeedButton;
ListBox1: TListBox;
Edit4: TEdit;
Edit5: TEdit;
Label1: TLabel;
Label2: TLabel;

procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
//WTr23card(char* comn,char* inTr2str,char* inTr3str)
procedure TForm1.SpeedButton1Click(Sender: TObject);//写卡
type
TIntFunc=function(comn:string;inTr2str:string):integer;stdcall;
var
Th:Thandle;
Tf:TIntFunc;
Tp:TFarProc;
begin
Th:=LoadLibrary('rwcommnew.dll'); {装载DLL}
if Th>0 then
try
Tp:=GetProcAddress(Th,PChar('WTr2card'));
if Tp<>nil
then begin
Tf:=TIntFunc(Tp);
Edit1.Text:=IntToStr(Tf('COM1',Edit2.Text)); {调用WTr2card函数}
showmessage(Edit2.Text);
showmessage('写卡成功!');
end
else
ShowMessage('WTr2card函数没有找到');
finally
FreeLibrary(Th); {释放DLL}
end
else
ShowMessage('rwcommnew.dll没有找到');
end;

procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
comm1.StartComm; //打开comm; 退出是应用comm1.StopComm结束
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
Comm1.StopComm;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);//读卡
type
TIntFunc1=function(comn:string;inTr2str:string):integer;stdcall;
var
Th:Thandle;
Tf:TIntFunc1;
Tp:TFarProc;
s1,s2:string;
begin
Th:=LoadLibrary('rwcommnew.dll'); {装载DLL}
if Th>0 then
try
Tp:=GetProcAddress(Th,PChar('RTr2card'));
if Tp<>nil
then begin
Tf:=TIntFunc1(Tp);
Edit1.Text:=IntToStr(Tf('COM1',s1)); {调用RTr2card函数}
showmessage(s1);
if s1='' then begin showmessage('读卡不成功!');exit; end
else
showmessage('读卡成功!');
Edit2.Text:=s1;
end
else
ShowMessage('RTr2card函数没有找到');
finally
FreeLibrary(Th); {释放DLL}
end
else
ShowMessage('rwcommnew.dll没有找到');

end;

procedure TForm1.SpeedButton5Click(Sender: TObject); //写进的卡数据
begin
Edit2.Text:=Edit4.Text+Edit5.Text;
end;

end.
 
怎么没有人来呢?问题解决就给分哦。对这个问题真的很迫切哦!
 
1、是Memory卡?
2、TIntFunc1=function(comn:string;inTr2str:string):integer;stdcall;
应该是out inTr2str:string
建议string类型改为-> pChar
 
TO:xianguo
我的是磁卡,
试了你的方法,编译时没有错误但当读卡时,会报错的!
 
和我遇到的问题一样!
我现在不用他们的DLL,我根据他们的协议自己写了!不知道是不是通用的。
不过我们的型号是“ZY-602”,估计和你差不多。
 
问题解决!
还是按照‘xianguo’的方法!
谢谢大家参与!
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
729
import
I
I
回复
0
查看
485
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部