Porrey.Uwp.IoT.Devices.Ds1307.SetAsync C# (CSharp) Method

SetAsync() public method

Sets the Date and Time on the DS1307.
public SetAsync ( DateTimeOffset value ) : System.Threading.Tasks.Task
value DateTimeOffset The date and time as a System.DateTime object /// that will be saved on the DS1307.
return System.Threading.Tasks.Task
		public async Task SetAsync(DateTimeOffset value)
		{
			byte[] writeBuffer = new byte[]
			{
				RTC_ADDRESS,
				Bcd.FromInt(value.Second),
				Bcd.FromInt(value.Minute),
				Bcd.FromInt(value.Hour),
				Bcd.FromInt((int)value.DayOfWeek),
				Bcd.FromInt(value.Day),
				Bcd.FromInt(value.Month),
				Bcd.FromInt(value.Year >= 2000 ? value.Year - 2000: 0),
			};

			await this.WriteAsync(writeBuffer);
		}

Usage Example

Beispiel #1
0
		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);
			}
		}
All Usage Examples Of Porrey.Uwp.IoT.Devices.Ds1307::SetAsync