|
ADC_IOControl 和DeviceIOControl读取数据。
[复制链接]
问题描述:我需要通过DeviceIOControl函数从我的ADC驱动中读取AD转换结果,但是始终无法读取正确结果。我们知道DeviceIOControl调用ADC_IOControl函数。ADC_IOControl函数中可以得到正确的AD结果,应该是ADC_IOControl函数到DeviceIOControl函数之间的函数传递有问题:
我的ADC_IOControl:
[code]
BOOL ADC_IOControl (DWORD hOpenContext,
DWORD dwCode,
PBYTE pBufIn,
DWORD dwLenIn,
PBYTE pBufOut,
DWORD dwLenOut,
PDWORD pdwActuralOut)
{
BOOL bRet=TRUE;
BYTE adc_value[2];
unsigned int adc;
DWORD num;
RETAILMSG(1,(TEXT("MYSTRINGGS:***********ADC_IOControl**********\n")));
adc = ReadAdc(dwCode);//dwCode决定ADC转换通道
adc_value[0]= char((adc&0x00ff));
adc_value[1]=char(((adc&0x0300)>>8));
pBufOut =adc_value;
num = 2;
pdwActuralOut = #
RETAILMSG(1,(TEXT("****ADC:Control Code = 0x%x\r\n"),dwCode));//输出ADC通道
RETAILMSG(1,(TEXT("****ADC:Control result = 0x%x\r\n"),adc));
RETAILMSG(1,(TEXT("****ADC:Control result = 0x%x\r\n"),adc_value[0]));
RETAILMSG(1,(TEXT("****ADC:Control result = 0x%x\r\n"),adc_value[1]));
return bRet;
}
DeviceIOControl函数调用:
unsigned char ADCData[2];
unsigned int size,adc_v;
ULONG size2;
size = 2;
size2 =2;
memset(ADCData,0,sizeof(ADCData));
DeviceIoControl(hStr,ADC_Chunnel,NULL,0,&ADCData[0],size,&size2,NULL);
[code]
查看串口输出信息
RETAILMSG(1,(TEXT("****ADC:Control Code = 0x%x\r\n"),dwCode));//输出ADC通道
RETAILMSG(1,(TEXT("****ADC:Control result = 0x%x\r\n"),adc));
RETAILMSG(1,(TEXT("****ADC:Control result = 0x%x\r\n"),adc_value[0]));
RETAILMSG(1,(TEXT("****ADC:Control result = 0x%x\r\n"),adc_value[1]));
这几个语句输出都正确,为什么DeviceIOControl函数不能读取结果呢?
这样调用有问题吗?
|
|