|
楼主 |
发表于 2021-3-15 13:15:01
|
显示全部楼层
好的,代码如下:
void CAd65_testDlg::OnOpenDevice()
{
// TODO: Add your control notification handler code here
hDevice=Fmad_OpenDevice(0);
if(hDevice!=INVALID_HANDLE_VALUE)
{
m_StatusDisplay.Format("打开成功!\n");
UpdateData(FALSE);
GetDlgItem(IDC_OpenDevice)->EnableWindow(TRUE);
GetDlgItem(IDC_StartSample)->EnableWindow(TRUE);
GetDlgItem(IDC_CloseDevice)->EnableWindow(TRUE);
UpdateData(FALSE);
}
else
{
m_StatusDisplay.Format("打开失败!\n");
UpdateData(FALSE);
}
}
//---------------------------------------------------------------------------------//
void CAd65_testDlg::OnStartSample()
{
// TODO: Add your control notification handler code here
BOOL bStatus=FALSE;
PULONG pData=new ULONG[786432]; //申请内存 !!!!!!!!!!!
memset(pData,0,3145728); //全部清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; //执行所用的毫秒数
static char BASED_CODE szFilter[] = "二进制文件 (*.dat)|*.dat||";
CString msg;
CString sFile;
CFileDialog dlgFile(FALSE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, \
szFilter,NULL);
dlgFile.m_ofn.lpstrTitle="保存";
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就是我开辟使用的内存缓冲区 ,只要一加上,程 序就出对话框
{
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 !");
}
|
|