?? sdimain.cpp
字號:
//---------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "SDIMain.h"
#include "t_titan.h"
#include "ftd2xx.h"
#include "copt.h"
//---------------------------------------------------------------------
#pragma resource "*.dfm"
TSDIAppForm *SDIAppForm;
//---------------------------------------------------------------------
__fastcall TSDIAppForm::TSDIAppForm(TComponent *AOwner)
: TForm(AOwner)
{
}
//---------------------------------------------------------------------
void __fastcall TSDIAppForm::FormCreate(TObject *Sender)
{
SDIAppForm->Caption = FT_STR_DEF_TITLE;
Application->OnHint = ShowHint;
}
//---------------------------------------------------------------------------
void __fastcall TSDIAppForm::FormActivate(TObject *Sender)
{
char Buf[64];
ManuLabel->Caption = FT_STR_DEF_MANUFACTURER;
DescLabel->Caption = FT_STR_DEF_PRODUCT_DESC;
wsprintf(Buf,"VID_%s&&PID_%s",FT_STR_DEF_VENDOR_ID,FT_STR_DEF_PRODUCT_ID);
DevIdLabel->Caption = Buf;
ProgramBitBtn->SetFocus();
}
//---------------------------------------------------------------------
void __fastcall TSDIAppForm::ShowHint(TObject *Sender)
{
StatusBar->Panels->Items[0]->Text = Application->Hint;
}
//---------------------------------------------------------------------------
BOOLEAN __fastcall TSDIAppForm::Program(TObject *Sender)
{
FT_PROGRAM_DATA ftData = {
0x0, // Header - must be 0x00000000
0xffffffff, // Header - must be 0xffffffff
1, // Header - FT_PROGRAM_DATA version
// 0 = original
// 1 = FT2232C extens
0x0403, //VID
0x6010, //PID
FT_STR_DEF_MANUFACTURER, //Manufacturer string
FT_STR_DEF_MANUFACTURER_ID, //Manufacturer ID string
FT_STR_DEF_PRODUCT_DESC, //description string
FT_STR_DEF_FIXED_SERNO, //serial number
90, //max current
1, //PNP
0, //Self Powered
1, //Remote wakeup
//
// Rev4 extensions
//
FALSE, //Rev4
FALSE, //in endpoint type
FALSE, //out endpoint type
FALSE, //pulldown
FALSE, //serial number
FALSE, //USB Version select
0, //USB version
//
// FT2232C extensions
//
TRUE, // non-zero if Rev5 chip, zero otherwise
FALSE, // TRUE if in endpoint is isochronous
FALSE, // TRUE if in endpoint is isochronous
FALSE, // TRUE if out endpoint is isochronous
FALSE, // TRUE if out endpoint is isochronous
FALSE, // TRUE if pull down enabled
TRUE, // TRUE if serial number to be used
TRUE, // TRUE if chip uses USBVersion
0x0200, // BCD (0x0200 => USB2)
FALSE, // TRUE if A interface is high current
FALSE, // TRUE if B interface is high current
FALSE, // TRUE if A interface is 245 FIFO
FALSE, // TRUE if A interface is 245 FIFO CPU target
FALSE, // TRUE if A interface is Fast serial
TRUE, // TRUE if A interface is to use VCP drivers
FALSE, // TRUE if B interface is 245 FIFO
FALSE, // TRUE if B interface is 245 FIFO CPU target
FALSE, // TRUE if B interface is Fast serial
TRUE // TRUE if B interface is to use VCP drivers
};
FT_HANDLE ftHandle;
FT_STATUS ftStatus;
wsprintf(InfoText,"Program EEPROM");
if (FT_Open(0,&ftHandle) != FT_OK)
return false;
ftStatus = FT_EE_Program(ftHandle,&ftData);
FT_Close(ftHandle);
return ftStatus == FT_OK;
}
//---------------------------------------------------------------------------
BOOLEAN __fastcall TSDIAppForm::Test(TObject *Sender,BOOLEAN ChannelA)
{
const int MaxBufferSize = 256;
int CurrentBufferSize;
unsigned char WriteBuffer[MaxBufferSize];
unsigned char ReadBuffer[MaxBufferSize];
TTitanTester t(ChannelA ? 0 : 1);
char ch = ChannelA ? 'A' : 'B';
BOOL fStatus;
SDIAppForm->Refresh();
if (!t.IsRunning()) {
strcpy(InfoText,"Failed to initialize tester");
return false;
}
t.Reset();
//
// Test1 : Activate CTS
//
wsprintf(InfoText,"Ch %c: Activate CTS",ch);
t.ActCTS();
if (!(MS_CTS_ON & t.WaitStatus()))
return false;
ProgressBar->StepIt();
//
// Test2 : Deactivate CTS
//
wsprintf(InfoText,"Ch %c: Deactivate CTS",ch);
t.DeactCTS();
if (MS_CTS_ON & t.WaitStatus())
return false;
ProgressBar->StepIt();
//
// Test3 : Activate DSR
//
wsprintf(InfoText,"Ch %c: Activate DSR",ch);
t.ActDSR();
if (!(MS_DSR_ON & t.WaitStatus()))
return false;
ProgressBar->StepIt();
//
// Test4 : Deactivate DSR
//
wsprintf(InfoText,"Ch %c: Deactivate DSR",ch);
t.DeactDSR();
if (MS_DSR_ON & t.WaitStatus())
return false;
ProgressBar->StepIt();
//
// Test5 : Activate CD
//
wsprintf(InfoText,"Ch %c: Activate CD",ch);
t.ActCD();
if (!(MS_RLSD_ON & t.WaitStatus()))
return false;
ProgressBar->StepIt();
//
// Test6 : Deactivate CD
//
wsprintf(InfoText,"Ch %c: Deactivate CD",ch);
t.DeactCD();
if (MS_RLSD_ON & t.WaitStatus())
return false;
ProgressBar->StepIt();
//
// Test7 : Activate RI
//
wsprintf(InfoText,"Ch %c: Activate RI",ch);
t.ActRI();
if (!(MS_RING_ON & t.WaitStatus()))
return false;
ProgressBar->StepIt();
//
// Test8 : Deactivate RI
//
wsprintf(InfoText,"Ch %c: Deactivate RI",ch);
t.DeactRI();
if (MS_RING_ON & t.WaitStatus())
return false;
ProgressBar->StepIt();
//
// Test 9: RX/TX at 300 baud
//
// Perform any buffer initialisation in DoRxTest and DoTxTest.
//
wsprintf(InfoText,"Ch %c: Rx/Tx at 300 Baud",ch);
if (!t.Set300())
return false;
CurrentBufferSize = 16;
fStatus = t.DoRxTest(WriteBuffer,ReadBuffer,CurrentBufferSize);
if (fStatus)
fStatus = t.DoTxTest(WriteBuffer,ReadBuffer,CurrentBufferSize);
if (!fStatus)
return false;
ProgressBar->StepIt();
//
// Test 10: RX/TX at 115200 baud
//
// Perform any buffer initialisation in DoRxTest and DoTxTest.
//
wsprintf(InfoText,"Ch %c: Rx/Tx at 115200 Baud",ch);
if (!t.Set115K())
return false;
CurrentBufferSize = 256;
fStatus = t.DoRxTest(WriteBuffer,ReadBuffer,CurrentBufferSize);
if (fStatus)
fStatus = t.DoTxTest(WriteBuffer,ReadBuffer,CurrentBufferSize);
ProgressBar->StepIt();
return (BOOLEAN) fStatus;
}
//---------------------------------------------------------------------------
void __fastcall TSDIAppForm::ProgramBitBtnClick(TObject *Sender)
{
ProgramBitBtn->Enabled = false;
PassLabel->Visible = false;
FailLabel->Visible = false;
if (!DisableEEPromCB->Checked) {
StatusBar->Panels->Items[0]->Text = "Program";
if (!Program(Sender)) {
StatusBar->Panels->Items[0]->Text = InfoText;
FailLabel->Visible = true;
goto quit;
}
}
#if 1
StatusBar->Panels->Items[0]->Text = "Test";
#else
StatusBar->Visible = false;
ProgressBar->Position = 0;
SendMessage(ProgressBar->Handle, PBM_SETBARCOLOR, 0, clGray);
ProgressBar->Visible = true;
#endif
if (!Test(Sender,TRUE)) {
StatusBar->Panels->Items[0]->Text = InfoText;
FailLabel->Visible = true;
goto quit;
}
if (!Test(Sender,FALSE)) {
StatusBar->Panels->Items[0]->Text = InfoText;
FailLabel->Visible = true;
goto quit;
}
StatusBar->Panels->Items[0]->Text = "";
PassLabel->Visible = true;
quit:
Application->ProcessMessages();
ProgressBar->Visible = false;
StatusBar->Visible = true;
ProgramBitBtn->Enabled = true;
ProgramBitBtn->SetFocus();
}
//---------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -