LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

d

Already answered to this question: read my previous post...


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 21 of 63
(1,704 Views)
Ini_Readfromfile has to be before any ini writing function to append. so that we are on the same page its like a log file, im keeping track of everything
0 Kudos
Message 22 of 63
(1,696 Views)

Thanks Roberto,Learning so much from you guys this is year of me being more libraries like never before and more functions

through last three years of coding. 

0 Kudos
Message 23 of 63
(1,697 Views)

Im checking to see if I handle the errorchecking right for the Ini_GetStringCopy  ?A little assistance?

 

int Boresight_Command(double  *dAZposX,double *dELposY)
{
    int error=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);
   
    //Verify if there is enough memory
    nullChk(iIniTextHandle=Ini_New (0));
   
    //Verify if file exist on disk
    error=FileExists(sPathName,0);
    if(error<=VI_SUCCESS)
    {
       Terminate_Executable();
       return FAILURE;
    }
    errChk(Ini_ReadFromFile (iIniTextHandle,sPathName));
    errChk(Ini_GetStringCopy(iIniTextHandle,g_sOperatorID, "OperatorID", //////////////////////////////I wanted to do a error check , did I do it right?
                           g_sOperatorID));
    errChk(Ini_GetDouble(iIniTextHandle,g_sSkrSerialNumberk,X_OFFSET_POS,
                         dAZposX));
    errChk(Ini_GetDouble(iIniTextHandle,g_sSkrSerialNumberk,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);
      
       //Cleaning memory
       free (g_sOperatorID);/////////////////////////////////// did i free in the right spot? im using the Ini_GetStringCopy
    }
    if(error < VI_SUCCESS)
    {
       sErrorMsg1 = GetGeneralErrorString (error);
       MessagePopup ("ERROR", sErrorMsg1);
       Terminate_Executable();
    }
    return error;
}

0 Kudos
Message 24 of 63
(1,672 Views)

Sorry I left out my Casting of a pointer to pointer on my char variable in Ini_GetStringCopy

Im checking to see if I handle the errorchecking right for the Ini_GetStringCopy  ?A little assistance?

 

int Boresight_Command(double  *dAZposX,double *dELposY)
{
    int error=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);
   
    //Verify if there is enough memory
    nullChk(iIniTextHandle=Ini_New (0));
   
    //Verify if file exist on disk
    error=FileExists(sPathName,0);
    if(error<=VI_SUCCESS)
    {
       Terminate_Executable();
       return FAILURE;
    }
    errChk(Ini_ReadFromFile (iIniTextHandle,sPathName));
    errChk(Ini_GetStringCopy(iIniTextHandle,g_sOperatorID, "OperatorID", //////////////////////////////I wanted to do a error check , did I do it right?
                           g_sOperatorID));
    errChk(Ini_GetDouble(iIniTextHandle,g_sSkrSerialNumberk,X_OFFSET_POS,
                         dAZposX));
    errChk(Ini_GetDouble(iIniTextHandle,g_sSkrSerialNumberk,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);
      
       //Cleaning memory
       free (g_sOperatorID);/////////////////////////////////// did i free in the right spot? im using the Ini_GetStringCopy
    }
    if(error < VI_SUCCESS)
    {
       sErrorMsg1 = GetGeneralErrorString (error);
       MessagePopup ("ERROR", sErrorMsg1);
       Terminate_Executable();
    }
    return error;
}

0 Kudos
Message 25 of 63
(1,671 Views)

Also guys while stepping through my code, i got non runtime fatal error from this

 

    g_sOperatorID = calloc( BUF_LEN, sizeof(char) );////////

 

int Boresight_Command(double  *dAZposX,double *dELposY)
{
    int error=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);
   
    //Verify if there is enough memory
    nullChk(iIniTextHandle=Ini_New (0));
   
    //Verify if file exist on disk
    error=FileExists(sPathName,0);
    if(error<=VI_SUCCESS)
    {
       Terminate_Executable();
       return FAILURE;
    }
    errChk(Ini_ReadFromFile (iIniTextHandle,sPathName));
   
   
    errChk(Ini_GetStringCopy(iIniTextHandle,g_sOperatorID, "OperatorID",
                           (char**)g_sOperatorID));
   
    g_sOperatorID = calloc( BUF_LEN, sizeof(char) );//////////////////////this is where i get the error
   
    errChk(Ini_GetDouble(iIniTextHandle,g_sSkrSerialNumberk,X_OFFSET_POS,
                         dAZposX));
    errChk(Ini_GetDouble(iIniTextHandle,g_sSkrSerialNumberk,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);
      
       //Cleaning memory
       free (g_sOperatorID);
    }
    if(error < VI_SUCCESS)
    {
       sErrorMsg1 = GetGeneralErrorString (error);
       MessagePopup ("ERROR", sErrorMsg1);
       Terminate_Executable();
    }
    return error;
}
 

0 Kudos
Message 26 of 63
(1,672 Views)

the error is  621, 53   Array assignments are illegal.

                   621, 53   Lvalue required.
 

0 Kudos
Message 27 of 63
(1,671 Views)

Well, a couple of things are not fully clear to me:

  1. There is no evidence as to how g_sOperatorID is defined, so I won't argue anything about that. The 'g' prefix makes me assume it is a global variable but I don't understand why using a global variable while you could use a local one (it is dimensioned, used and freed in the same callback): try using a local string
           char sOperatorID[BUF_LEN];
    In case you want to actually store the string read in a global variable, DO NOT free it at the end of the callback!
  2. In any case, you must allocate the string BEFORE using it in Ini_GetStringCopy ()
  3. You are using the same variable both for Section Name and Buffer parameters: what's the meaning of that????? If you do not pass a proper value for Section Name parameter you are likely to read nothing from the IniText object!
Message Edited by Roberto Bozzolo on 11-25-2009 03:03 PM


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 28 of 63
(1,666 Views)

well the reason Im naming it as a global is because  I want to remember where I am, Im using that global in many places through the source file

 

its define as g_sOperatorID[BUF_LEN];

0 Kudos
Message 29 of 63
(1,661 Views)
also can you explain this?""it is dimensioned, used and freed in the same callback""
0 Kudos
Message 30 of 63
(1,661 Views)