📄 frmmain.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "frmMain.h"
#include "AT125Lib.h"
#include "../lib/Function_basic.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmNMain *frmNMain;
AT125Lib *com1;
//---------------------------------------------------------------------------
__fastcall TfrmNMain::TfrmNMain(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::FormCreate(TObject *Sender)
{
com1=new AT125Lib;
GetConfigSetting();
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::btnOpenCom1Click(TObject *Sender)
{
com1->CloseComPort();
if(com1->OpenComPort(txtCom->Text.ToInt() ))
{
Application->MessageBox("Success","", MB_OK );
}
else
{
Application->MessageBox("Open Port failed","",MB_ICONERROR | MB_OK );
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::btnDisconnectClick(TObject *Sender)
{
com1->CloseComPort();
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::btnExitClick(TObject *Sender)
{
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::chkRegularReadClick(TObject *Sender)
{
Timer1->Enabled = chkRegularRead->Checked;
if(chkRegularRead->Checked)
{
}
chkRegularRead->Color = clBtnFace;
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::Timer1Timer(TObject *Sender)
{
char buf[32],buf2[64];
if(com1->IsOpened())
{
if(rdoTID->Checked )
{
if(com1->T5557ReadTID(buf)>0)
{
Bin2Hex(buf2, buf ,8 );
txtRegularRead->Text =buf2;
chkRegularRead->Color = clLime;
}
else
{
chkRegularRead->Color = clBtnFace;
}
}
else
{
if(com1->T5557RegularRead(buf,txtBlocks->Text.ToInt()*4 )>0)
{
//Application->MessageBox("Success","", MB_OK );
Bin2Hex(buf2, buf ,txtBlocks->Text.ToInt()*4 );
txtRegularRead->Text =buf2;
chkRegularRead->Color = clLime;
}
else
{
chkRegularRead->Color = clBtnFace;
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::btnTestClick(TObject *Sender)
{
char buf[32],buf2[64];
if(com1->IsOpened())
{
if(rdoTID->Checked )
{
if(com1->T5557ReadTID(buf)>0)
{
Bin2Hex(buf2, buf ,8 );
txtRegularRead->Text =buf2;
}
}
else
{
if(com1->T5557RegularRead(buf,txtBlocks->Text.ToInt()*4 )>0)
{
Bin2Hex(buf2, buf ,txtBlocks->Text.ToInt()*4 );
txtRegularRead->Text =buf2;
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::rdoTIDClick(TObject *Sender)
{
txtBlocks->Enabled =false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::rdoBlocksClick(TObject *Sender)
{
txtBlocks->Enabled =true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::btnReadClick(TObject *Sender)
{
char buf[32],buf2[64];
if(com1->IsOpened())
{
if(com1->T5557ReadBlock(buf,txtReadAddr->Text.ToInt())>0)
{
Bin2Hex(buf2, buf ,4 );
txtReadData->Text =buf2;
}
else
{
txtReadData->Text ="";
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::btnWriteBlockClick(TObject *Sender)
{
char buf[32];
if(com1->IsOpened())
{
buf[0]=hex2int((txtWriteData->Text.SubString(1*2-1,2)).c_str(),2);
buf[1]=hex2int((txtWriteData->Text.SubString(2*2-1,2)).c_str(),2);
buf[2]=hex2int((txtWriteData->Text.SubString(3*2-1,2)).c_str(),2);
buf[3]=hex2int((txtWriteData->Text.SubString(4*2-1,2)).c_str(),2);
if(com1->T5557WriteBlock(buf,txtWriteAddr->Text.ToInt())>0)
{
Application->MessageBox("Write Block Success","", MB_OK );
}
else
{
Application->MessageBox("Write Block Failure","", MB_OK );
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::btnUpdateConfigClick(TObject *Sender)
{
//char buf[32];
if(com1->IsOpened())
{
//buf[0]=hex2int((txtConfig->Text.SubString(1*2-1,2)).c_str(),2);
//buf[1]=hex2int((txtConfig->Text.SubString(2*2-1,2)).c_str(),2);
//buf[2]=hex2int((txtConfig->Text.SubString(3*2-1,2)).c_str(),2);
//buf[3]=hex2int((txtConfig->Text.SubString(4*2-1,2)).c_str(),2);
if(com1->T5557WriteConfig(config)>0)
{
Application->MessageBox("Write Config Success","", MB_OK );
}
else
{
Application->MessageBox("Write Config Failure","", MB_OK );
}
}
}
//---------------------------------------------------------------------------
void TfrmNMain::GetConfigSetting()
{
char buf[32];
config[0]= ((unsigned char)cboMasterKey->Text.ToInt()&0xff)<<4;
config[1]= (((unsigned char)cboBitRate->ItemIndex&0xff)<<2) | ((unsigned char)(cboModulation->ItemIndex ==9)&0x01) ;
config[2]= (((unsigned char)cboModulation->ItemIndex &0xff)<<4 ) | (((unsigned char)cboPSKCF->ItemIndex&0xff)<<2) | (((unsigned char)cboAOR->ItemIndex&0x01)<<1);
config[3]= (((unsigned char)cboMaxBlock->ItemIndex &0xff)<<5 ) | (((unsigned char)cboPWD->ItemIndex&0x01)<<4) | (((unsigned char)cboST->ItemIndex&0x01)<<3) | (((unsigned char)cboPORDelay->ItemIndex&0x01)) ;
Bin2Hex(buf,config ,4 );
txtConfig->Text=buf;
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::cboMasterKeyChange(TObject *Sender)
{
GetConfigSetting();
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::cboXModeChange(TObject *Sender)
{
GetConfigSetting();
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::cboBitRateChange(TObject *Sender)
{
GetConfigSetting();
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::cboModulationChange(TObject *Sender)
{
GetConfigSetting();
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::cboPSKCFChange(TObject *Sender)
{
GetConfigSetting();
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::cboAORChange(TObject *Sender)
{
GetConfigSetting();
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::cboMaxBlockChange(TObject *Sender)
{
GetConfigSetting();
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::cboPWDChange(TObject *Sender)
{
GetConfigSetting();
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::cboSTChange(TObject *Sender)
{
GetConfigSetting();
}
//---------------------------------------------------------------------------
void __fastcall TfrmNMain::cboPORDelayChange(TObject *Sender)
{
GetConfigSetting();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -