04-12-2010 07:41 AM
Hi Im using a define macro , Im trying to format a string a certain way in the Error check macro im creating.
This is what I have so far, and it works.
#define ERROR_CHECK(fCall,iErrorNumber)if(iStatusCheck=(fCall),iStatusCheck<0)\
{iStatusCheck=iErrorNumber;goto ErrorCondition;} else
ERROR_CHECK(ChillerTemp(Temp),InvalidTemp);
But Now I want to be able to add another parameter with a format of a sprintf, can you assist me, Let me give you and example of what im trying to do below
Im trying to find a certain way to include this sprintf in another parameter in my define macro. Im cutting everything down to one line of code .
sprintf(mErrorData.errMsg,"F%d:ERROR:Chiller Temperature",CHILLER_EXECUTE);------ im trying to include this line in the define macro, can you give some me assistance
mErrorData.errCode = errorFlag;
so do i do something like this below,
ERROR_CHECK(ChillerTemp(Temp),sprintf(mErrorData.errMsg,"F%d:ERROR:Chiller Temperature",CHILLER_EXECUTE)); -------- do you think this will work
and if this works, how would I include this line of in the macro after receiving the error ------- mErrorData.errCode = errorFlag;
I ask that because when i go to quit , Im doing a check against mErrorData.errCode!=pass
QUIT://escape destination
if(mErrorData.errCode != PASS)
{
errorFlag = FGEUBIT_EXECUTE;
}
return(errorFlag);
04-12-2010 08:06 AM
actually this line is taking care of below, I just need to see how im going to use the sprintf
and if this works, how would I include this line of in the macro after receiving the error ------- mErrorData.errCode = errorFlag;
04-12-2010 08:21 AM
Hi I think should work, Im getting ready to go test it in a hour, Im just writing everything down on paper first,
So im going to try this, Let me know if you think this will work below
#define
ERROR_CHECK(fCall,iErrorNumber)if(mErrorData.errCode=(fCall),mErrorData.errCode<0)\
{mErrorData.errCode=iErrorNumber; eAgent->LogError(&mErrorData);goto
ErrorCondition;} else
ERROR_CHECK(ChillerTemp(Temp),sprintf(mErrorData.errMsg,"F%d:ERROR:Chiller Temperature",CHILLER_EXECUTE)); -------- do you think this will work
04-12-2010 09:49 AM - edited 04-12-2010 09:50 AM
I don't think you will get the result you are looking for. sprinf() returns the number of ASCII characters processed - are you expecting an error code?
JR
04-14-2010 10:42 AM
#define GEU_ERROR_AGENT(fCall,iErrorFlag,sStrPointer)if(mErrorData.errCode=(fCall),mErrorData.errCode!=PASS)\
{mErrorData.errCode=errorFlag;sprintf(mErrorData.errMsg, "F%d:ERROR :%s:",errorFlag,sStrPointer);,eAgent->LogError(&mErrorData);goto QUIT;}
ok this is the function im expecting pass or fail below , pass = 0 , and fail = 1 or any number but 0.
errorFlag -getChillerTemp()->execute("_ChillerTemp", Temp);
so im trying to embed this in my define macro
which is
GEU_ERROR_AGENT( getChillerTemp()->execute("_ChillerTemp", Temp),FCHILLER_EXECUTE,"getChillerTemp"); ///////// for some reason when I use the define macro, its failing and should not fail because when I put it the nornal way below its passes
Normal Way: this passes below, but when i switch to the define macro it fails some odd reason
if((errorFlag = getChillerTemp()->execute("_ChillerTemp", Temp)) != PASS)
{
sprintf(mErrorData.errMsg, "F%d:ERROR:getChillerTemp",errorFlag);
eAgent->LogError(&mErrorData);
goto QUIT:
}
QUIT://escape destination
if(mErrorData.errCode != PASS)
{
errorFlag = FCHILLER_EXECUTE;
}
return errorFlag;
04-14-2010 11:01 AM
These might be typos, but you have some inconsistencies within your macro. For instance, you have a macro parameter iErrorFlag which is not used within the macro body, but you do have a (integer?) errorFlag which does not appear to be altered. Are these supposed to be the same?
Before spending too much time on analysis, it is best to start with known code that is copied and pasted from the original C source, rather than simply being re-typed into this forum.
JR
04-14-2010 11:24 PM
Sorry about that, this is the correct info below
#define
GEU_ERROR_AGENT(fCall,iErrorFlag,sStrPointer)if(mErrorData.errCode=(fCall),mErrorData.errCode!=PASS)\
{mErrorData.errCode=errorFlag;sprintf(mErrorData.errMsg,
"F%d:ERROR
:%s:",errorFlag,sStrPointer);,eAgent->LogError(&mErrorData);goto
QUIT;}
errorFlag =getChillerTemp()->execute("_ChillerTemp", Temp);
GEU_ERROR_AGENT( getChillerTemp()->execute("_ChillerTemp", Temp),FCHILLER_EXECUTE,"getChillerTemp"); ///////// for some reason when I use the define macro, its failing and should not fail because when I put it the nornal way below its passes
Normal Way: this passes below, but when i switch to the define macro it fails some odd reason
if((errorFlag
= getChillerTemp()->execute("_ChillerTemp", Temp)) != PASS)
{
sprintf(mErrorData.errMsg, "F%d:ERROR:getChillerTemp",errorFlag);
eAgent->LogError(&mErrorData);
goto QUIT:
}
QUIT://escape destination
if(mErrorData.errCode != PASS)
{
errorFlag =
FCHILLER_EXECUTE;
}
return errorFlag;