I am using a Netduino Plus 2 with VS 2012 and am trying to sync/set the date and time on the netduino to an NTP server. I have found a function online and made the necessary conversions to VB and ran into a road block here:
fractpart = Convert.ToUInt64(256 * fractpart + ntpData(offsetTransmitTime + i))
I am getting an error "Requested opperation is not valid because the runtume library System.Decimal.Multiply is not defined". I have looked at all references available and can not find a solution. Any help would be greatly appreciated. Here is the full function:
Public 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 = Convert.ToUInt64(256 * intpart + ntpData(offsetTransmitTime + i))
Next
For i As Integer = 4 To 7
fractpart = Convert.ToUInt64(256 * fractpart + ntpData(offsetTransmitTime + i))
Next
Dim milliseconds As ULong = Convert.ToUInt64(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 networkDateTime
End Function