09-16-2009 03:22 AM
Instead of passing the description string to MessagePopup you can simply add it to a textbox, listbox or other UI control or WriteLine it to a file.
If you use a
09-16-2009 03:25 AM
yeah im getting to many errors with your code, im going to fixthat later, im going to work on the log window
so the writeline function is basically doing what?
09-16-2009 03:37 AM
09-16-2009 03:38 AM
09-16-2009 03:46 AM
As I said earlier, it's an instructions from the Formatting and I/O Library to write to a file
Depending on which control you are using as a log window, it will have different way of writing to it.
09-17-2009 06:28 AM
i need a lil help trying to finish this off i want write this errors as well to the text file.
*******************************************************
void DisplayRS232Error (int bytes_sent,int bytes_read)
{
File *f1=0;
f1 = fopen("RECORD_OF_ERRORS.txt", "w");
char ErrorMessage[200];
switch (RS232Error)
{
default :
if (RS232Error < 0)
{
Fmt (ErrorMessage, "%s<RS232 error number %i", RS232Error);
MessagePopup ("RS232 Message", ErrorMessage);
}
break;
case 0 :
MessagePopup ("RS232 Message", "No errors.");
break;
case -2 :
Fmt (ErrorMessage, "%s", "Invalid port number (must be in the "
"range 1 to 8).");
MessagePopup ("RS232 Message", ErrorMessage);
break;
case -3 :
Fmt (ErrorMessage, "%s", "No port is open.\n"
"Check COM Port setting in Configure.");
MessagePopup ("RS232 Message", ErrorMessage);
break;
case -99 :
Fmt (ErrorMessage, "%s", "Timeout error.\n\n"
"Either increase timeout value,\n"
" check COM Port setting, or\n"
" check device.");
MessagePopup ("RS232 Message", ErrorMessage);
break;
}
}
09-17-2009 06:44 AM
Undefined symbol '_RECORD_OF_ERRORS' referenced in "RS-33_CHILLER.c".
im getting this error when i try it this way.
************************************************
void DisplayRS232Error (int bytes_sent,int bytes_read)
{
FILE *f1=0;
f1 = fopen("RECORD_OF_ERRORS.txt", "w");
size_t str_length = 0;
char ErrorMessage[200];
switch (RS232Error)
{
default :
if (RS232Error < 0)
{
Fmt (ErrorMessage, "%s<RS232 error number %i", RS232Error);
MessagePopup ("RS232 Message", ErrorMessage);
WriteStringToFile (f1, ErrorMessage);
}
break;
case 0 :
MessagePopup ("RS232 Message", "No errors.");
break;
case -2 :
Fmt (ErrorMessage, "%s", "Invalid port number (must be in the "
"range 1 to 8).");
MessagePopup ("RS232 Message", ErrorMessage);
WriteStringToFile (f1, ErrorMessage);
break;
case -3 :
Fmt (ErrorMessage, "%s", "No port is open.\n"
"Check COM Port setting in Configure.");
MessagePopup ("RS232 Message", ErrorMessage);
WriteStringToFile (f1, ErrorMessage);
break;
case -99 :
Fmt (ErrorMessage, "%s", "Timeout error.\n\n"
"Either increase timeout value,\n"
" check COM Port setting, or\n"
" check device.");
MessagePopup ("RS232 Message", ErrorMessage);
WriteStringToFile (f1, ErrorMessage);
break;
}
fclose(f1);
}
09-17-2009 06:48 AM
nevermind i found why i got that error, is this going to work how im doing it, any suggestions.
void DisplayRS232Error (int bytes_sent,int bytes_read)
{
FILE *f1=0;
f1 = fopen("RECORD_OF_ERRORS.txt", "w");
size_t str_length = 0;
char ErrorMessage[200];
switch (RS232Error)
{
default :
if (RS232Error < 0)
{
Fmt (ErrorMessage, "%s<RS232 error number %i", RS232Error);
MessagePopup ("RS232 Message", ErrorMessage);
WriteStringToFile (f1, ErrorMessage);
}
break;
case 0 :
MessagePopup ("RS232 Message", "No errors.");
break;
case -2 :
Fmt (ErrorMessage, "%s", "Invalid port number (must be in the "
"range 1 to 8).");
MessagePopup ("RS232 Message", ErrorMessage);
WriteStringToFile (f1, ErrorMessage);
break;
case -3 :
Fmt (ErrorMessage, "%s", "No port is open.\n"
"Check COM Port setting in Configure.");
MessagePopup ("RS232 Message", ErrorMessage);
WriteStringToFile (f1, ErrorMessage);
break;
case -99 :
Fmt (ErrorMessage, "%s", "Timeout error.\n\n"
"Either increase timeout value,\n"
" check COM Port setting, or\n"
" check device.");
MessagePopup ("RS232 Message", ErrorMessage);
WriteStringToFile (f1, ErrorMessage);
break;
}
}
09-17-2009 07:09 AM
many suggestion: what you wrote is never going to do what you want.
1. i don't see the point of declaring bytes_sent and bytes_read as arguments to the DisplayRS232Error() function: those values are never used in the body of the function.
2. where is RS232Error declared ? it seems like it is a global variable. it would be much more correct to pass it as an argument (that's about the only value on which this function depends)
3. you open the log file at the beginning of the function. that's not efficient, the file will be opened each time there is an RS232 error. it would be better to open the file once at the beginning of the program and close it properly at the end.
4. you open the file with a "w" mode: read the documentation for the fopen() function. the file will be erased each time you call the DisplayRS232Error(), thus losing any previous error. i am pretty sure you want to use mode "w+" which append to the file if it already exists.
5. you open the log file but you do never close it ! remember to always free the resource you are using, files are no exception.
beside this, i will add:
6. a log is useless without other informations, like the date and time an error occured.
7. do you ever test your code before posting ? point 4 is critical, and running your software only 2 times would have showed this problem. take the time to review your code, compile it, test it, debug it, and try to correct as much problems as you can by yourself (it is much more rewarding) before posting another question. you could have avoided your last 2 posts if you had done your job correctly.
09-17-2009 07:24 AM
right now im trying something out , basically trying to see if i can all my message pop ups in the text file, then im going to go back and format them with the date and time etc............
so if it take the FILE * f1 out the function and put itin my main i get undeclared errors because im using writestringtofile.
so how would i do this logic. and yes im stepping through it now. let me try something else i got a mind block at the moment.