示例#1
0
        private async void Button_ClickAsync(object sender, RoutedEventArgs e)
        {
            Ds1307    ds  = new Ds1307();
            NtpClient ntp = new NtpClient();

            try
            {
                // await ds.InitializeAsync();
                // Debug.Write(ds.DeviceAddress);
                // //////     DateTime? dt = await ntp.GetAsync(@"europe.pool.ntp.org");
                // if (ds.IsInitialized)
                //     Debug.WriteLine("zains");

                // var dto = new DateTimeOffset(DateTime.Now);
                // await ds.SetAsync(dto);

                //// var dtoa = await ds.GetAsync();
                //// Debug.WriteLine(dtoa.DateTime.ToLocalTime());



                await LoadChartContents();
            }

            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                ds.Dispose();
            }
        }
示例#2
0
        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();
            }
        }