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  | ||||||||||||||
NTP Time howto call with SDK 4.3
Started by JoopC, Feb 04 2013 02:15 PM
Best Answer JoopC, 07 February 2013 - 09:31 PM
Thank you Supra, it's work, thank you. Go to the full post
5 replies to this topic
#1Posted 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? #2Posted 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 #3Posted 04 February 2013 - 05:32 PM
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.
#4Posted 04 February 2013 - 05:44 PM
You cannot use Or inside looping; Only block IF/then ELSE condition.
SUpra. #5Posted 04 February 2013 - 07:42 PM I thought this was (and still is) broken in VB. See Query NTP server. Byte operations not supported? #6Posted 07 February 2013 - 09:31 PM Best Answer
Thank you Supra, it's work, thank you. 0 user(s) are reading this topic0 members, 0 guests, 0 anonymous users | ||||||||||||||
|
||||||||||||||
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | ||||||||||||||