10-31-2009 12:43 PM
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;
}
10-31-2009 01:07 PM - edited 10-31-2009 01:09 PM
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:
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!
11-01-2009 11:32 AM
11-01-2009 11:37 AM
SORRY ABOUT THAT, THE PROGRAM IS WORKING. i HAD TO PUT THE PRINTF STATEMENT IN THE MAIN
INSTEAD OF THE FUNCTION CALL. THANKS ROBERTO.
11-02-2009 07:45 AM
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);
11-02-2009 12:13 PM
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;
}
11-02-2009 12:22 PM - edited 11-02-2009 12:23 PM
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.
11-02-2009 12:32 PM
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;
}
11-02-2009 01:30 PM
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()?
11-02-2009 01:59 PM
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