发表于:2009/6/11 19:21:36
#0楼
我希望用用PCI-1713数据采集卡后台中断方式采集六个电位计数据,现在用研华自带的MAdint例程进行调试,发现每次经过DRV_FAIIntScanStart启动中断,DRV_CheckEvent检查中断事件,传递数据三步完成之后,必须重新启动中断,检查中断事件才可以完成下一次的数据传输.而我需要DRV_FAIIntScanStart启动一次中断之后,外部数据在后台不断的读入到缓冲区中,在我的主程序需要数据采集卡数据的时候就直接取用数据缓冲区中的数据即可,而不需要繁琐的重新启动中断,检查中断事件,传输数据才可得到数据.这样繁琐的操作也得不到实时的数据.
下面是我的采集程序。求指点。
void ThreadProc()
{
LPVOID temp;
float tdata[6]={0,0,0,0,0,0};
int i,j;
YH.YH_ADstart();
USHORT usEventType=0;
ptCheckEvent.EventType = &usEventType;
ptCheckEvent.Milliseconds = 100;
while(1)
{
// Check message
if ((ErrCde = DRV_CheckEvent(DriverHandle1713,
(LPT_CheckEvent)&ptCheckEvent)) == 0)
{
// Process interrupt event
if (usEventType & ADS_EVT_INTERRUPT)
adInterruptEvent();
// Process buffer change event
if (usEventType & ADS_EVT_BUFCHANGE)
adBufChangeEvent();
// Process overrun event
if (usEventType & ADS_EVT_OVERRUN)
adOverrunEvent();
// Process terminate event
if (usEventType & ADS_EVT_TERMINATED)
{
adTerminateEvent();
if ((ErrCde = DRV_FAITransfer(DriverHandle1713,(LPT_FAITransfer)&ptFAITransfer)) != 0)
return ;
temp= (FLOAT far *)ptFAITransfer.DataBuffer;
for(j=0;j<(int)(gulConvNum/gwNumChl);j++)
{
for(i = 0; i < gwNumChl; i++)
{
tdata[i]+=((float *)temp)[i+gwNumChl*j];
}
}
for(i = 0; i < gwNumChl; i++)
{
AD_buff[i]=tdata[i]/(int)(gulConvNum/gwNumChl);
tdata[i]=0;
}
if(m_YHAD)//true means restart
YH.YH_ADstart();
else
{
GlobalUnlock(hBuf);// Free buffer
GlobalUnlock(hADBuf);
GlobalFree(hBuf);
GlobalFree(hADBuf);
DRV_DeviceClose(&DriverHandle1713);// Close driver
return;
}
}
}
}
}
void CYH::YH_ADstart(void)
{
if ((ErrCde = DRV_FAIIntScanStart(DriverHandle1713,
(LPT_FAIIntScanStart)&ptFAIIntScanStart)) != 0)//启动中断
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
GlobalUnlock(hBuf);
GlobalUnlock(hADBuf);
GlobalFree(hBuf);
GlobalFree(hADBuf);
DRV_DeviceClose((LONG far *)&DriverHandle1713);
}
}
下面是我的采集程序。求指点。
void ThreadProc()
{
LPVOID temp;
float tdata[6]={0,0,0,0,0,0};
int i,j;
YH.YH_ADstart();
USHORT usEventType=0;
ptCheckEvent.EventType = &usEventType;
ptCheckEvent.Milliseconds = 100;
while(1)
{
// Check message
if ((ErrCde = DRV_CheckEvent(DriverHandle1713,
(LPT_CheckEvent)&ptCheckEvent)) == 0)
{
// Process interrupt event
if (usEventType & ADS_EVT_INTERRUPT)
adInterruptEvent();
// Process buffer change event
if (usEventType & ADS_EVT_BUFCHANGE)
adBufChangeEvent();
// Process overrun event
if (usEventType & ADS_EVT_OVERRUN)
adOverrunEvent();
// Process terminate event
if (usEventType & ADS_EVT_TERMINATED)
{
adTerminateEvent();
if ((ErrCde = DRV_FAITransfer(DriverHandle1713,(LPT_FAITransfer)&ptFAITransfer)) != 0)
return ;
temp= (FLOAT far *)ptFAITransfer.DataBuffer;
for(j=0;j<(int)(gulConvNum/gwNumChl);j++)
{
for(i = 0; i < gwNumChl; i++)
{
tdata[i]+=((float *)temp)[i+gwNumChl*j];
}
}
for(i = 0; i < gwNumChl; i++)
{
AD_buff[i]=tdata[i]/(int)(gulConvNum/gwNumChl);
tdata[i]=0;
}
if(m_YHAD)//true means restart
YH.YH_ADstart();
else
{
GlobalUnlock(hBuf);// Free buffer
GlobalUnlock(hADBuf);
GlobalFree(hBuf);
GlobalFree(hADBuf);
DRV_DeviceClose(&DriverHandle1713);// Close driver
return;
}
}
}
}
}
void CYH::YH_ADstart(void)
{
if ((ErrCde = DRV_FAIIntScanStart(DriverHandle1713,
(LPT_FAIIntScanStart)&ptFAIIntScanStart)) != 0)//启动中断
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
GlobalUnlock(hBuf);
GlobalUnlock(hADBuf);
GlobalFree(hBuf);
GlobalFree(hADBuf);
DRV_DeviceClose((LONG far *)&DriverHandle1713);
}
}
[此贴子已经被作者于2009-6-11 20:49:33编辑过]