LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

creating a log file box or window with all your error handling

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



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 11 of 31
(1,914 Views)

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?

0 Kudos
Message 12 of 31
(1,881 Views)
It's an instructions from the Formatting and I/O Library to write to a file. Look in the online help for it. Alternatively you could use fwrite or fputs.


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 13 of 31
(1,880 Views)
so basically i use the writeline,its going to send my strings to an log window?
0 Kudos
Message 14 of 31
(1,879 Views)

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.



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 15 of 31
(1,879 Views)

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

0 Kudos
Message 16 of 31
(1,844 Views)

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

}

0 Kudos
Message 17 of 31
(1,846 Views)

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


 
}
 

0 Kudos
Message 18 of 31
(1,846 Views)

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.

0 Kudos
Message 19 of 31
(1,845 Views)

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.

 

0 Kudos
Message 20 of 31
(1,839 Views)