LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

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

<flame mode="angry, yelling, bigredface, your-most-feared-nightmare-is-right-in-front-of-you">

 

darnell wrote:

"so if it take the FILE * f1 out the function and put it in my main i get undeclared errors because im using writestringtofile."

 

do you ever think before posting ? do you know what the scope of a variable is ? this is the basic of a programming language: variables and scope. that's chapter 2 of any good book about any existing programming language !

 

this forum is made for people having problems with CVI, IT IS NOT A TEACHING ROOM FOR WANNABE-DEVELOPPERS ! beginners are welcome, we can teach them and we do that very often and pleasingly, but this time you are going too far ! this problem shows your lack of understanding of the C programming language, which we already have pointed many times. now you stop kidding us, you get a programming course, and you don't come back until you masters the basic of a program ! the task you are doing here could be an assignment for a programming class, and students would complete it faster without resorting to pollute an entire forum.

 

</flame>

Message 21 of 31
(2,486 Views)

lolololo, listen here i told you i had a mind block , i cant be to beginning if i fix it, some days are just that way when you cant focus but i fix it peace out

 

with out the kindergarden book.

 

back to roberto

 

i went this route, im going to format the date and time now, tell me what you think

 

********************************************************

 

 

 void DisplayRS232Error (int bytes_sent,int bytes_read)
{
    char sMsg[10000]={0};
    char ErrorMessage[200];
    switch (RS232Error)
        {
        default :
            if (RS232Error < 0)
                {  
                Fmt (ErrorMessage, "%s<RS232 error number %i", RS232Error);
                MessagePopup ("RS232 Message", ErrorMessage);
                
                //DBGPRINT(ErrorMessage);

            sprintf (ErrorMessage,"\n%i:   %s\n",clock(),sMsg);  texPrint(ErrorMessage);

            //    WriteStringToFile (f1, ErrorMessage);
            DEBGPRNT(ErrorMessage);
            
                                //    WriteMsgToFile (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);

            //sprintf (ErrorMessage,"\n%i:   %s\n",clock(),sMsg);  texPrint(ErrorMessage);
            
                        //WriteMsgToFile (ErrorMessage);
            DEBGPRNT(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);
            //DBGPRINT(ErrorMessage);
            //       sprintf (ErrorMessage,"\n%i:   %s\n",clock(),sMsg);  texPrint(ErrorMessage);
                              DEBGPRNT(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);
        //    DBGPRINT(ErrorMessage);

        //    sprintf (ErrorMessage,"\n%i:   %s\n",clock(),sMsg);  texPrint(ErrorMessage);

                          DEBGPRNT(ErrorMessage);

            break;  
            
          
        }
    

 
 
}

 

 

int WriteMsgToFile (char string2write[])
{

   FILE* f1;
   char logwindow[1000];

   size_t str_length = 0;

   texPrint(string2write);

   sprintf (logwindow,"\n%i:   %s\n",clock(),string2write);

   texLogPdel(logwindow);

   f1 = fopen("RECORD_OF_ERRORS.txt","a");
  
     str_length = strlen(logwindow);
     fwrite(&str_length, sizeof(size_t), 1, f1);
    fwrite(logwindow, str_length, 1, f1);

  // fwrite(logwindow,strlen(string2write),1,f1);

   fclose(f1);

   return 0;
}
 

0 Kudos
Message 22 of 31
(2,474 Views)

Darnell:

 

It really would be in your best interest to take an introductory programming class.

 

Despite your efforts to convince us otherwise, you need a good guided introduction to some of the basic concepts of C.  Your claims of a difficult transition from C++ to C, brain cramps, mind blocks, being sleepy, being on the slow bus, drawing a blank, second guessing yourself don't convince us of your programming expertise.  The code and the questions you post show that you need fundamentals.  Based on your postings, I would suggest taking a class rather than trying to learn on your own.  A class will force the kind of step-by-step approach that you need.  With the way you jump from question to question without digesting the replies you receive, learning on you own is probably not the best approach.

 

Many community colleges offer good introductory classes. For example, here's a list of classes at a randomly chosen community college: https://bannerweb.pima.edu/pls/pima/az_tw_subcrse_catalog.p_subjcrse_list?p_subject_code=CIS

Here's a class description that would benefit you.

http://www.pima.edu/aux/course_outlines/cis/cis265.rtf

 

If you want to make a career of programming, you'll need a good foundation.  Take a class.

 

There is some truth in the heat of dummy_decoy's comments.

 

We are all here to help, but you need to do more to help yourself.  Take a class.

Try your code before posting it.

Ask better questions.  Don't just post your code and say "tell me what you think".  That just gives the impression that you just want us to do your work and that you have no idea what you are really supposed to be doing.

 

Here's what I think of the code in your latest post: you're reinventing the wheel, but your version ain't round!  Look at the help for the CVI function GetRS232ErrorString ().  If you want to add something for specific cases, that's ok, but then in your default case (which you should add to your switch statement), include a call to GetRS232ErrorString ().

0 Kudos
Message 23 of 31
(2,454 Views)

i have nothing else to say.i got my program to work. i found the mistakes in my last code that i posted that you had a repsonse to.

 

thanks anyway AL_S

0 Kudos
Message 24 of 31
(2,448 Views)

this is what i did to correct what you guys was talking about. so this the correct version.

 

so i thats how i define it in my header file, so all i have to now is call DEBGPRNT(Errormessage);  in the  DisplayRS232Error functioin call.

 

so its many ways to do code. but like i told you im a math person. I just got a good book last nite, so strings in C. the book is pretty good.

 

in my text file that im going to post , you will see what im doing.

 

 

#define DEBGPRNT(sMsg){ WriteMsgToFile(sMsg);}

 

int WriteMsgToFile (char string2write[])
{

   FILE *f1;
   char logwindow[100000];

   double dateTimeVal;
  
   char window[100000];

 
   size_t str_length = 0;
 
   f1 = fopen ("RECORD_OF_ERRORS.txt", "a");
  
   
   GetCurrentDateTime (&dateTimeVal);
   FormatDateTimeString (dateTimeVal, "%I:%M%p %A, %B %d, %Y ------", logwindow, 10000);
  
   strcpy(window,logwindow );
  
  

   texPrint(string2write);

   sprintf (logwindow,"%i:%s",clock(),string2write);
  

   strcat(window, logwindow);
  
   texLogPdel(window);
  
   str_length = strlen(window);

   fwrite(window, str_length, 1, f1);
  
     Delay(1);
                                               
                                               
 
   fclose (f1);
 
   system("notepad.exe RECORD_OF_ERRORS.txt");
  
 
 return 0;
}  

0 Kudos
Message 25 of 31
(2,437 Views)

this is what i did to correct what you guys was talking about. so this the correct version.

 

so i thats how i define it in my header file, so all i have to now is call DEBGPRNT(Errormessage);  in the  DisplayRS232Error functioin call.

 

so its many ways to do code. but like i told you im a math person. I just got a good book last nite, so strings in C. the book is pretty good.

 

 

 

in my text file that im going to post , you will see what im doing. I could do more. but less is more.

 

 

#define DEBGPRNT(sMsg){ WriteMsgToFile(sMsg);}

 

int WriteMsgToFile (char string2write[])
{

   FILE *f1;
   char logwindow[100000];

   double dateTimeVal;
  
   char window[100000];

 
   size_t str_length = 0;
 
   f1 = fopen ("RECORD_OF_ERRORS.txt", "a");
  
   
   GetCurrentDateTime (&dateTimeVal);
   FormatDateTimeString (dateTimeVal, "%I:%M%p %A, %B %d, %Y ------", logwindow, 10000);
  
   strcpy(window,logwindow );
  
  

   texPrint(string2write);

   sprintf (logwindow,"%i:%s",clock(),string2write);
  

   strcat(window, logwindow);
  
   texLogPdel(window);
  
   str_length = strlen(window);

   fwrite(window, str_length, 1, f1);
  
     Delay(1);
                                               
                                               
 
   fclose (f1);
 
   system("notepad.exe RECORD_OF_ERRORS.txt");
  
 
 return 0;
}  

0 Kudos
Message 26 of 31
(2,436 Views)

darnell,

 

I am totally convinced now that you confuse this forum with twitter.

 

Thanks for sharing with us all the mindstorms you are having.

But I read this forum to keep up with the CVI community, not to witness your (or anybody else's) chaotic thought process while writing their code. So please;

 

- If you have a question, ask the question. Do not post a whole CVI project.

- If you want to learn, read the replies people spend hours to write. Do not deny yourself and throw away everything with a single "nevermind".

 

I am not reading your forum threads to find a solution to your "problem" anymore, because I know that it is impossible even to understand your real question.

I am reading them on the hope that I might grab a tiny information from the other people's replies.

 

But it started hurting me to see you ignoring all the people who are "struggling" to help you.

 

I am not expecting you to understand this post either.

However, I had to write it just to get these thoughts out of my chest.

 

May programming angels be with you... They are the only beings that can withstand this pain...

Message Edited by ebalci on 09-18-2009 01:43 AM
S. Eren BALCI
IMESTEK
Message 27 of 31
(2,423 Views)

sir again i have nothing else to say, from this point on i will do exactly like you say. since i really  dont know programming as you say.

 

im just defending myself against false information. but for now own im going to respond to false information . but i have a question and i want to learn 

 

 

something i will ask a question. because its always room for improvement. like i said thanks for everything. you guys are great.

0 Kudos
Message 28 of 31
(2,413 Views)

Darnell:

 

As in any public forum, sometimes it takes awhile to figure out the etiquette and expected behavior.  There are often a few bruised egos and frustrations on the way.

 

Good questions are always welcome.  A good question is about a specific problem you're having, after you have done some research on your own using resources like the search function on this site, CVI help, a good reference book, and search engines like Google.

 

I'm glad to see that you got a book on C.  I still use a handful of my favorite books (but there have been some that I've recycled since they weren't worth much else).  The book you mentioned earlier has some limitations as a reference for CVI since it's a book on C++.

 

What book did you get?  I'll see if I can find a copy and let you know what I think.  

0 Kudos
Message 29 of 31
(2,412 Views)

1- It is not your lack of programming knowledge people are -mainly- complaining about.

Because that's why we are all in this forum: Cover up our lack of information.

We are complaining about the way you use the forum.

 

2- False information !?! If you do not want false information, do not provide false information.

If you think people here are giving you false information, why don't you try to make yourself clear first.

Besides, I did not see even a tiny bit of false information in the replies people sent to your questions.

 

3- Improvement... People complain here because you do not show any improvement, despite many suggestions they provide.

You keep doing everything in your own way, and as we all see, your way is not helping your questions to get solved.

Look, we are discussing something here that has nothing to do with the thread's title...

 

4- Look at other threads in the forum. See how it is easy to get to a solution when questions are asked the right way.

There were not so many multi-page threads before your posts arrived.

Message Edited by ebalci on 09-18-2009 08:06 AM
S. Eren BALCI
IMESTEK
0 Kudos
Message 30 of 31
(2,409 Views)