LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

SriptFile Logic help

im trying to get the integer this time instead of putting the integer into the ini file, its not getting the integer,im probably overwriting or someting.

can you assist me?

int main()

{

  int Width=0,  Height=0; 

  Get_Centroid_Center ( Width,  Height)

return 0;

}

int Get_Centroid_Center (int frameWidth, int frameHeight)
{
    char dirName[500];
    IniText iniStation=0; ///< Handle for the Station INI file.
    char pathName[500];
 
    GetProjectDir(dirName);
   
    MakePathname(dirName,CONFIG_FILE3,pathName);
    if(iniStation != 0)
    {
       Ini_Dispose(iniStation);
    }
    Ini_ReadFromFile (iniStation,pathName);
   
    Ini_GetInt(iniStation, "123456789", "FRAMEWIDTH", &frameWidth);
   
    Ini_GetInt(iniStation, "123456789", "FRAMEHEIGHT", &frameHeight);
   // Ini_WriteToFile(iniStation, pathName);
    if(iniStation != 0)
    {
       Ini_Dispose(iniStation);
    }
   
    //system("notepad Config.ini");
    return VI_SUCCESS;                                                   



0 Kudos
Message 21 of 33
(1,898 Views)

I suppose you want GetCentroidCenter to return the values it reads from file. For the function to do so it must receive the variables by address, otherwise it will not be able to return the values to the caller. For this to happen your code must be modified as follows:

int main()

{

  int Width=0,  Height=0; 

 

  Get_Centroid_Center (&Width,  &Height)

  return 0;

}

 

int Get_Centroid_Center (int *frameWidth, int *frameHeight)
{
    IniText iniStation=0; ///< Handle for the Station INI file.
    char pathName[500];
 
    GetProjectDir(pathName);
    MakePathname(pathName, CONFIG_FILE3, pathName);


// Those lines are useless: iniStation is a local variable and here is still initialized to 0

    if(iniStation != 0)
    {
       Ini_Dispose (iniStation);
    }
 

    iniStation = Ini_New (0);   // This is absolutely needed for you to use Ini files!

    Ini_ReadFromFile (iniStation, pathName);
   
    Ini_GetInt (iniStation, "123456789", "FRAMEWIDTH", frameWidth);
    Ini_GetInt (iniStation, "123456789", "FRAMEHEIGHT", frameHeight);
   

    if(iniStation != 0)
    {
       Ini_Dispose (iniStation);
    }
    
    return VI_SUCCESS;                                                   

I have made those modifications in the code:

  1. Passed frameWidth and frameHeight by reference to Get_Centroid_Center (): this permits to get back their values (this is really a basic C mistake: you were probably thinking to something else while you were coding this, weren't you?)
  2. Deleted some lines at the beginning of Get_Centroid_Center (): in this point there is no possibility that iniStation has any value
  3. Added Ini_New at the beginning of the function: if you don't create the in-memory Ini object you won't be able to manipulate it and get / put values!

 I will say you nothing about error checking: I'm pretty sure this is only an abstract of your actual code where you have added all necessary elements to detect if an error has raised!

Message Edited by Roberto Bozzolo on 10-31-2009 07:09 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?
Message 22 of 33
(1,898 Views)
Im still not getting the values from the ini file at all, I dont know what im doing wrong.
int main()
{
    int width=0;
    int height=0;
   
    Get_Centroid_Center (&width, &height);
   
   
    return 0;
}

int Get_Centroid_Center (int *frameWidth, int *frameHeight)
{
    char dirName[500];
    IniText iniStation=0; ///< Handle for the Station INI file.
    char pathName[500];
 
    GetProjectDir(dirName);
   
    MakePathname(dirName,CONFIG_FILE3,pathName);
    iniStation=Ini_New(0);
    Ini_ReadFromFile (iniStation,pathName);
   
    //Update the current file with the frame width and frame height
    //which is half of the frame. (Center)
    //This file is also associated with a serial number from the seeker
    Ini_GetInt(iniStation, "123456789", "FRAMEWIDTH", frameWidth);
   
    //Update the current file with the frame width and frame height
    //which is half of the frame. (Center)
    //This file is also associated with a serial number from the seeker
    Ini_GetInt(iniStation, "123456789", "FRAMEHEIGHT", frameHeight);
    // Ini_WriteToFile(iniStation, pathName);
   
    printf("%d, %d",frameWidth,frameHeight);
    GetKey();
    if(iniStation != 0)
    {
       Ini_Dispose(iniStation);
    }
   
    //system("notepad Config.ini");
    return VI_SUCCESS;                                                   



0 Kudos
Message 23 of 33
(1,879 Views)

SORRY ABOUT THAT, THE PROGRAM IS WORKING. i HAD TO PUT THE PRINTF STATEMENT IN THE MAIN

 

INSTEAD OF THE FUNCTION CALL. THANKS ROBERTO.

0 Kudos
Message 24 of 33
(1,827 Views)

Darnell:

 

Your printf() statement in Get_Centroid_Center as you posted it prints the pointers, not the values.

 

Your function definition for Get_Centroid_Center shows that you're using pointers:

int Get_Centroid_Center (int *frameWidth, int *frameHeight)

 

*frameWidth and *frameHeight are int's.

frameWidth and frameHeight are pointers to int's.

 

printf in Get_Centroid_Center would work like this:

 

printf("%d, %d", *frameWidth, *frameHeight);

 

Message 25 of 33
(1,810 Views)

Im getting this non fatal error 

NON-FATAL RUN-TIME ERROR:   "AutomationEOD_Init.c", line 397, col 7, thread id 0x000013DC:   Uninitialized string.
 

#define HRCHECK_FILE(sMsg)           { Write_HrChecks_To_Script_File(sMsg);}


int Write_HrChecks_To_Script_File (char stringToWrite[]);//HrCheck script file
 

int Write_HrChecks_To_Script_File (char stringToWrite[])//Log error script file
{
   FILE *textFile;
   char errorMsg[BUF_LEN];
   char textFileName[BUF_LEN];
   char statusCheckMsg[BUF_LEN];
   char newErrorMsgVariable[BUF_LEN];
   double dateTimeValue;

 
   size_t stringLength = 0;
   textFile = fopen ("DAS3000_SOFTWARE_ERRORS.txt", "a");
   if(textFile == NULL)                                           
   {                                                                  
         sprintf(statusCheckMsg, "Error opening file %s", textFileName);       
         MessagePopup ("File Open Error", statusCheckMsg);
      HRCHECK_FILE(statusCheckMsg);
      return FAILURE;
   }  
   else
   {
      GetCurrentDateTime (&dateTimeValue);
      FormatDateTimeString (dateTimeValue, "%I:%M%p %A, %B %d, %Y  -----  ",
                                        errorMsg, BUF_LEN);
      strcpy(newErrorMsgVariable,errorMsg );
      sprintf (errorMsg,"%i:%s",clock(),stringToWrite); ************************** this is where i get the error, its saids uninitialized stringToWrite

      strcat(newErrorMsgVariable, errorMsg);
      stringLength = strlen(newErrorMsgVariable);
      fwrite(newErrorMsgVariable, stringLength, 1, textFile);
      fclose (textFile);
   }
   return VI_SUCCESS;
}  

0 Kudos
Message 26 of 33
(1,798 Views)

Darnell:

 

Since you passed stringToWrite as a parameter, the routine that called Write_HrChecks_To_Script_File() would initialize it.  Take a look at the calling routine to see how the parameter you're passing to Write_HrChecks_To_Script_File() gets initialized.  Post the calling routine, if you need to, after you take a look at it.

Message Edited by Al S on 11-02-2009 12:23 PM
0 Kudos
Message 27 of 33
(1,797 Views)

I did post the function.

 

unless you talking about

 

int hrCheck( HRESULT hresult, char function[STR_LEN])
{
    char *errorBuf; // Error buffer in CA_GetAutomationErrorString
    char *tempString;       // Temp string  displays error messaging
   
    if(FAILED( hresult ))
    {
       errorBuf = calloc( BUF_LEN, sizeof(char) );
       tempString = calloc( BUF_LEN, sizeof(char) );
       if(!(errorBuf && tempString))
       {
           if(errorBuf)
           {
              free( errorBuf );
              HRCHECK_FILE(errorBuf);
           }
           
           if(tempString)
           {
              free( tempString );
              HRCHECK_FILE(tempString);
           }
           return VI_SUCCESS;
       }
       CA_GetAutomationErrorString( hresult, errorBuf, BUF_LEN );
       HRCHECK_FILE((char*)hresult);
       sprintf(tempString, "Error: %s\n    Function: %s\n",errorBuf,function);
       HRCHECK_FILE((char*)tempString);
       if((g_comError.wCode != 0) || (g_comError.sCode != 0))
       {
           g_comError.sCode = 0;
           HRCHECK_FILE((char*)g_comError.sCode);
           g_comError.wCode = 0;
           HRCHECK_FILE((char*)g_comError.wCode );
       }
       free( tempString );
       HRCHECK_FILE(tempString);
       free( errorBuf );
       HRCHECK_FILE(errorBuf );
    }
    return VI_SUCCESS;
}
 

0 Kudos
Message 28 of 33
(1,793 Views)

Darnell:

 

Yes, I was talking about "the routine that called Write_HrChecks_To_Script_File()", "the calling routine".

 

I would suggest you put a breakpoint early in hrCheck() and step through the code so you see what call is causing your error.

 

There are two things I don't understand about the code you posted.

1. Why use a macro to do the following?

#define HRCHECK_FILE(sMsg)           { Write_HrChecks_To_Script_File(sMsg);}

Why not just call Write_HrChecks_To_Script_File()?

 

2. (Related to your question)  I don't understand what you are doing in casting variables as pointers to char's in your calls to HRCHECK_FILE().

For example:

HRCHECK_FILE((char*)hresult);

 

userint.h has the following definition:

 

#ifndef _HRESULT_DEFINED
#define _HRESULT_DEFINED
typedef long HRESULT;
#endif /* !_HRESULT_DEFINED */

 

So HRESULT is a long.  What are you trying to do by casting it as (char*)?

If you want to convert the number to a string, why not use sprintf()? 

0 Kudos
Message 29 of 33
(1,774 Views)

The function accept long, so when i want to place my function HRCHECK_FILE((char*)hresult);

 

i have to point it to a char. because hresult is long  if I can remember. it works either way.

 

so do you know why i am getting the error

0 Kudos
Message 30 of 33
(1,765 Views)