11-20-2009 12:52 AM
is there a error check or return value for Ini_New( 0 );
or Ini_ReadfromFIle, I want to do a check to see if the file is curently in directory, is possible using
ini style from cvi., anythere any other error handling I can possibly do and why in this situation.
the send servo command function moves the arm on a robot etc....... in the x and y position blah blah
im just looking for any exception handling in this situation
int Boresight_Command(double *dAZposX,double *dELposY)
{
char sAZposX[100]={0};
char sELposY[100]={0};
char sCrtCommand[256]={0};
char sDirPath[BUF_LEN_FOR_DIRECTORY];
IniText iIniTextHandle=0; // Handle for the text file.
char sPathName[BUF_LEN_FOR_DIRECTORY];
GetProjectDir(sDirPath);
MakePathname(sDirPath,KEY_TEXT_FILE,sPathName);
iIniTextHandle=Ini_New (0);
Ini_ReadFromFile (iIniTextHandle,sPathName);
Ini_GetDouble(iIniTextHandle,"RECOVER", INI_TAG_X_OFFSET_POS, dAZposX);
Ini_GetDouble(iIniTextHandle,"RECOVER", INI_TAG_X_OFFSET_POS, dELposY);
Fmt(sAZposX,"%f",*dAZposX);
sprintf(sCrtCommand,"SERVO, WRITE, 095000000, %s",sAZposX);
Send_SERVO_Command(sCrtCommand);
Fmt(sELposY,"%f",*dELposY);
sprintf(sCrtCommand,"SERVO, WRITE, 090000000, %s",sELposY);
Send_SERVO_Command(sCrtCommand);
if(iIniTextHandle != VI_SUCCESS)
{
//Cleaning memory
Ini_Dispose(iIniTextHandle);
return FAILURE;
}
return VI_SUCCESS;
11-20-2009 01:16 AM - edited 11-20-2009 01:17 AM
darnell,
Of course, there are error check values for both functions.
You can kindly see the help from the function panel:
Ini_New: "... 0 is returned if there is not enough memory ..."
Ini_ReadFromFile: "... A zero indicates success ..."
You can also use FileExists function to see if a file is available on disk.
Last, but not least, you violated another forum law by entering a meaningless subject for your post.
But you are always too ignoring to pay attention to such niceness, aren't you?
11-20-2009 02:32 AM
In addition to the good suggestions from ebalci, you can use nullChk and errChk macros from the Programmer's Toolbox: they are well documented in toolbox.h.
int SomeFunction (void)
{
int error = 0;
IniText T = 0;
nullChk (T = Ini_New (0));
errChk (Ini_ReadFromFile (T, "myIniFile.ini"));
// Sample reading function
errChk (Ini_GetInt (T, "Section", "Item", &value));
Error:
if (T) Ini_Dispose (T);
// You may add some message here for the user if (error < 0)
return error;
}
11-20-2009 10:24 AM
Sorry about that, I wasnt paying attn,I didnt try to do it on purpose.
int SomeFunction (void)///// are you sayinguse this logic in the function I already created, or create a function call and just call it
{
int error = 0;
IniText T = 0;
nullChk (T = Ini_New (0)); ///////////can you explain?
errChk (Ini_ReadFromFile (T, "myIniFile.ini"));/////is the line checking to see if file available
// Sample reading function
errChk (Ini_GetInt (T, "Section", "Item", &value));////is this check to see if i got the value to the variable
Error:
if (T) Ini_Dispose (T); ////and im assuming if anything fail above ,it jumps down to this point, and return error
// You may add some message here for the user if (error < 0)
return error;
}
11-20-2009 11:03 AM
int SomeFunction (void)///// are you saying use this logic in the function I already created, or create a function call and just call itI was suggesting you a framework for adding error checking to your function. With the ability to return the error found (if any) to the caller in case you want to propagate it and trim the behaviour of your program in this case
{
int error = 0;
IniText T = 0;
nullChk (T = Ini_New (0)); ///////////can you explain?
Please review this thread about it and look at the documentation on Ini_New function
errChk (Ini_ReadFromFile (T, "myIniFile.ini"));/////is the line checking to see if file available
As you may notice studying the documentation, Ini_ReadFromFile can return several errors. In case the file does not exist you are likely to receive error -94. Use GetGeneralErrorString () function to obtain a description of errors returned by IniFile functions. And please open the function panel for Ini_ReadFromFile and right-click on 'status' field: you will see which errors this function returns (this is valid for every fp)
// Sample reading function
errChk (Ini_GetInt (T, "Section", "Item", &value));////is this check to see if i got the value to the variable
This check is in case you get some error while accessing the IniFile object. In case of non existing section/item you will receive error = 0.
Error:
if (T) Ini_Dispose (T); ////and im assuming if anything fail above ,it jumps down to this point, and return error
Right: have you looked at the documentation for errChk and nullChk I pointed you to earlier?
// You may add some message here for the user if (error < 0)
return error;
}
11-20-2009 11:51 AM
11-20-2009 09:12 PM
do it like this
int Conversion_Number(int *Multiplier)//Functionality: retrieving actual
//multiplier which currently is not
//available
{
int error=0;
char dir1Name[BUF_LEN_FOR_DIRECTORY];
IniText initextHandle1=0; // Handle for the text file.
char pathName1[BUF_LEN_FOR_DIRECTORY];
GetProjectDir(dir1Name);
MakePathname(dir1Name,CONFIG_FILE6,pathName1);
initextHandle1=Ini_New (0);
Ini_ReadFromFile (initextHandle1,pathName1);
nullChk(Ini_GetInt(initextHandle1,MULTIPLIER,INI_TAG_PIXEL_TO_DEGREES,
Multiplier));
Error:
if(initextHandle1)
{
//Cleaning memory
Ini_Dispose(initextHandle1);
MessagePopup("ERROR","ERROR RECIEVED");
return FAILURE;
}
return VI_SUCCESS;
}
11-20-2009 11:56 PM
Where is all the error checking you asked about for Ini_New and Ini_ReadFromFile !?
Where is the code to check if the INI file exist or not !?
Are you still posting temporary code?
You can use the MAX_PATHNAME_LEN constant instead of BUF_LEN_FOR_DIRECTORY.
It makes your code more portable.
11-21-2009 01:59 AM
11-21-2009 02:14 AM - edited 11-21-2009 02:18 AM
nullChk, as the name implies, checks if the return value of a function is NULL.
For some functions like Ini_New, NULL (as a return value) means the function was not successful.
Instead of assigning variables for return values and using IF statements to check if the return value was NULL or not, it is possible to use the nullChk macro.
It automatically reads and compares the value you provide (in this case the return of Ini_New) and if the function's return is NULL, it sends the execution to the Error label where you can handle the error condition properly.
Didn't you read Roberto's post? There is a whole function with error handling there!
Copy and paste it to your file and step through the code in debug mode.
Try the error conditions by yourself and see what happens.
This is maybe the 10th thread about your error handling issues. It seems we are not making any progress.