private async Task TestClock() { // *** // *** Clock // *** Ds1307 dtc = new Ds1307(); await dtc.InitializeAsync(); // *** // *** Get the date and time from the clock // *** DateTimeOffset dt = await dtc.GetAsync(); // *** // *** Create an NTP client and get the date and time // *** NtpClient ntp = new NtpClient(); DateTimeOffset?ndt = await ntp.GetAsync("0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org", "3.pool.ntp.org"); // *** // *** Update the clock if we have a result from the servers // *** if (ndt.HasValue) { await dtc.SetAsync(ndt.Value); } }
private async Task Test() { Ds1307 dtc = new Ds1307(); NtpClient ntp = new NtpClient(); try { await dtc.InitializeAsync(); // *** // *** Create an NTP client and get the date and time // *** var ndt = await ntp.GetAsync("0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org", "3.pool.ntp.org"); // *** // *** Update the clock if we have a result from the servers // *** if (ndt.HasValue) { await dtc.SetAsync(ndt.Value); } // *** // *** Get the date and time from the clock // *** if (!dtc.IsInitialized) { return; } DateTimeOffset dt = await dtc.GetAsync(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { dtc.Dispose(); } }