|
Okay, the code is as follows:
void CAd65_testDlg::OnOpenDevice()
{
// TODO: Add your control notification handler code here
hDevice=Fmad_OpenDevice(0);
if(hDevice!=INVALID_HANDLE_VALUE)
{
m_StatusDisplay.Format("Open successfully!\n");
UpdateData(FALSE);
GetDlgItem(IDC_OpenDevice)->EnableWindow(TRUE);
GetDlgItem(IDC_StartSample)->EnableWindow(TRUE);
GetDlgItem(IDC_CloseDevice)->EnableWindow(TRUE);
UpdateData(FALSE);
}
else
{
m_StatusDisplay.Format("Failed to open!\n");
UpdateData(FALSE);
}
}
//------------------------------------------------ ---------------------------------//
void CAd65_testDlg::OnStartSample()
{
// TODO: Add your control notification handler code here
BOOL bStatus=FALSE;
PULONG pData=new ULONG[786432]; //Apply for memory! ! ! ! ! ! ! ! ! ! !
memset(pData,0,3145728); //clear all to 0
int n = 0;
bStatus=Fmad_WriteN(hDevice, 20);
bStatus = Fmad_WriteUserParameter(hDevice, 62, 255);
bStatus = Fmad_SelClk(hDevice, FALSE);
bStatus = Fmad_SetSample(hDevice, 0x3);
bStatus = Fmad_StartSample(hDevice);
bStatus = Fmad_WriteTrigger(hDevice);
DWORD begin = 0;
DWORD end = 0;
begin = GetTickCount();
cycle: while (!Fmad_DataReady(hDevice))
{
}
if((n==0)||(n%2==0))
{
bStatus=Fmad_GetTrigData(hDevice,pData+(n*0x2000),0x4000*2,0x0);
n++;
}
else
{
bStatus=Fmad_GetTrigData(hDevice,pData+(n*0x2000),0x4000*2,0x8000);
n++;
}
if(n <64)
{
goto cycle;
}
bStatus = false;
bStatus = Fmad_SetSample(hDevice, 0x0);
end = GetTickCount();
DWORD timeUse = end-begin; //The number of milliseconds used for execution
static char BASED_CODE szFilter[] = "Binary file (*.dat)|*.dat||";
CString msg;
CString sFile;
CFileDialog dlgFile(FALSE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,\
szFilter,NULL);
dlgFile.m_ofn.lpstrTitle="Save";
dlgFile.DoModal();
sFile=dlgFile.GetFileName();
if(!sFile.IsEmpty())
{
int n=sFile.Find(".dat");
if(n<0)
sFile=sFile+".dat";
CFile file;
if(!file.Open(sFile,CFile::modeCreate|CFile::modeWrite))
{
msg.Format("Can't not open the file %s.",sFile);
AfxMessageBox(msg);
return;
}
file.Write(pData,3145728);
file.Close();
/*
if (pData!=NULL) //pData is the memory buffer I opened and used, as long as it is added, the program will pop up a dialog box
{
delete []pData;
}
*/
}
}
void CAd65_testDlg::OnCloseDevice()
{
// TODO: Add your control notification handler code here
hDevice = Fmad_CloseDevice(hDevice);
if(hDevice==INVALID_HANDLE_VALUE)
{
GetDlgItem(IDC_OpenDevice)->EnableWindow(TRUE);
GetDlgItem(IDC_StartSample)->EnableWindow(FALSE);
GetDlgItem(IDC_CloseDevice)->EnableWindow(FALSE);
}
else
AfxMessageBox("Can't Close Device !");
} |
|