/// <summary> /// Gets the date / time in 24 hour format. /// </summary> /// <returns>A DateTime object</returns> public DateTime Get() { var clockData = new byte[7]; var transaction = new I2CDevice.I2CTransaction[] { _i2CBus.CreateWriteTransaction(new[] { DS1307_RTC_START_ADDRESS }), _i2CBus.CreateReadTransaction(clockData) }; if (_i2CBus.Execute(_configuration, transaction, TIMEOUT_TRANS) == 0) { throw new Exception("I2C transaction failed"); } return(new DateTime( BcdToDec(clockData[6]) + 2000, // year BcdToDec(clockData[5]), // month BcdToDec(clockData[4]), // day BcdToDec(clockData[2] & 0x3f), // hours over 24 hours BcdToDec(clockData[1]), // minutes BcdToDec(clockData[0] & 0x7f) // seconds )); }