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

NTP Time howto call with SDK 4.3


Best Answer JoopC, 07 February 2013 - 09:31 PM

You cannot use Or inside looping;

Only block IF/then ELSE condition.

 

SUpra.

Thank you Supra, it's work, thank you.

Go to the full post


  • Please log in to reply
5 replies to this topic

#1 JoopC

JoopC

    Advanced Member

  • Members
  • PipPipPip
  • 148 posts

Posted 04 February 2013 - 02:15 PM

hello, We are upgrading to 4.3 but now we get a error bitwise shifting in Visual Basic to get the time from a NTP time server. This is old code and always worked in 4.2

 

 

 

Dim lIntPart As Long = 0 Dim lFractPart As Long = 0

For i As Integer = 0 To 3 lIntPart = (lIntPart << 8) Or ntpData(bOffsetTransmitTime + i) Next   For i As Integer = 4 To 7 lFractPart = (lFractPart << 8) Or ntpData(bOffsetTransmitTime + i) Next  

 

Error 1 Type 'System.Nullable(Of )' is not defined. (The error is under the << 8)

 

Does anyone knows why and also there is a buildin function in the SDK 4.3 for calling the time server.

How can we call this function?  



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 04 February 2013 - 04:50 PM

Hi JoopC,

Netduino Plus 2 includes the NETMF TimeService feature.
http://msdn.microsof...y/ee436640.aspx

As to the bug you're experiencing with Visual Basic... Do you have a small repro (<= 20 lines of code) you can share? We can ping the NETMF and/or VB teams and see if something has broken with the latest bits.

Chris

#3 supra

supra

    Advanced Member

  • Members
  • PipPipPip
  • 210 posts
  • LocationOntario, Canada

Posted 04 February 2013 - 05:32 PM

hello, We are upgrading to 4.3 but now we get a error bitwise shifting in Visual Basic to get the time from a NTP time server. This is old code and always worked in 4.2

 

 

 

Dim lIntPart As Long = 0 Dim lFractPart As Long = 0

For i As Integer = 0 To 3 lIntPart = (lIntPart << 8) Or ntpData(bOffsetTransmitTime + i) Next   For i As Integer = 4 To 7 lFractPart = (lFractPart << 8) Or ntpData(bOffsetTransmitTime + i) Next  

 

Error 1 Type 'System.Nullable(Of )' is not defined. (The error is under the << 8)

 

Does anyone knows why and also there is a buildin function in the SDK 4.3 for calling the time server.

How can we call this function?  

Public Shared Function GetNetworkTime() As DateTime	Dim ep As New IPEndPoint(Dns.GetHostEntry("time-a.nist.gov").AddressList(0), 123)	Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)	s.Connect(ep)	Dim ntpData As Byte() = New Byte(47) {}	' RFC 2030	ntpData(0) = &H1b	For i As Integer = 1 To 47		ntpData(i) = 0	Next	s.Send(ntpData)	s.Receive(ntpData)	Dim offsetTransmitTime As Byte = 40	Dim intpart As ULong = 0	Dim fractpart As ULong = 0	For i As Integer = 0 To 3		intpart = 256 * intpart + ntpData(offsetTransmitTime + i)	Next	For i As Integer = 4 To 7		fractpart = 256 * fractpart + ntpData(offsetTransmitTime + i)	Next	Dim milliseconds As ULong = (intpart * 1000 + (fractpart * 1000) / &H100000000L)	s.Close()	Dim timeSpan__1 As TimeSpan = TimeSpan.FromTicks(CLng(milliseconds) * TimeSpan.TicksPerMillisecond)	Dim dateTime As New DateTime(1900, 1, 1)	dateTime += timeSpan__1	Dim offsetAmount As TimeSpan = TimeZone.CurrentTimeZone.GetUtcOffset(dateTime)	Dim networkDateTime As DateTime = (dateTime + offsetAmount)	Debug.Print(networkDateTime.ToString())	Return networkDateTimeEnd Function

 

Supra.



#4 supra

supra

    Advanced Member

  • Members
  • PipPipPip
  • 210 posts
  • LocationOntario, Canada

Posted 04 February 2013 - 05:44 PM

hello, We are upgrading to 4.3 but now we get a error bitwise shifting in Visual Basic to get the time from a NTP time server. This is old code and always worked in 4.2

 

 

 

Dim lIntPart As Long = 0 Dim lFractPart As Long = 0

For i As Integer = 0 To 3 lIntPart = (lIntPart << 8) Or ntpData(bOffsetTransmitTime + i) Next   For i As Integer = 4 To 7 lFractPart = (lFractPart << 8) Or ntpData(bOffsetTransmitTime + i) Next  

 

Error 1 Type 'System.Nullable(Of )' is not defined. (The error is under the << 8)

 

Does anyone knows why and also there is a buildin function in the SDK 4.3 for calling the time server.

How can we call this function?  

 

You cannot use Or inside looping;

Only block IF/then ELSE condition.

 

SUpra.



#5 emg

emg

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 04 February 2013 - 07:42 PM

I thought this was (and still is) broken in VB. See Query NTP server. Byte operations not supported?



#6 JoopC

JoopC

    Advanced Member

  • Members
  • PipPipPip
  • 148 posts

Posted 07 February 2013 - 09:31 PM   Best Answer

You cannot use Or inside looping;

Only block IF/then ELSE condition.

 

SUpra.

Thank you Supra, it's work, thank you.






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.