LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

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

is there a sample code available to see how to create a log file box or wondow in CVI and also the date and time?

 

 

and also how do you give kudos to people on NI.com?

0 Kudos
Message 1 of 31
(5,290 Views)

Darnell:

 

I'm not sure just what you are looking for.  Can you be any more descriptive?

 

If you want a log window, take a look at the textbox example that ships with CVI.  It shows you how to add lines, insert lines, delete lines, and clear the box.

 

If you want to get the system date and time, there are a bunch of functions available to do that.  Just search help for date or time.

One of the most flexible ways to report the date and time is the FormatDateTimeString() function.  It operates on the output of GetCurrentDateTime(), and let's you format the date and time just about any way you would like.  To see the options on formatting, go to Help, then on the index tab enter FormatDateTimeString and press enter.  Then in the help text that's displayed, click on the highlighted words absolute date/time format specifiers.

 

For simple file operations where you just want to write messages to a file, you can use the ANSI C functions fopen(), fprintf(), and fclose().

Here is a simple example that writes time-stamped messages to a file and then uses notepad to call up the file for demo purposes so you don't have to hunt for it to see what's in it.

 

#include <utility.h>
#include <ansi_c.h>
#include <userint.h>
main()
{
 FILE *fpMyFile;
 char myText[256];
 char dateTimeString[256];
 double dateTimeVal;
 int i;
 
 if ((fpMyFile = fopen ("myfile.txt", "w")) == NULL)
  MessagePopup ("File Save Error", "Error saving file");
 else
 {
  
  for (i=0; i<5; i++)
  {
   GetCurrentDateTime (&dateTimeVal);
   FormatDateTimeString (dateTimeVal, "%I:%M:%S %p %A, %B %d, %Y", dateTimeString, 256);
   sprintf(myText, "%s: Message number %d\n", dateTimeString, i+1);
   fprintf(fpMyFile, "%s", myText);
   Delay(1);
  }
  
  fclose (fpMyFile);
  
  system("notepad.exe myfile.txt");
 }
}

As far as giving Kudos on this forum, each question and response box should have a goldstar icon labeled Kudos! on the right hand side.  To give a Kudo for that particular response, just click on the star.  For questions that you post, you should also see a green checkmark icon on each response.  If one response answered your question, you can click on the green checkmark to identify that response as your answer.  If you don't see the goldstar icon on every response and the green checkmark on responses to your questions, what browser are you using?  How do you get to this forum?  If you're using some old-style newsreader, try using a full-featured web browser (Internet Explorer, Google Chrome, Firefox, etc.) and start at http://forums.ni.com

Message 2 of 31
(5,311 Views)

darnell,

 

1- You can use the textbox, listbox, table or tree controls to log events and data while your code is running.

I'm sure in the CVI samples folder there are many sample code for programming these controls.

 

Textboxes are easy to use but they are also simple in terms of graphical appearance. You cannot modify much other than text size and color, and the settings are global, I mean, when you change text color in a textbox, all text changes to new color. You cannot set different colors for your error messages, measurement results and normal event logs.

 

However, for tree and table controls, you can change the attributes of each cell. So that it is possible to write each new entry to the table in a different graphical look.

You can even use multiple columns to align specific parts (like time and date information) of your log data.

 

It is even possible to insert images into table/tree cells. I personally use them to indicate if the added log line is an error message, or if there is an out of limits measurement, etc..

 

 

2- There are many time/date functions in CVI. Just open the function panel search and type "time". Then select the one appropriate for your needs.

 

3- To give kudos, simply click on the yellow star that appears on the right hand side of each message. You will see "1" appearing on the star if you are the first person to rate the message. If other people rated that message already than the kudos counter will just increment by one.

 

Hope this helps, 

S. Eren BALCI
IMESTEK
0 Kudos
Message 3 of 31
(5,311 Views)
You may not be seeing the yellow Kudos box depending on your user profile settings. Go to "My profile" page, "Personal Preferences" tab and "Kudos Settings" section on the bottom of the page, and check that the "Reduced Kudos UI" checkmark is not checked: as explained in the online help, "This profile setting hides selected parts of the Kudos User Interface, such as the Kudos button in messages and the Kudos column in lists of messages" so it prevents you from kudoing messages.


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 4 of 31
(5,299 Views)

got it, thats why i was confuse when you guys kept saying give me kudos, but i have it now. thanks

 

 

ok al or roberto whoever

 

 

ok basically i want to creat a log. basically i want to keep track of of all the error handling also .

 

im going to post a portion of my code to explain what i want to do.

 

i want the user to have option to to type his name in, and then type in the description of what hes  getting ready to

 

do.  for example   Name:  Roberto

 

                            Event: Test chiller code

 

                           etc........................./// this portion is being extra to learn how to use a log window, i never tried to use one

                                                        // so i wanted to try it out.

 but the part i really want all of my message popup strings or error handling i want to be able to send them to a log window or log file

 

i want to be able to keep track and also pull the date and time. 

 

 

 

this below , you notice if any errors popup you will see message popup , so im trying to keep of all those popup in a log file or log window

 

 along with the date and time , im going to try it myself now

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

 

 

int MASTER_RESET_UPDATE_DEVICE (int PHYSICAL_PORT, int CommandCode,
                                        int deviceAddress, int data)
{    int RS232Error=0;
    int msblsb=0;
    int MSCardAddress=0;
    int bytes_sent=0;
    int bytes_read=0;


    char            read_data[TEXT_LENGTH];
    unsigned char   outputdata[NUM_BYTE_IN_CMD];
    unsigned char    inbuff    [NUM_BYTE_IN_RESP];


    bytes_sent= OpenComConfig(PHYSICAL_PORT,"",BAUDRATE,
                              PARITY,DATABITS,STOPBITS,INPUTQ,OUTPUTQ);
   
   
      if (bytes_sent<VI_SUCCESS)
             
    {
       
       
        RS232Error = ReturnRS232Err ();
       
        if (RS232Error)
           
        DisplayRS232Error ( bytes_sent, bytes_read);
       

           
    }
         
   
    memset( outputdata, 0, NUM_BYTE_IN_CMD);
   
    memset( inbuff,     0, NUM_BYTE_IN_RESP);   
   
    outputdata[MSCARD_BYTE] = MSCardAddress;
   
    outputdata[1] = CommandCode; //'U';
   
    // embed controller number and device address into output message

    data <<= NUM_ADDRESS_BITS; // left shift data bits
   
    msblsb = data | deviceAddress;  // combine data and address bits
   
    outputdata[2] = (msblsb>>8) & 0xff;  // Set MSB
   
    outputdata[3] =  msblsb & 0xff;  // Set LSB
   
    outputdata[4]=0;
   
    outputdata[5]=0;
   
    // calc check sum
    outputdata[6] = outputdata[0] + outputdata[1] + outputdata[2] +
                    outputdata[3] +outputdata[4]+ outputdata[5];
   
    outputdata[6] = outputdata[6] & 0xFF;


    bytes_sent=ComWrt(PHYSICAL_PORT,outputdata,NUM_BYTE_IN_CMD);
   
     if (bytes_sent!=PHYSICAL_PORT )
             
    {
       
            RS232Error = ReturnRS232Err ();
       
            if (RS232Error)
           
            DisplayRS232Error ( bytes_sent, bytes_read);
       
    }
   
   

    bytes_read=ComRd(PHYSICAL_PORT,inbuff,NUM_BYTE_IN_CMD);
     
    if (bytes_read!=PHYSICAL_PORT )
             
    {
       
       
            RS232Error = ReturnRS232Err ();
       
            if (RS232Error)
           
            DisplayRS232Error ( bytes_sent, bytes_read);
       

           
    }
   

        if (bytes_sent != NUM_BYTE_IN_CMD)     // Get response from COM device
   
    {
            RS232Error = ReturnRS232Err ();
       
            if (RS232Error)
           
            DisplayRS232Error ( bytes_sent, bytes_read);
       
       
    }


       
    if (outputdata[MSCARD_BYTE] != inbuff[MSCARD_BYTE])    // compare card Address bytes
                                       
       
    {
            MessagePopup("%s","CHECK CARD ADDRESS!!");
    }
       
      
    if (outputdata[SEND_CHKSUM_BYTE] != inbuff[RECORD_CHKSUM_BYTE])// compare checksum bytes
    {
            MessagePopup("%s","CHECK SUM BYTE NOT EQUAL!!");
    }
   
    if (inbuff[REC_BUSERROR_BYTE] == 0)// Check returned status byte   
    {
       
        return VI_SUCCESS;
    }

return 0;   
       

}
 

 

 

 

 

0 Kudos
Message 5 of 31
(5,292 Views)
With reference to error checking, you may find useful a document I published some time ago about it: I recently updated it so that it s more readable. Thake a look at it and consider if it can help you in developing a good error-checking strategy in your application.


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 6 of 31
(5,288 Views)
i want to try something where would i place those functions in your in the code below that i posted previsiously
0 Kudos
Message 7 of 31
(5,285 Views)

the document you posted, im getting alot of errors , which i can fix its which is no problem, im getting alot of errors which i included alot libraries

 

the need to be included to run the program , but its missing i guess a prototype you use for the Month function also.

 

was that done on person just for us to have something to reference?

0 Kudos
Message 8 of 31
(5,283 Views)

Which errors are you finding? The code should compile without errors unless you are running a CVI 8.5 or higher. In this case, due to the introduction of C99 features in the compiler you must do the following modifications:

 

  1. At the beginning of the #include file add the line
    #pragma iso_9899_1999;
  2. In the definition of the error message functions you must change from "char *function" to "const char *function"

With reference to "Month" function, it simply returns the verbose short name of the month received as a parameter:

 char * CVIFUNC Month (int m)

// Return month name
{
    switch (m) {
        case 1:  return "Jan";
        case 2:  return "Feb";
        case 3:  return "Mar";
        case 4:  return "Apr";
        case 5:  return "May";
        case 6:  return "Jun";
        case 7:  return "Jul";
        case 8:  return "Aug";
        case 9:  return "Sep";
        case 10: return "Oct";
        case 11: return "Nov";
        case 12: return "Dec";
    }
    return 0;
}



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 9 of 31
(5,280 Views)

yea i have 9.0.

 

is this a way i can all my pop ups to log window or file

0 Kudos
Message 10 of 31
(5,278 Views)