所以我的主要功能是这样的:
void main {
uint32 errmsg;
uint32 mydata;
if (LOG) {
std::ofstream file;
file.open(fileName,ios_base::app);
file << "!!!mydata: " << mydata << ",&mydata: " << &mydata << endl;
file.close();
}
errmsg = ReadReg32(0, 0, &mydata);
if (LOG) {
std::ofstream file;
file.open(fileName,ios_base::app);
file << "!!! returned mydata: " << mydata << ",&mydata: " << &mydata << endl;
file.close();
}
}
并在下面调用 ReadReg32:
static uint32 ReadReg32(uint32 brdNum, uint32 address, uint32 *data)
{
std::ofstream file;
if (LOG) {
file.open(fileName,ios_base::app);
file << " ReadReg32: brdNum =" << brdNum << ", address =" << address << endl;
file << " ReadReg32 ... Data WAS: " << *data << endl;
file.close();
}
/* AD:TW Check if we need to do init */
bool initstatus = checkDeferredInit();
ADMXRC3_HANDLE phCard;
ADMXRC3_STATUS status;
//open card
if((status = ADMXRC3_Open(brdNum, &phCard)) != ADMXRC3_SUCCESS)
return status;
//read data
if((status = ADMXRC3_Read(phCard, NON_PREFETCHABLE_SPACE, 0, address, 4, &data)) != ADMXRC3_SUCCESS){
ADMXRC3_Close(phCard);
return status;
}
if (LOG) {
file.open(fileName,ios_base::app);
file << " ReadReg32 ... Data IS: " << data << ", &data: " << &data << ", Read status =" << status << endl;
file.close();
}
//close card
status = ADMXRC3_Close(phCard);
if (LOG) {
file.open(fileName,ios_base::app);
file << " ReadReg32 ... Close card status =" << status << ", Returning ..." << endl;
file.close();
}
return status;
}
相关的输出是这样的:
!!!mydata: 348,&mydata: 000000000012F050
ReadReg32: brdNum =0, address =0
ReadReg32 ... Data WAS: 348
checkDeferredInit
ReadReg32 ... Data IS: 0000000081040102, &data: 000000000012EF30, Read status =0
ReadReg32 ... Close card status =0, Returning ...
!!! returned mydata: 348,&mydata: 000000000012F050
其中 0000000081040102 是我希望看到的正确数字,但它永远不会将其返回给调用函数,即 mydata 永远不会更新。
有趣的笔记:
- 在 ADMXRC3_Read 中,如果我不使用 &data,我会得到“不正确”的数据值
- 在 ADMXRC3_Read 中,我坚持 &data 的类型应该是 void *pbuffer?
任何想法都像一箱啤酒或一瓶中规中矩的盒装葡萄酒一样值钱。;)
我很感激你的任何想法,这让我很难过......