11-21-2009 02:15 AM
11-21-2009 02:15 AM
ok this is what i have
int Boresight_Command(double *dAZposX,double *dELposY)
{
int error=0;
int G=0;
char *sErrorMsg1=0;
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);
//sErrorMsg1=
error=FileExists(sDirPath,0);
if(error<0)
{
return FAILURE;
}
errChk(Ini_ReadFromFile (iIniTextHandle,sPathName));
//errChk(Ini_GetString(iIniTextHandle,g_sOperatorID, "OperatorID", g_sOperatorID));
errChk(Ini_GetDouble(iIniTextHandle,g_sSkrSerialNumberk, INI_TAG_X_OFFSET_POS, dAZposX));
errChk(Ini_GetDouble(iIniTextHandle,g_sSkrSerialNumberk, INI_TAG_Y_OFFSET_POS, dELposY));
Fmt(sAZposX,"%f",*dAZposX);
sprintf(sCrtCommand,"SERVO, WRITE, 098000034, %s",sAZposX);
Send_SERVO_Command(sCrtCommand);
Fmt(sELposY,"%f",*dELposY);
sprintf(sCrtCommand,"SERVO, WRITE, 098000038, %s",sELposY);
Send_SERVO_Command(sCrtCommand);
Error:
if(iIniTextHandle)
{
//Cleaning memory
Ini_Dispose(iIniTextHandle);
sErrorMsg1=GetGeneralErrorString(error);
MessagePopup("ERROR",sErrorMsg1);
return FAILURE;
}
return VI_SUCCESS;
}
11-21-2009 02:27 AM - edited 11-21-2009 02:33 AM
- Still no error checking for Ini_New.
- Wrong variable for FileExists function. You should use sPathName instead of sDirPath.
- FileExists return 0 if the file does not exist. Your code does not consider it as error. You should use:
error = FileExists (sPathName, 0);
if (error <= 0)
{
return FAILURE;
}
11-21-2009 02:43 AM
is this correct ? anything else?
int Boresight_Command(double *dAZposX,double *dELposY)
{
int error=0;
int G=0;
char *sErrorMsg1=0;
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);
nullChk(iIniTextHandle=Ini_New (0));
error=FileExists(sPathName,0);
if(error<=0)
{
return FAILURE;
}
errChk(Ini_ReadFromFile (iIniTextHandle,sPathName));
//errChk(Ini_GetString(iIniTextHandle,g_sOperatorID, "OperatorID", g_sOperatorID));
errChk(Ini_GetDouble(iIniTextHandle,g_sSkrSerialNumberk, INI_TAG_X_OFFSET_POS, dAZposX));
errChk(Ini_GetDouble(iIniTextHandle,g_sSkrSerialNumberk, INI_TAG_Y_OFFSET_POS, dELposY));
Fmt(sAZposX,"%f",*dAZposX);
sprintf(sCrtCommand,"SERVO, WRITE, 098000034, %s",sAZposX);
Send_SERVO_Command(sCrtCommand);
Fmt(sELposY,"%f",*dELposY);
sprintf(sCrtCommand,"SERVO, WRITE, 098000038, %s",sELposY);
Send_SERVO_Command(sCrtCommand);
Error://///////////////////////////////////////////is this in the right place?????
///// I get this error user interface library did not open, why is that, and everything else pass up at the top
if(iIniTextHandle)11-21-2009 03:33 AM
As I said earlier, Ini_ReadFromFIle returns an error if the file does not exist, so you coud avoid the FileExists () check. Unless you want to check if file exists BEFORE running into memory-concuming operations like Ini_New and so on. If you want to run this way you should place it before Ini_New ().
Another issue is the correct error checking, as ebalci already pointed you to: error conditions are marked by a negative value in 'error' (nullChk macro too returns a valid 'error' value <0), so your function should terminate this way:
int Boresight_Command(double *dAZposX,double *dELposY)
{
// Your declarations and code here
error = 0; // Clear 'error' before ending the function
// This is useful since Ini_xx functions return a positive value in 'error' on success
Error:
if (iIniTextHandle) {
//Cleaning memory
Ini_Dispose (iIniTextHandle);
}
if (error < 0) {
sErrorMsg1 = GetGeneralErrorString (error);
MessagePopup ("ERROR", sErrorMsg1);
}
return error;
}
Final answers to your in-code questions:
is this in the right place????? Yes, the Error: label is in the correct position
I get this error user interface library did not open, why is that, and everything else pass up at the top What do you mean by this???
11-21-2009 05:07 AM
got a question?
error=errChk( Ini_ReadFromFile (iIniTextHandle,sPathName)); ////////////should it be like this? or the errChk by it sefl is doing everything?
if(error<0)
{
return FAILURE;
}
if(iIniTextHandle )////// //// just a basic question , I should know this , I rarely use it and I see it all the time, what is the condition saying?
//////////////////// is it saying if iIniTextHandle==0, or not 0?
11-21-2009 08:42 AM
As per errChk macro, I cannot but point you again to toolbox.h where it is defined: by looking at the code you will understand that error = errrChk (someFunction) is nonsense.
Take a look also at the explanation given by Luis G on this macro.
if(iIniTextHandle) is exactly the opposite of what you say: the condition is true if iIniTextHandle is non-zero, that is this notation is equivalent to if(iIniTextHandle != 0) { }
darnell, for the umpteenth time I urge you to go and read what we are suggesting you !
11-21-2009 12:16 PM
11-22-2009 05:14 AM
I don't understand your last question: Ini_WriteToFile write the content of the IniText object to disk.
Now, if you want to update previous file contents you must read the file before using any Ini_Put function (typically immediately after Ini_New function), otherwise Ini_WriteToFile will write to disk all (and only!) the elements you have placed in the IniText object with your Ini_Put calls, overwriting previous file contents (you will lose all items you have not previously populated with ini_PutXX calls).
11-22-2009 03:42 PM
I want to append the file. append means to to keep adding on to the file instead of writing over it, or re writing. example
[123456]
x = 2
y = 3
[234567]
x = 4
y = 6
so basically every time i debug or run my code, its adds to the file instead of rewriting, how can i do that?