Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

A tip for sending a DateTime value through serial


  • Please log in to reply
2 replies to this topic

#1 Bendage

Bendage

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts
  • LocationIrvine, CA

Posted 30 March 2012 - 03:39 AM

So tonight I was racking my brain on the easiest way to send a datetime val as a string through serial to my Netduino. The problem is that the Netduino code in my app is so big I didn't want to write a bunch of substring parsing code to parse the datetime string to set the controller clock.

I noticed the Ticks constructor on the New DateTime object in the Micro Framework so I figured I'd just convert DateTime.Now.Ticks.ToString on the PC and send it through. What happened was the tick count exceeded the Micro Framework DateTime.MaxValue. Hmmmm!

Looking through it more MF starts their DateTime at 1/1/1601 12:00 AM while Framework 4.0 is 1/1/1 12:00 AM

Here is the solution if anyone is interested


// PC Send
string time = (DateTime.Now.Ticks - new DateTime(1601, 1, 1).Ticks).ToString();


// Send time string via serial....

// Netduino Instantiate
Microsoft.SPOT.Hardware.Utility.SetLocalTime(new DateTime(Int64.Parse(time));



Bam! You got your clock set with no parsing.

#2 emg

emg

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 30 March 2012 - 10:13 AM

Yep. Works via Ethernet too. I send logging data from the Netduino back to a PC and use UDP sockets to create a poor mans NTP server where the PC can force a time setting on the Netduino or the Netduino can request a time update.

#3 emg

emg

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 01 April 2012 - 04:52 PM

Also remember if you sending the time from the netduino back to the PC to add 1600 years to the ticks value for the correct date. See here: DateTime ticks inconsistent between .NET MF 4.2 and full .NET 4.0?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.