Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert a Long data to Date format in LabVIEW 7.0

I am using a ehternet communication between TINI and Labview. From TINI I am throwing Temperature( DOUBLE) and Date and time Information(LONG). When I try to catch it via TCP/IP client in LabVIEW(Simple Data Server Example) it in fact show me the Temperature value which get converted via Type cast. But the Date information I have tried with time stamp and others but it is not getting solved. I am not getting the right time/date information at all. when I connect it to time stamp it shows me some 1904 and some other time. I dun know why it is happening . any one can help. I am really stuck in here.
0 Kudos
Message 1 of 16
(5,784 Views)
Hi Shawon,

Without know the complete structure of the TINI output, I'm not sure how much help I can be.
I am assuming you meant you are using the "Simple Data Client" example.

There are 2 things you could try, both relate to the second Typecast:
1) On the type of the second typecast wire in a numeric constant with value 0, of the representation U32. Connect the output to the "Format Date/Time String", you can leave the time format blank.

2) On the type of the second typecast wire in a numeric constant with value 0, of the representation U32. Connect the output to the "To timestamp" primitive found on the Numeric >> Conversion tab.

I hope this solves your problem, if however it does not then please reply but can you give me the output format of your T
INI device.

Regards
James
Applications Engineer
NI UK
0 Kudos
Message 2 of 16
(5,784 Views)
Dear James

I couldn't still solve the problem. I let you know whats wrong in here. first of all I am throwing the Date as a Long format from the TINI. Here is the partial code which I have used.

"public void writeLogEntry(Object sample, DataOutputStream dout) throws IOException {
dout.writeLong(((HumiditySample)sample).getTimeStamp());

dout.writeDouble(((HumiditySample)sample).getTemperature());
}"
It is done in java which capture TimeStamp from the system and write in Long format.

when i have tried in ur (b) method u have given me i got the following string"ucev...." not in english format which i couldn't copy here.

when I try to convert it in double format i got the following value "5.33449E-312". I tried to play around with "get
Date/Time string" and other time vi's. Some times I always get some dates from 01/01/1904. Why it comes from 1904. For example when I converted 5.33449E-312 to a TimeStamp, I get dates from 01/01/1904.

Please help me out regarding this. Waiting for ur reply.

Regards

Shawon
0 Kudos
Message 3 of 16
(5,784 Views)
Hi Shawon,

Can you post the output for this line "public void writeLogEntry(Object sample, DataOutputStream dout) throws IOException {
dout.writeLong(((HumiditySample)sample).getTimeSta mp());"

It should be something in the format 3.16289E+9

The reason you are getting a date of 01/01/1904, is that was the date chosen to be the zero second marker.

All timestamps are refrenced as seconds from 00:00:00 01/01/1904.

Regards
James
Applications Engineer
NI UK
0 Kudos
Message 4 of 16
(5,784 Views)
dear james

yaah u true. the output of the java in the TINI from ""public void writeLogEntry(Object sample, DataOutputStream dout) throws IOException {
dout.writeLong(((HumiditySample)sample).getTimeSta mp());" is in the format of 3.16289E+9 comes out. I am tring to convert it to the time and date in LabVIEW but I am always getting some times from 1904. I understood that the all the time stamp has been referenced from 00:00:00 01/01/1904.

But I dun know how to convert it to current time and that point I am having the problem. I want to convert 3.16289E+9 to date and time in labview which is the time and date in tini and I wanna show in Labview and I am getting from 00:00:00 01/01/1904.

I am really stuck in here. Please help me o
ut regarding this. unless this I am not able to solve to proceed in further in my project. please help me out regarding this.

regards

shawon
0 Kudos
Message 5 of 16
(5,784 Views)
Hi Shawon,

Now I know that the output is in the format 3.16289E+9

you can wire the numeric output of your code in to the to timestamp function, located on the Functions pallette All Functions >> Numeric >> Conversion >> To Time Stamp.

I attach a very simple program to show you this.

Regards
James
Applications Engineer
NI UK
0 Kudos
Message 6 of 16
(5,784 Views)
Dear James

I was in fact wrong to understand the difference. It is not 3.16289E+9 but it is 5.33652E-312 when i convert the tini type into typecast using double.

I have created a program for u to see which values I get from tini when I convert the tini format into Double and when I convert it to a Long. the programme "samplejames" where u can see that when I convert it to a U32 i get two data in array index(0 and 1) and they are in order 251 and 2.08684E+9 and while I convert it to a double I get only 5.33652E-312 which are not giving me the right date format. I am really sorry that I gave u the wrong information last time. I am ashamed for that. I attached the whole programme("shawonclient") as well whe
re u can see what I am tring to do. Please help me out within ur busy time. I will be grateful for that.

Regards

Shawon
Download All
0 Kudos
Message 7 of 16
(5,784 Views)
Dear James

I am still waiting for your reply about the date format. I am really in trouble. Please have a look on my two files that I have send to you last mail and please advice me regarding this. I am really in problem regarding that. I am waiting for your reply.

Regards

shawon
0 Kudos
Message 8 of 16
(5,784 Views)
Hi Shawon,

Sorry for the delay, been very busy, I attach a vi that should allow you to read in the timestamp values.

If it doesn't work increase the number of bytes.
If you get timeout errors, decrease the number of bytes.

I will be out of the office for a few days, if this doesn't work, then I will need you to send in your Java code so I can have a look at the TCP comms.

Hope this solves your problem.

Regards
James
Applications Engineer
NI UK
0 Kudos
Message 9 of 16
(5,784 Views)
Dear James

Thank for your reply. I have tried with byte changing and it is not working. when I set it to 8 in timestamp nothing shows and I tried them changing the byte range and it not showing the proper result. I also believe that I have problem in the java code i am sending. how ever I have send the whole application I am working on.

You will see in "HumiditySample.java"; long timeStamp is taking time from system which is written on dout.writeLong in "HumidityLogger.java" which is now captured by "loggingdaemon.java" which finally throws the data in "datalogger.java"to write on the network connection. There is a java file
called"DataLoggerClient.java" which can be run to see the
readings file correctly from the machine which in fact read corriectly as a Client while labView I am facing the problem. Hope this information will help u to get the problem. I am consistengly tring to solve it but i am stuck here. I am tring to learn. please help me out.

regards
shawon
London Metropolitan University
Download All
0 Kudos
Message 10 of 16
(5,784 Views)