📄 unitmain.~pas
字号:
unit UnitMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, PanelXMXControl_TLB, StdCtrls, StrUtils;
type
TFrmMain = class(TForm)
GpCommands: TGroupBox;
GpParameters: TGroupBox;
GpResponse: TGroupBox;
BtConnect: TButton;
BtDisconnect: TButton;
BtSelectChip: TButton;
BtSelectPage: TButton;
BtRead: TButton;
BtWrite: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
CmbKey: TComboBox;
CmbPage: TComboBox;
CmbBlock: TComboBox;
LblConnectionState: TLabel;
LblSN: TLabel;
LblConfBlock: TLabel;
LblDataRead: TLabel;
MxPanel: TPanelXMX;
btLoadKeys: TButton;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure BtConnectClick(Sender: TObject);
procedure BtDisconnectClick(Sender: TObject);
procedure BtSelectChipClick(Sender: TObject);
procedure BtSelectPageClick(Sender: TObject);
procedure BtReadClick(Sender: TObject);
procedure BtWriteClick(Sender: TObject);
procedure btLoadKeysClick(Sender: TObject);
private { D閏larations priv閑s }
bOldCoupler: Boolean;
public
{ D閏larations publiques }
end;
var
FrmMain: TFrmMain;
implementation
{$R *.dfm}
procedure TFrmMain.FormCreate(Sender: TObject);
var
Index: Integer;
begin
// Combo boxes initialization
CmbKey.AddItem('No Auth', TObject.Create);
CmbKey.AddItem('Kd', TObject.Create);
CmbKey.AddItem('Kc', TObject.Create);
CmbKey.ItemIndex := 0;
for Index := 0 to 7 do CmbPage.AddItem(IntToStr(Index), TObject.Create);
CmbPage.ItemIndex := 0;
for Index := 0 to 31 do CmbBlock.AddItem(IntToStr(Index), TObject.Create);
CmbBlock.ItemIndex := 6;
end;
procedure TFrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
// Disconnect coupler
MxPanel.Disconnect;
end;
procedure TFrmMain.BtConnectClick(Sender: TObject);
var
iSwitchValue: Integer;
vCommandReturn: OleVariant;
sCommandReturn: String;
begin
// Connect coupler and test result
if not MxPanel.Connect then
ShowMessage('Connection failed')
else
begin
// Test coupler version
iSwitchValue := MxPanel.ISO7816T0SendCmd($80, $F2, $00, $00, $01, mt0dOut, '', 1, vCommandReturn);
sCommandReturn := vCommandReturn;
if (StrToInt(Midstr(sCommandReturn, 1, 3)) and 48) = 0 then
bOldCoupler := False
else
bOldCoupler := True;
// Update command access and display result
BtConnect.Enabled := False;
BtDisconnect.Enabled := True;
if bOldCoupler then
LblConnectionState.Caption := 'Coupler state : Connected (Old coupler)'
else
LblConnectionState.Caption := 'Coupler state : Connected (New coupler)';
end;
end;
procedure TFrmMain.BtDisconnectClick(Sender: TObject);
begin
// Disconnect coupler
MxPanel.Disconnect;
// Update command access and display defaults
BtConnect.Enabled := True;
BtDisconnect.Enabled := False;
LblConnectionState.Caption := 'Coupler state : Disconnected';
LblConfBlock.Caption := 'Page conf block : ';
LblSN.Caption := 'Serial Number : ';
LblDataRead.Caption := 'Data : ';
end;
procedure TFrmMain.BtSelectChipClick(Sender: TObject);
var
vBlock: OleVariant;
sSN: String;
begin
// SELECT with no authentification (done in PAGESEL)
if not MxPanel.SelectCard($00, $07, vBlock) then
ShowMessage('Selection error')
else
begin
sSN := vBlock;
sSN := MidStr(sSN, 4, 26);
LblSN.Caption := 'Serial number : ' + sSN;
end;
end;
procedure TFrmMain.BtSelectPageClick(Sender: TObject);
var
vBlock: OleVariant;
sConfBlock: String;
Key: TxMxKey;
begin
// Retreive authentification to use
case CmbKey.ItemIndex of
0: Key := mkNoAuth;
1: Key := mkKd;
2: Key := mkKc;
end;
// Retreive coupler generation
if bOldCoupler then
begin (*Old coupler*)
// Send PAGESEL command to chip
if MxPanel.SelectAuthPage(mkNoAuth, CmbPage.ItemIndex, vBlock) then
begin
// Manual authentification
if MxPanel.Authentify(Key, vBlock) then
begin
// Update result display
sConfBlock := vBlock;
LblConfBlock.Caption := 'Page SN : ' + sConfBlock;
end
else
ShowMessage('Page authentification failed');
end
else
ShowMessage('Page selection failed');
end
else
begin (*New coupler*)
// Use PAGESEL coupler command (with authentification)
if MxPanel.SelectPage(Key, CmbPage.ItemIndex, vBlock) then
begin
// Update result display
sConfBlock := vBlock;
LblConfBlock.Caption := 'Page conf block : ' + sConfBlock;
end
else
ShowMessage('Page selection failed');
end;
end;
procedure TFrmMain.BtReadClick(Sender: TObject);
var
vBlock: OleVariant;
sData: String;
begin
// READ content of selected block
if MxPanel.ReadBlock(CmbBlock.ItemIndex, 1, vBlock) then
begin
// Update result display
sData := vBlock;
LblDataRead.Caption := 'Data : ' + sData;
end
else
ShowMessage('Read Error');
end;
procedure TFrmMain.BtWriteClick(Sender: TObject);
begin
// WRITE data in block selected
if MxPanel.WriteBlock(CmbBlock.ItemIndex, 1, '$01$02$03$04$05$06$07$08') then
begin
// Update result display
LblDataRead.Caption := 'Data : Write complete -> $01$02$03$04$05$06$07$08';
end
else
ShowMessage('Write error');
end;
procedure TFrmMain.btLoadKeysClick(Sender: TObject);
begin
// Load exchange key
if not MxPanel.KeyLoading(mpkExchange, mklmXorKo, '$5C$BC$F1$DA$45$D5$FB$5F', '$5C$BC$F1$DA$45$D5$FB$5F') then
begin
ShowMessage('Exchange key loading error');
Exit;
end;
// Load Kc and Kd
if not MxPanel.KeyLoading(mpkP0Kd, mklmXorKe, '$5C$BC$F1$DA$45$D5$FB$5F', '$F0$E1$D2$C3$B4$A5$96$87') then
begin
ShowMessage('Debit key loading error');
Exit;
end;
if not MxPanel.KeyLoading(mpkP0Kc, mklmXorKe, '$5C$BC$F1$DA$45$D5$FB$5F', '$76$65$54$43$32$21$10$00') then
begin
ShowMessage('Credit key loading error');
Exit;
end;
ShowMessage('Keys loaded successfully');
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -