public Mb85rc256vDevice(int busNumber, byte chipNumber, I2cBusSpeed speed = I2cBusSpeed.FastMode, I2cSharingMode sharingMode = I2cSharingMode.Exclusive) : base(chipNumber, MemorySize) { // Get address var address = GetDataI2cAddress(chipNumber); // Connect to hardware Hardware = I2cExtensions.Connect(busNumber, address, speed, sharingMode); }
public Ms5611Device(int busNumber, bool csb, Ms5611Osr rate, I2cBusSpeed speed = I2cBusSpeed.FastMode, I2cSharingMode sharingMode = I2cSharingMode.Exclusive) { // Get address ChipSelectBit = csb; Address = GetI2cAddress(csb); // Connect to hardware _hardware = I2cExtensions.Connect(busNumber, Address, speed, sharingMode); // Initialize members Prom = new Ms5611PromData(); Osr = rate; // Read current calibration data (potentially not stable until next reset) // We don't reset automatically so that it is possible for any ongoing tasks to complete ReadProm(); }
public static Mb85rcvDeviceId?GetDeviceId(int busNumber, byte idAddress, byte dataAddress, I2cBusSpeed speed = I2cBusSpeed.FastMode, I2cSharingMode sharingMode = I2cSharingMode.Exclusive) { // Connect to ID device using (var framIdRegister = I2cExtensions.Connect(busNumber, idAddress, speed, sharingMode)) { // Send ID command sequence, returning device ID bytes var dataAddress8bit = (byte)(dataAddress << 1); var data = new byte[Mb85rcvDeviceId.Size]; var transfer = framIdRegister.WriteReadPartial(new[] { dataAddress8bit }, data); if (transfer.Status == I2cTransferStatus.SlaveAddressNotAcknowledged) // Any other error must throw { // Return null when not found return(null); } // Decode and return ID when found return(new Mb85rcvDeviceId(data)); } }
public Pca9685Device(int busNumber, byte chipNumber, int?clockSpeed, I2cBusSpeed speed = I2cBusSpeed.FastMode, I2cSharingMode sharingMode = I2cSharingMode.Exclusive) { // Validate if (clockSpeed.HasValue && (clockSpeed == 0 || clockSpeed.Value > ClockSpeedMaximum)) { throw new ArgumentOutOfRangeException(nameof(clockSpeed)); } // Get address var address = GetI2cAddress(chipNumber); // Connect to hardware _hardware = I2cExtensions.Connect(busNumber, address, speed, sharingMode); // Initialize configuration ClockIsExternal = clockSpeed.HasValue; ClockSpeed = clockSpeed ?? InternalClockSpeed; FrequencyDefault = CalculateFrequency(PrescaleDefault, ClockSpeed); FrequencyMinimum = CalculateFrequency(PrescaleMaximum, ClockSpeed); // Inverse relationship (max = min) FrequencyMaximum = CalculateFrequency(PrescaleMinimum, ClockSpeed); // Inverse relationship (min = max) // Build channels _channels = new Collection <Pca9685ChannelValue>(); Channels = new ReadOnlyCollection <Pca9685ChannelValue>(_channels); for (var index = 0; index < ChannelCount; index++) { _channels.Add(new Pca9685ChannelValue(index)); } // Set "all call" address I2cExtensions.WriteJoinByte(_hardware, (byte)Pca9685Register.AllCall, I2cAllCallAddress); // Enable auto-increment and "all call" I2cExtensions.WriteReadWriteBit(_hardware, (byte)Pca9685Register.Mode1, (byte)(Pca9685Mode1Bits.AutoIncrement | Pca9685Mode1Bits.AllCall), true); // Read current values and update properties ReadAll(); }
public Mb85rc04vDevice(int busNumber, byte chipNumber, I2cBusSpeed speed = I2cBusSpeed.FastMode, I2cSharingMode sharingMode = I2cSharingMode.Exclusive) : base(chipNumber, MemorySize) { // Check device addresses var lowerAddress = GetDataI2cAddress(chipNumber, false); var upperAddress = GetDataI2cAddress(chipNumber, true); // Connect to devices try { Hardware = I2cExtensions.Connect(busNumber, lowerAddress, speed, sharingMode); HardwareUpper = I2cExtensions.Connect(busNumber, upperAddress, speed, sharingMode); } catch { // Free resources on initialization error Hardware?.Dispose(); HardwareUpper?.Dispose(); // Continue error throw; } }