发表于:2005/12/1 11:17:00
#0楼
在用VC做研华PCL-818数据采集编程时,采用动态连接库方式(818驱动,device manager都已装),按照说明编了一个采集0号通道的例子,运行时先是提示一个AI conversion failed对话框。按确定后,然后又弹出Invalid driver handle failed.我是按照说明来编的阿!我把adsapi32.lib,driver.h,os.h都按照说明设置好了阿!就是不知道出在什么地方,我用研华自带的AD_SOFT例程运行,也出现了AI conversion failed对话框。超级郁闷中:(:(:(。我这方面还没入门,请懂这方面的大侠指教,万分感谢!!!!
主要代码如下:
void CYk1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
ErrCde=DRV_DeviceOpen(0,(LONG far*)&DriverHandle);
char szErrMsg[100];
if(ErrCde!=SUCCESS)
{
strcpy(szErrMsg,"Device open error!");
MessageBox((LPCSTR)szErrMsg,"Device Open",MB_OK);
return;
}
ptDevFeatures.buffer=(LPDEVFEATURES)&DevFeatures;
ptDevFeatures.size=sizeof(DEVFEATURES);
if((ErrCde=DRV_DeviceGetFeatures(DriverHandle,
(LPT_DeviceGetFeatures)&ptDevFeatures))!=SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox((LPCSTR)szErrMsg,"Driver Message GetFeatures ",MB_OK);
DRV_DeviceClose((LONG far*)&DriverHandle);
return;
}
ptAIConfig.DasGain=DevFeatures.glGainList[gwGain].usGainCde;
ptAIConfig.DasChan=gwChannel;
if((ErrCde=DRV_AIConfig(DriverHandle,
(LPT_AIConfig)&ptAIConfig))!=0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox((LPCSTR)szErrMsg,"Driver Message AIConfig ",MB_OK);
DRV_DeviceClose((LONG far*)&DriverHandle);
return;
}
ptAIVoltageIn.chan=gwChannel;
ptAIVoltageIn.gain=ptAIConfig.DasGain;
ptAIVoltageIn.TrigMode=0;//internal trigger
ptAIVoltageIn.voltage=(FLOAT far*)&fVoltage;
//定时器触发数据采集
SetTimer(1,500,0);
}
void CYk1Dlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString szBuffer;
char szErrMsg[100];
strcpy(szErrMsg,"Device open error!");
szBuffer.Format("data=%10.6f",fVoltage);
if((ErrCde=DRV_AIVoltageIn(DriverHandle,
(LPT_AIVoltageIn)&ptAIVoltageIn))!=0)///就在这里出的问题,到底是什么原因呢????????
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox((LPCSTR)szErrMsg,"Driver Message AIVoltageIn ",MB_OK);
DRV_DeviceClose((LONG far*)&DriverHandle);
return;
}
CWnd* pWnd=GetDlgItem(IDC_EDIT1);
pWnd->SetWindowText(szBuffer);
pDataList->InsertString(0,szBuffer);
CDialog::OnTimer(nIDEvent);
}
主要代码如下:
void CYk1Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
ErrCde=DRV_DeviceOpen(0,(LONG far*)&DriverHandle);
char szErrMsg[100];
if(ErrCde!=SUCCESS)
{
strcpy(szErrMsg,"Device open error!");
MessageBox((LPCSTR)szErrMsg,"Device Open",MB_OK);
return;
}
ptDevFeatures.buffer=(LPDEVFEATURES)&DevFeatures;
ptDevFeatures.size=sizeof(DEVFEATURES);
if((ErrCde=DRV_DeviceGetFeatures(DriverHandle,
(LPT_DeviceGetFeatures)&ptDevFeatures))!=SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox((LPCSTR)szErrMsg,"Driver Message GetFeatures ",MB_OK);
DRV_DeviceClose((LONG far*)&DriverHandle);
return;
}
ptAIConfig.DasGain=DevFeatures.glGainList[gwGain].usGainCde;
ptAIConfig.DasChan=gwChannel;
if((ErrCde=DRV_AIConfig(DriverHandle,
(LPT_AIConfig)&ptAIConfig))!=0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox((LPCSTR)szErrMsg,"Driver Message AIConfig ",MB_OK);
DRV_DeviceClose((LONG far*)&DriverHandle);
return;
}
ptAIVoltageIn.chan=gwChannel;
ptAIVoltageIn.gain=ptAIConfig.DasGain;
ptAIVoltageIn.TrigMode=0;//internal trigger
ptAIVoltageIn.voltage=(FLOAT far*)&fVoltage;
//定时器触发数据采集
SetTimer(1,500,0);
}
void CYk1Dlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString szBuffer;
char szErrMsg[100];
strcpy(szErrMsg,"Device open error!");
szBuffer.Format("data=%10.6f",fVoltage);
if((ErrCde=DRV_AIVoltageIn(DriverHandle,
(LPT_AIVoltageIn)&ptAIVoltageIn))!=0)///就在这里出的问题,到底是什么原因呢????????
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox((LPCSTR)szErrMsg,"Driver Message AIVoltageIn ",MB_OK);
DRV_DeviceClose((LONG far*)&DriverHandle);
return;
}
CWnd* pWnd=GetDlgItem(IDC_EDIT1);
pWnd->SetWindowText(szBuffer);
pDataList->InsertString(0,szBuffer);
CDialog::OnTimer(nIDEvent);
}