LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to add display time and date function in CVI

I use try to add this code to my CVI
 
 
int CVICALLBACK TimeCallback (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 char timeAndDate[80];
 switch (event)
  {
  case EVENT_TIMER_TICK:
    sprintf (timeAndDate, "%s %s", TimeStr (), DateStr ());
       SetCtrlVal(g_vPanelHandle, MAIN_TIMESTRING, timeAndDate);
   break;
  }
 return 0;
}
But I met "winuser.h" error when I debug it.
such as
 
main.c - 10 errors, 1 warning
  "winuser.h"(1466,3)   Warning: Empty declaration.
  "winuser.h"(1466,3)   syntax error; found 'integer constant' expecting ';'.
  "winuser.h"(1466,3)   Unrecognized declaration.
  "winuser.h"(1466,6)   Unrecognized declaration.
  "winuser.h"(1466,8)   Unrecognized declaration.
  "winuser.h"(2717,15)   syntax error; found 'identifier' expecting ')'.
  "winuser.h"(2720,27)   Extraneous formal parameter specification.
  "winuser.h"(2725,15)   syntax error; found 'identifier' expecting ')'.
  "winuser.h"(2728,27)   Extraneous formal parameter specification.
  "winuser.h"(2739,14)   syntax error; found 'integer constant' expecting ')'.
  "winuser.h"(2745,14)   syntax error; found 'integer constant' expecting ')'.
can anybody help me? thanks
 
BR,
Crystal
0 Kudos
Message 1 of 13
(6,699 Views)
Hi!

  As it was suggested in another post, try to define timeAndDate in this way:

        char *timeAndDate;

        timeAndDate = malloc(80*sizeof(char));

      etc.....

 instead of static definition.

I would also suggest you to put <windows.h> header at the top of include list (this was stated in another post too).

Please, let me know if this solves!

graziano
0 Kudos
Message 2 of 13
(6,680 Views)

Hi,

Thanks for your suggestion.

But after  I change as follow


int CVICALLBACK TimeCallback (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
        char *timeAndDate;
        timeAndDate = malloc(80*sizeof(char));
 switch (event)
  {
  case EVENT_TIMER_TICK:
    sprintf (timeAndDate, "%s %s", TimeStr (), DateStr ());
       SetCtrlVal(g_vPanelHandle, MAIN_TIMESTRING, timeAndDate);
   break;
  }
 return 0;
}
and of course I have include windows.h at the top of main.c

#include <windows.h>
#include <analysis.h>
#include "age1960.h"
#include "EMMI.h"
#include <utility.h>
#include <ansi_c.h>
#include <string.h>
#include <formatio.h>
#include <visa.h>
#include <userint.h>
#include <cvirte.h> /* Needed if linking in external compiler; harmless otherwise */

the error is the same as before:-(

Hope you can understand what I mean

0 Kudos
Message 3 of 13
(6,676 Views)

I would also investigate wether you have defined elsewhere in your program some element named "MSG": this is the name of a structure defined in winuser.h (line 1466: the first error in your list) and comes in conflict with controls or variables with the same name exsisting in the application.

I personally tend not to use all-uppercase control names since the risk of conflicting names between my controls (defined as macros in the include file associated with the UIR) and system elements is very high. Nevertheless, sometimes it happens that I choose a name already present in some system include file and the "Empty declaration" error you find is the main warning lamp of this fact.

Let me know if this helps you a little

Roberto



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?
Message 4 of 13
(6,669 Views)

Hi,

yes, as you mentioned, I define a popup ,pls look at code as follow,which i define in the *.h file


#define  MSG                             10
#define  MSG_OK                          2       /* callback function: Button_Message_Dialog_Ok */
#define  MSG_PICTUREBUTTON               3
#define  MSG_MSG                         4

could you tell me how to avoid this conflict. thanks

crystal

0 Kudos
Message 5 of 13
(6,668 Views)
Simply rename MSG panel and control in a different way (Msg, MyMSG, MSGPanel... as you please Smiley Happy ).
Do it in the UIR editor and do not modify the .h file by yourself (it will automatically be regenerated each time you save your uir file!)

Message Edited by Roberto Bozzolo on 01-09-2006 09:56 AM



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?
Message 6 of 13
(6,662 Views)

Hi,

Great! It works after I do what you have told me. Thanks a lot! Since I used to compile with Labview. But now i need to compile with CVI, so I am a freshman of CVI.

Another question with my CVI,

After I debug my CVI, it display run-time errors as follow:

 NON-FATAL RUN-TIME ERROR:   "gsm_rf_tester_main.c", line 201, col 8, thread id 0x000006E4:   Library function error (return value == -79 [0xffffffb1]). The control values could not be completely loaded into the panel because the panel has changed.

but I can got the CVI debug.exe file.

Hope you can help me.

crystal

0 Kudos
Message 7 of 13
(6,657 Views)

I'm happy you solved your problem.

Regarding the -79 error, have you checked the Save/RecallPanelState that Colin suggested in the other thread?



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?
Message 8 of 13
(6,646 Views)

hi

I remark  the Recall Panel State code in my app as colin told me, the error doesn't happen.

thanks

 

0 Kudos
Message 9 of 13
(6,644 Views)
For what it's worth...
 
#include <ansi.c>
// ---------------------------------------------------------------------------
// Date/Time structures and variables
// ---------------------------------------------------------------------------
char  *PtrToTimeString;
time_t   NowSeconds;  // time_t is an unsigned int definition
struct tm  LocalNow, *PtrToLocalNow;
 
void main()
{
...
  // Start the separate thread which gets time and updates the time of day string
  // PtrToTimeString, and updates the top panel time/date display.
  // PtrToTimeString can be accessed anytime from anywhere in the application.
 PtrToLocalNow = &LocalNow;
 displayDateTime = TRUE;
 CmtScheduleThreadPoolFunction (DEFAULT_THREAD_POOL_HANDLE,
              updateDateTimeThread, NULL, NULL);
RunUserInterface();
...
}
 
int CVICALLBACK updateDateTimeThread (void *ctrlID) 
{
/*---------------------------------------------------------------------------------------
 Even though this is identified as a CVICALLBACK, it is actually a separate
 thread, which, as long as the displayDatetime flag is asserted, regularly acquires the
 computer date/time information, formats a character string, and writes that
 string to the top panel. This thread runs continuously until the QuitButton callback
 de-asserts the displayDatetime flag, which causes this thread to cease.
/*-------------------------------------------------------------------------------------*/
 while (displayDateTime)
  {
   // Get the current time from the computer operating system  
  time(&NowSeconds);
   // Convert the time in seconds to the struct tm    
  PtrToLocalNow = localtime (&NowSeconds);
   // Convert the struct tm to a character string           
  PtrToTimeString = asctimeDMYT (PtrToLocalNow);
   // Update the top panel date/time string  
  SetCtrlVal (panelHandle, PANEL_DATE_TIME_STRING, PtrToTimeString); 
   // Delay 1/3 second and do it again
  Delay(0.33);
  }
 return 0;
}
 
Message 10 of 13
(6,611 Views)