LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

d

ok this is what i have
0 Kudos
Message 11 of 63
(1,994 Views)

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;
}

0 Kudos
Message 12 of 63
(1,995 Views)

- 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;

}

- You should popup error message if there is an error. In your code it will popup if the INI handle is nonzero, which is actually expected behavior, not an error.
You should write if (error != 0) {...}
 
Message Edited by ebalci on 11-21-2009 10:33 AM
S. Eren BALCI
IMESTEK
Message 13 of 63
(1,994 Views)

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)
    {
       //Cleaning memory
       Ini_Dispose(iIniTextHandle);
       sErrorMsg1=GetGeneralErrorString(error);
       MessagePopup("ERROR",sErrorMsg1);
       return FAILURE;
    }
    return VI_SUCCESS;
}
0 Kudos
Message 14 of 63
(1,990 Views)

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??? Smiley Surprised



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 15 of 63
(1,989 Views)

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?

      

0 Kudos
Message 16 of 63
(1,968 Views)

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 !

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 17 of 63
(1,963 Views)
also do ini style writing have a function to append the the file, I dont want to keep over writing the file
0 Kudos
Message 18 of 63
(1,965 Views)

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).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 19 of 63
(1,945 Views)

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?

0 Kudos
Message 20 of 63
(1,936 Views)