C++ builder 管道的应用 实例 红色字体

来源:互联网 发布:江苏语音网络系统注册 编辑:程序博客网 时间:2024/05/21 20:27
//---------------------------------------------------------------------------
 #include <vcl.h>
#pragma hdrstop




#pragma comment(lib, "shlwapi.lib")
#include <shlwapi.h>


#include "windows.h"
#include "usbprt.h"
#include "Unit1.h"




#include "burning.h"
#include <tchar.h>
#include <stdio.h>


#include "Unit2.h"
#include "Unit3.h"


//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString FilePath;
AnsiString dut_bin_path;
AnsiString download_mode;
AnsiString flashaddress;
AnsiString dut_mcu_name;
unsigned long mode_selected =0;
unsigned long bin_selected  =0;
unsigned long mcu_selected  =0;
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
//Memo2->Lines->Clear();
Memo1->Lines->Clear();
Edit1->Text="";
//ComboBox1->Text = "\" MCU type  \"";
ComboBox1->Items->Add("8266");
ComboBox1->Items->Add("8267");
ComboBox1->Items->Add("8366");
ComboBox1->Items->Add("8368");
ComboBox1->Items->Add("5562");
ComboBox1->ItemIndex=0;
//ComboBox2->Text ="\"download mode\"";
ComboBox2->Items->Add("usb");
ComboBox2->Items->Add("evk");
ComboBox2->ItemIndex=0;
//Label3->Caption = "Flash address:";
   // Label4->Caption = "Download mode:";
Edit2->Text = "0x0000";
flashaddress = Edit2->Text;
download_mode = "usb";
mode_selected = 1;
HANDLE m_hDev = NULL;
//m_hDev = GetPrintDeviceHandle(0xffff);
if((m_hDev = GetPrintDeviceHandle(0xffff)) == NULL){
//Memo1->Lines->Add("Printdevice 5562 test!\n") ;
m_hDev = GetPrintDeviceHandle2(0xffff);
}
if(m_hDev == NULL)
{
//Memo1->Lines->Add("NO Usb Device!\n") ;
StatusBar1->Panels->Items[0]->Text = "NO Usb Device!\n";
//BitBtn1->Enabled = 0;
//BitBtn2->Enabled = 0;
return;
}
StatusBar1->Panels->Items[0]->Text = "Usb Device Ok!\n";
StatusBar1->Panels->Items[2]->Text = "No bin file is selected !";
Memo1->Lines->Add("Please select the appropriate DUT!\n") ;
dut_bin_path = "\\drive_bin\\dut_5325_flash_v0222.bin";dut_mcu_name = "8266";
download_mode = "usb";mode_selected = 1;
}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString StrFileName;
if(OpenDialog1->Execute())
{
  // Memo2->Lines->Clear();


StrFileName = PathFindFileName ((OpenDialog1->FileName).c_str());
//sRichEdit1->Lines->Add(StrFileName);
  // Memo2->Lines->Add(OpenDialog1->FileName);
  //Memo1->Lines->Add(StrFileName) ;
  //Memo1->Lines->Add(OpenDialog1->FileName) ;
Edit1->Text= OpenDialog1->FileName;
FilePath = AnsiString(OpenDialog1->FileName );
Memo1 ->Lines->Append(" ")  ;
Memo1 ->Lines->Append("Now can download the *.bin file by click \"USB_download button\" !")  ;
bin_selected = 1;
StatusBar1->Panels->Items[2]->Text = FilePath.c_str() ;
}
}
//---------------------------------------------------------------------------


////-------------------  downlaod to flash ----------------------------------
void __fastcall TForm1::Button2click(TObject *Sender)
{
HANDLE m_hDev = NULL;
//m_hDev = GetPrintDeviceHandle(0xffff);
if((m_hDev = GetPrintDeviceHandle(0xffff)) == NULL){
//Memo1->Lines->Add("Printdevice 5562 test!\n") ;
m_hDev = GetPrintDeviceHandle2(0xffff);
}
if(m_hDev == NULL)
{
Memo1->Lines->Add("NO Usb Device!\n") ;
return;
}
if(!mode_selected)
{
//Form2->Label1->Caption ="Don't select download mode !\n Please select the download mode !";
//Form2->ShowModal();
ShowMessage("Don't select download mode !\n Please select the download mode !");
return;
}
if(!bin_selected)
{
//Form2->Label1->Caption ="Don't select \"*.bin\" file !\n Please select approtiate \"*.bin\" file !";
//Form2->ShowModal();
ShowMessage("Error ! \n Hadn't selected \"*.bin\" file !\n Please select approtiate \"*.bin\" file !");
return;
}
char exeFullPath[MAX_PATH + 1]; // Full path
char binFullPath[MAX_PATH + 1]; // Full path
char test_bin[] = "\\usb_download.exe";
char test_space[] = " ";
//char test_binl[] = "8266";
GetModuleFileNameA(NULL,exeFullPath,MAX_PATH);
(strrchr(exeFullPath, '\\'))[0] = 0; // 删除文件名,只获得路径字串
GetModuleFileNameA(NULL,binFullPath,MAX_PATH);
(strrchr(binFullPath, '\\'))[0] = 0; // 删除文件名,只获得路径字串
//strcat(binFullPath,"\\dut_5325_flash_v0222.bin"); //dut_bin_path
strcat(binFullPath,dut_bin_path.c_str());
//Memo1->Lines->Add(binFullPath) ;
strcat(exeFullPath,test_bin);
//Memo1->Lines->Add(exeFullPath) ;
strcat(exeFullPath," ");
strcat(exeFullPath,dut_mcu_name.c_str());
strcat(exeFullPath," ");
//strcat(exeFullPath,binFullPath);
//strcat(exeFullPath," ");
strcat(exeFullPath,FilePath.c_str());
strcat(exeFullPath," ");
strcat(exeFullPath,download_mode.c_str());
strcat(exeFullPath," ");
strcat(exeFullPath,flashaddress.c_str());
//strcat(exeFullPath," active");
//Memo1->Lines->Add(exeFullPath) ; //Edit2
//FilePath.c_str();
//ShellExecute(NULL,"open",exeFullPath,test_bin,NULL,SW_SHOW);
//------
//------    一下是创建管道的实例    -----------------------
 SECURITY_ATTRIBUTES sa;
 HANDLE hRead,hWrite;


 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
 sa.lpSecurityDescriptor = NULL;
 sa.bInheritHandle = TRUE;
 if (!CreatePipe(&hRead,&hWrite,&sa,0))
 {
ShowMessage("Error On CreatePipe()");
return;
 }
 STARTUPINFOA si;
 PROCESS_INFORMATION pi;
 si.cb = sizeof(STARTUPINFOA);
 GetStartupInfoA(&si);
 si.hStdError = hWrite;
 si.hStdOutput = hWrite;
 si.wShowWindow = SW_HIDE;
 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;




 if (!CreateProcessA(NULL,exeFullPath,NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi))
 {
ShowMessage("Error on CreateProcessA()");
return;
 }
 CloseHandle(hWrite);
 DWORD bytesRead;
 AnsiString  str;
 bool err_flag=0;
 while (true)
 {
char buffer[2050]={0};
buffer[2048]=0;
if (ReadFile(hRead,buffer,2048,&bytesRead,NULL) == NULL)
  break;
str =buffer;
//
if( (StrPos(str.c_str(),"error") != false) || (StrPos(str.c_str(),"ERROR") != false)\
|| (StrPos(str.c_str(),"Error") != false) || (StrPos(str.c_str(),"not") != false))
{


err_flag = true;
// break;
}
Memo1->SelStart = Memo1->Text.Length();
Memo1->SelText = str;
Application->ProcessMessages();
if(Memo1->Lines->Count>200)
{
 Memo1->Lines->BeginUpdate();
 Memo1->Lines->Delete(0);
 Memo1->Lines->EndUpdate();
}


 }
}
////--------------------- download to ram -----------------------------------
void __fastcall TForm1::Button4click(TObject *Sender)
{
HANDLE m_hDev = NULL;
//m_hDev = GetPrintDeviceHandle(0xffff);
if((m_hDev = GetPrintDeviceHandle(0xffff)) == NULL){
//Memo1->Lines->Add("Printdevice 5562 test!\n") ;
m_hDev = GetPrintDeviceHandle2(0xffff);
}
if(m_hDev == NULL)
{
Memo1->Lines->Add("NO Usb Device!\n") ;
return;
}
if(!mode_selected)
{
//Form2->Label1->Caption ="Don't select download mode !\n Please select the download mode !";
//Form2->ShowModal();
ShowMessage("Don't select download mode !\n Please select the download mode !");
return;
}
if(!bin_selected)
{
//Form2->Label1->Caption ="Don't select \"*.bin\" file !\n Please select approtiate \"*.bin\" file !";
//Form2->ShowModal();
ShowMessage("Error ! \n Hadn't selected \"*.bin\" file !\n Please select approtiate \"*.bin\" file !");
return;
}
char exeFullPath[MAX_PATH + 1]; // Full path
char binFullPath[MAX_PATH + 1]; // Full path
char test_bin[] = "\\usb_download.exe";
char test_space[] = " ";
//char test_binl[] = "8266";
GetModuleFileNameA(NULL,exeFullPath,MAX_PATH);
(strrchr(exeFullPath, '\\'))[0] = 0; // 删除文件名,只获得路径字串
GetModuleFileNameA(NULL,binFullPath,MAX_PATH);
(strrchr(binFullPath, '\\'))[0] = 0; // 删除文件名,只获得路径字串
//strcat(binFullPath,"\\dut_5325_flash_v0222.bin"); //dut_bin_path
strcat(binFullPath,dut_bin_path.c_str());
//Memo1->Lines->Add(binFullPath) ;
strcat(exeFullPath,test_bin);
//Memo1->Lines->Add(exeFullPath) ;
strcat(exeFullPath," ");
strcat(exeFullPath,dut_mcu_name.c_str());
strcat(exeFullPath," ");
//strcat(exeFullPath,binFullPath);
//strcat(exeFullPath," ");
strcat(exeFullPath,FilePath.c_str());
strcat(exeFullPath," ");
strcat(exeFullPath,download_mode.c_str());
strcat(exeFullPath," ");
strcat(exeFullPath,flashaddress.c_str());
strcat(exeFullPath," ram ");
//Memo1->Lines->Add(exeFullPath) ; //Edit2
//FilePath.c_str();
//ShellExecute(NULL,"open",exeFullPath,test_bin,NULL,SW_SHOW);
//------
//------
 SECURITY_ATTRIBUTES sa;
 HANDLE hRead,hWrite;


 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
 sa.lpSecurityDescriptor = NULL;
 sa.bInheritHandle = TRUE;
 if (!CreatePipe(&hRead,&hWrite,&sa,0))
 {
ShowMessage("Error On CreatePipe()");
return;
 }
 STARTUPINFOA si;
 PROCESS_INFORMATION pi;
 si.cb = sizeof(STARTUPINFOA);
 GetStartupInfoA(&si);
 si.hStdError = hWrite;
 si.hStdOutput = hWrite;
 si.wShowWindow = SW_HIDE;
 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;




 if (!CreateProcessA(NULL,exeFullPath,NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi))
 {
ShowMessage("Error on CreateProcessA()");
return;
 }
 CloseHandle(hWrite);
 DWORD bytesRead;
 AnsiString  str;
 bool err_flag=0;
 while (true)
 {
char buffer[2050]={0};
buffer[2048]=0;
if (ReadFile(hRead,buffer,2048,&bytesRead,NULL) == NULL)
  break;
str =buffer;
//
if( (StrPos(str.c_str(),"error") != false) || (StrPos(str.c_str(),"ERROR") != false)\
|| (StrPos(str.c_str(),"Error") != false) || (StrPos(str.c_str(),"not") != false))
{


err_flag = true;
// break;
}
Memo1->SelStart = Memo1->Text.Length();
Memo1->SelText = str;
Application->ProcessMessages();
if(Memo1->Lines->Count>200)
{
 Memo1->Lines->BeginUpdate();
 Memo1->Lines->Delete(0);
 Memo1->Lines->EndUpdate();
}


 }
}
//---------------------------------------------------------------------------
void active_mcu_5562()
{
char exeFullPath[MAX_PATH + 1]; // Full path
char binFullPath[MAX_PATH + 1]; // Full path
char test_bin[] = "\\usb_download.exe 5562 test.bin evk 0000 flash active";
char test_space[] = " ";
//char test_binl[] = "8266";
GetModuleFileNameA(NULL,exeFullPath,MAX_PATH);
(strrchr(exeFullPath, '\\'))[0] = 0; // 删除文件名,只获得路径字串
GetModuleFileNameA(NULL,binFullPath,MAX_PATH);
(strrchr(binFullPath, '\\'))[0] = 0; // 删除文件名,只获得路径字串
//strcat(binFullPath,"\\dut_5325_flash_v0222.bin"); //dut_bin_path
strcat(binFullPath,dut_bin_path.c_str());
//Memo1->Lines->Add(binFullPath) ;
strcat(exeFullPath,test_bin);
//-----------
 SECURITY_ATTRIBUTES sa;
 HANDLE hRead,hWrite;


 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
 sa.lpSecurityDescriptor = NULL;
 sa.bInheritHandle = TRUE;
 if (!CreatePipe(&hRead,&hWrite,&sa,0))
 {
ShowMessage("Error On CreatePipe()");
return;
 }
 STARTUPINFOA si;
 PROCESS_INFORMATION pi;
 si.cb = sizeof(STARTUPINFOA);
 GetStartupInfoA(&si);
 si.hStdError = hWrite;
 si.hStdOutput = hWrite;
 si.wShowWindow = SW_HIDE;
 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;




 if (!CreateProcessA(NULL,exeFullPath,NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi))
 {
ShowMessage("Error on CreateProcessA()");
return;
 }
 CloseHandle(hWrite);
 DWORD bytesRead;
 AnsiString  str;
 bool err_flag=0;
 while (true)
 {
char buffer[2050]={0};
buffer[2048]=0;
if (ReadFile(hRead,buffer,2048,&bytesRead,NULL) == NULL)
  break;
str =buffer;
//
if( (StrPos(str.c_str(),"error") != false) || (StrPos(str.c_str(),"ERROR") != false)\
|| (StrPos(str.c_str(),"Error") != false) || (StrPos(str.c_str(),"not") != false))
{


err_flag = true;
// break;
}
Form1->Memo1->SelStart = Form1->Memo1->Text.Length();
Form1->Memo1->SelText = str;
Application->ProcessMessages();
if(Form1->Memo1->Lines->Count>200)
{
 Form1->Memo1->Lines->BeginUpdate();
 Form1->Memo1->Lines->Delete(0);
 Form1->Memo1->Lines->EndUpdate();
}


 }
}


void __fastcall TForm1::Active_mcu(TObject *Sender)
{
HANDLE m_hDev = NULL;
//m_hDev = GetPrintDeviceHandle(0xffff);
if((m_hDev = GetPrintDeviceHandle(0xffff)) == NULL){
//Memo1->Lines->Add("Printdevice 5562 test!\n") ;
m_hDev = GetPrintDeviceHandle2(0xffff);
}
if(m_hDev == NULL)
{
Memo1->Lines->Add("NO Usb Device!\n") ;
return;
}
char exeFullPath[MAX_PATH + 1]; // Full path
char binFullPath[MAX_PATH + 1]; // Full path
char test_bin[] = "\\usb_download.exe 8266 test.bin evk 0000 flash active";
char test_space[] = " ";
//char test_binl[] = "8266";
GetModuleFileNameA(NULL,exeFullPath,MAX_PATH);
(strrchr(exeFullPath, '\\'))[0] = 0; // 删除文件名,只获得路径字串
GetModuleFileNameA(NULL,binFullPath,MAX_PATH);
(strrchr(binFullPath, '\\'))[0] = 0; // 删除文件名,只获得路径字串
//strcat(binFullPath,"\\dut_5325_flash_v0222.bin"); //dut_bin_path
strcat(binFullPath,dut_bin_path.c_str());
//Memo1->Lines->Add(binFullPath) ;
strcat(exeFullPath,test_bin);
//------
//------
 SECURITY_ATTRIBUTES sa;
 HANDLE hRead,hWrite;


 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
 sa.lpSecurityDescriptor = NULL;
 sa.bInheritHandle = TRUE;
 if (!CreatePipe(&hRead,&hWrite,&sa,0))
 {
ShowMessage("Error On CreatePipe()");
return;
 }
 STARTUPINFOA si;
 PROCESS_INFORMATION pi;
 si.cb = sizeof(STARTUPINFOA);
 GetStartupInfoA(&si);
 si.hStdError = hWrite;
 si.hStdOutput = hWrite;
 si.wShowWindow = SW_HIDE;
 si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;




 if (!CreateProcessA(NULL,exeFullPath,NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi))
 {
ShowMessage("Error on CreateProcessA()");
return;
 }
 CloseHandle(hWrite);
 DWORD bytesRead;
 AnsiString  str;
 bool err_flag=0;
 while (true)
 {
char buffer[2050]={0};
buffer[2048]=0;
if (ReadFile(hRead,buffer,2048,&bytesRead,NULL) == NULL)
  break;
str =buffer;
//
if( (StrPos(str.c_str(),"error") != false) || (StrPos(str.c_str(),"ERROR") != false)\
|| (StrPos(str.c_str(),"Error") != false) || (StrPos(str.c_str(),"not") != false))
{


err_flag = true;
// break;
}
Memo1->SelStart = Memo1->Text.Length();
Memo1->SelText = str;
Application->ProcessMessages();
if(Memo1->Lines->Count>200)
{
 Memo1->Lines->BeginUpdate();
 Memo1->Lines->Delete(0);
 Memo1->Lines->EndUpdate();
}


 }
 //active_mcu_5562();
}


//---------------------------------------------------------------------------


void __fastcall TForm1::select_item(TObject *Sender)
{
//unsigned char bin_buffer[1024*64]={};
//unsigned char ram_buffer[1024*4]={};
int mcu_idbuffer = 0;
int buffer = 0;
HANDLE m_hDev = NULL;
//m_hDev = GetPrintDeviceHandle(0xffff);
if((m_hDev = GetPrintDeviceHandle(0xffff)) == NULL){
//Memo1->Lines->Add("Printdevice 5562 test!\n") ;
m_hDev = GetPrintDeviceHandle2(0xffff);
}
if(m_hDev == NULL)
{
Memo1->Lines->Add("NO Usb Device!!\n") ;
//BitBtn1->Enabled = 0;
//BitBtn2->Enabled = 0;
StatusBar1->Panels->Items[0]->Text = "NO Usb Device!!\n";
return;
}
StatusBar1->Panels->Items[0]->Text = "Usb Device Ok!!\n";
BitBtn1->Enabled = 1;
BitBtn2->Enabled = 1;


ReadMem(m_hDev,0x7e,(unsigned char*)&buffer,2,1);
//Memo1->Lines->Add(IntToHex(buffer,4)) ;
//WriteMem (m_hDev,0x8000,(unsigned char*)&buffer,2,1);
//ComboBox1->Items->GetText();
mcu_idbuffer =  ComboBox1->ItemIndex;
//Memo1->Lines->Add(mcu_idbuffer) ;
Memo1 ->Lines->Append(" ")  ;
Memo1 ->Lines->Append("Please selected \"download mode\" !")  ;
mcu_selected = 1;
switch(mcu_idbuffer)
{
case 0: /*if(buffer == 0x5325)*/{ dut_bin_path = "\\drive_bin\\dut_5325_flash_v0222.bin";dut_mcu_name = "8266"; return;} /*else {break; }*/
case 1: /*if(buffer == 0x5326)*/{ dut_bin_path = "\\drive_bin\\dut_8267_flash_v0002.bin";dut_mcu_name = "8267"; return;} /*else {break; }*/
case 2: /*if(buffer == 0x5315)*/{ dut_bin_path = "\\drive_bin\\dut_5315_flash_v01b9.bin";dut_mcu_name = "8366"; return;}/* else {break; }*/
case 3: /*if(buffer == 0x5318)*/{ dut_bin_path = "\\drive_bin\\dut_5318_flash_v020a.bin";dut_mcu_name = "8368"; return;} /*else {break; }*/
case 4: /*if(buffer == 0x5562)*/{ dut_bin_path = "\\drive_bin\\dut_5560_flash.bin";dut_mcu_name = "5562"; return;} /*else {break; }*/
default : break;
}
Memo1->Lines->BeginUpdate();
Memo1->Lines->Clear();
Memo1->Lines->EndUpdate();
dut_bin_path = "\\dut_5325_flash_v0222.bin";
Memo1->Lines->Add("the detected DUT is :") ;
//Memo1->Lines ;
switch(buffer)
{
case 0x5325: Memo1 ->Lines->Append("5325 ---> 8266")  ; break;
case 0x5326: Memo1 ->Lines->Append("5326 ---> 8267")  ; break;
case 0x5315: Memo1 ->Lines->Append("5315 ---> 8366")  ; break;
case 0x5318: Memo1 ->Lines->Append("5318 ---> 8368")  ; break;
case 0x5562: Memo1 ->Lines->Append("5562")  ; break;
default : break;
}
//Memo1 ->Lines->Append(IntToHex(buffer,4))  ;
Memo1 ->Lines->Append("Please selected the appropriate \"DUT\"")  ;
//mcu_selected = 1;
}
//---------------------------------------------------------------------------




void __fastcall TForm1::select_download_mode(TObject *Sender)
{
ComboBox2->ItemIndex;
switch(ComboBox2->ItemIndex)
{
case 0: Memo1 ->Lines->Append("Please selected the \"USB\" download mode !");download_mode = "usb";mode_selected = 1; break;
case 1: Memo1 ->Lines->Append("Please selected the \"EVK\" download mode !");download_mode = "evk";mode_selected = 1; break;
default: download_mode = "usb_evk";break;
}
Memo1 ->Lines->Append("The download mode :")  ;
Memo1 ->Lines->Append(download_mode)  ;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::edit2_change(TObject *Sender)
{
flashaddress = Edit2->Text.c_str();
AnsiString temp_text = "The flash address: ";
Memo1 ->Lines->Append("The flash address: ")  ;
Memo1 ->Lines->Append(flashaddress.c_str())  ;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::flash_address_spec(TObject *Sender)
{
Form2->Caption = "address specification";
Form2->Label1->Caption ="the flash address must be times of 0x1000 .\n For the below example :";
Form2->Memo1->Clear();
Form2->Memo1->Lines->Add("The correct address format :") ;
Form2->Memo1->Lines->Add("\t 1: address 0x0000 is ok !") ;
Form2->Memo1->Lines->Add("\t 2: address 0x11000 is ok !\n") ;
Form2->Memo1->Lines->Add(" ") ;
Form2->Memo1->Lines->Add("The error address format :") ;
Form2->Memo1->Lines->Add("\t 3: address 0x08ff is error !") ;
Form2->Memo1->Lines->Add("\t 4: address 0x110ff is error !\n") ;
Form2->ShowModal();
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Down_flow_spec(TObject *Sender)
{
Form2->Caption = "Dlownload flow";
Form2->Label1->Caption ="The operation flow as the belows :";
Form2->Memo1->Clear();
Form2->Memo1->Lines->Add("\t 1: Select the \"mcu\" type") ;
Form2->Memo1->Lines->Add(" ") ;
Form2->Memo1->Lines->Add("\t 2: Select the download mode , this must be select !") ;
Form2->Memo1->Lines->Add(" ") ;
Form2->Memo1->Lines->Add("\t 3: Set the flash address where the \"*.bin\" will be programed !\(Set depend on  the need\)") ;
Form2->Memo1->Lines->Add(" ") ;
Form2->Memo1->Lines->Add("\t 4: Select the \"*.bin\" file to be downloaded ! ") ;
Form2->Memo1->Lines->Add(" ") ;
Form2->Memo1->Lines->Add("\t 5: Click \" download \" button to download the \"*.bin\"") ;
Form2->Memo1->Lines->Add(" ") ;
Form2->ShowModal();
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Memo1Change(TObject *Sender)
{
   if(Memo1->Lines->Count > 1000)
   {
 Memo1->Lines->BeginUpdate();
 Memo1->Lines->Delete(0);
 Memo1->Lines->EndUpdate();
   }
}
//---------------------------------------------------------------------------
unsigned long dis_no_usb = 0;
unsigned long dis_yes_usb = 0;
void __fastcall TForm1::ontimer(TObject *Sender)
{
StatusBar1->Panels->Items[1]->Text = Now().FormatString("yyyy-mm-dd hh:nn:ss");
HANDLE m_hDev = NULL;
m_hDev = GetPrintDeviceHandle(0xffff);
if((m_hDev = GetPrintDeviceHandle(0xffff)) == NULL){
//Memo1->Lines->Add("Printdevice 5562 test!\n") ;
m_hDev = GetPrintDeviceHandle2(0xffff);
}
if(m_hDev == NULL)
{
StatusBar1->Panels->Items[0]->Text = "NO Usb Device!\n";
if(!dis_no_usb)
{
dis_no_usb = 1;
Memo1->Lines->Add("NO Usb Device!\n") ;
//ShowMessage("NO Usb Device!");
  /* Form3->Caption = "Error !";
Form3->Label1->Caption = " NO USB Device !!";
Form3->ShowModal() ;  */
dis_yes_usb  = 1;
}
//Memo1->Lines->Add("NO Usb Device!\n") ;
//StatusBar1->Panels->Items[0]->Text = "NO Usb Device!\n";
//dis_yes_usb  = 1;
return;
}
/* if(dis_yes_usb)
{
Form3->CloseQuery();
Form3->Close() ;
dis_yes_usb  = 0;
} */
dis_no_usb = 0;
StatusBar1->Panels->Items[0]->Text = "Usb Device Ok!\n";
}
//---------------------------------------------------------------------------
原创粉丝点击