LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

time shift plotting data on absolute time graph

Solved!
Go to solution

Hi All,

 

I'm plotting some data on an absolute time graph and I find 2 hours of time shift between data shown by the debugger (on the left)  and data plotted on the graph (X - AUTO SCALE).

The time registered in ptTime, has been acquired using the "time ()" function and the PC has Amsterdam, Berlin, Rome as time zone.

Here below a screen shot that put together the code, the debugger and the result.

By the way, the debugger is showing the correct time version!

 

 

Anyone can suggest me how to treat data in order to have the same result on debugger window and on the graph?

 

Many thanks and regards

Sergio

0 Kudos
Message 1 of 7
(5,511 Views)

You forgot the screenshot Smiley Wink

0 Kudos
Message 2 of 7
(5,508 Views)

Sorry, I've used "Insert Image" but apparently I made a mistake.

 

Well I'll try with an attachment now.

 

Sergio

0 Kudos
Message 3 of 7
(5,505 Views)

1. Make sure that you don't have any offset specified for the graph's x-axis. Edit the graph in the UI Editor, and verify that the hour offset is zero:

 

time.png

 

2. The screenshot you posted for the debugger shows the times formatted as if they were time_t times, not UIDateTime times. The graph expects UIDateTime times, so make sure that this is what you're passing to the plotting function.

 

This is how the CVI debugger shows UIDateTime times and time_t times, respectively:

 

timeformat.png

0 Kudos
Message 4 of 7
(5,477 Views)

Thank you for the suggestions, here below my considerations.

1. The x-axis offset is zero

2. Yes I'm using a time_t array as X axis data, infact I declare VAL_UNSIGNED_INTEGER as X data type in the PlotXY() function, so this could be the problem.

    Let me ask few questions:

    a. in the CVI debugger you show, the time_t variable appears as a double, while its definition in "time.h" is "typedef unsigned int time_t;" so I'm a little bit confused

    b. I was not able to find UIDateTime type in the CVI help, is it the value returned by GetCurrentDateTime(double *)?

    c. Is there any function to convert time_t values into UIDateTime values?

 

Thanks for the help

Sergio

0 Kudos
Message 5 of 7
(5,434 Views)
Solution
Accepted by Laser

Question: in the CVI debugger you show, the time_t variable appears as a double, while its definition in "time.h" is "typedef unsigned int time_t;" so I'm a little bit confused.

Answer: I did something non-sensical in that screenshot: I took a variable of type double (it happened to be a UIDateTime, actually) and configured the debugger to format it as if it were a time_t variable. The formatted values that the debugger shows me, as a result, are invalid, of course. But I just wanted to show you the time_t formatting, because it matches what you have in your screenshot, and I was already suspicious that you were using time_t variables to pass to the graph.

 

By the way, If you're not familiar with how you can change the formatting in the debugger, this is how you do it:

 

format.png

 

Usually, the debugger can automatically pick the best format to use, based on the data type of the variable (for example, with time_t variables). But in this case, what the debugger calls a "Date Time" variable is simply a double. The debugger can't assume that you want to view all of your double variables as a "Date Time", and so you have to override it yourself.

 

Question: I was not able to find UIDateTime type in the CVI help, is it the value returned by GetCurrentDateTime(double *)?

Answer: There's really no such thing as a "UIDateTime" data type. I was a bit careless with my terminology. Unfortunately, when you're dealing with dates and times, there are many possible representations of these quantities in the C world, and it's important that you use the correct variant for the purpose that you're using it for. In this case, graph controls expect that you pass it the time format that is used by the UI library, i.e., the one that is returned by the GetCurrentDateTime or MakeDateTime functions. The underlying C data type for this time representation is simply double, and so there isn't a good name to use to refer to it. That's why I used UIDateTime, but I should have been more clear than that.

 

Question: Is there any function to convert time_t values into UIDateTime values

Answer: Yes. you can use the following two Programmer's Toolbox functions, in exactly this sequence:

 

    CVIAbsoluteTimeFromCVIANSITime(time_t ansiTime, CVIAbsoluteTime *absTime);

    CVIAbsoluteTimeToCVIUILTime(CVIAbsoluteTime absTime, double *uilTime);

 

 

Message 6 of 7
(5,427 Views)

Thank you very much, you have been clear and completly satisfying.

 

Sergio

0 Kudos
Message 7 of 7
(5,405 Views)