/// <summary> /// Creates a new instance of the <see cref="Tlc59711Connection"/> class and initializes it. /// </summary> /// <param name="connection">A open SPI connection</param> /// <param name="initializeWithDefault">If <c>true</c> the SPI connection will be initialized with common data transfers settings.</param> /// <param name="numberOfDevices">Number of <see cref="ITlc59711Device"/>s connected together.</param> public Tlc59711Connection(INativeSpiConnection connection, bool initializeWithDefault, int numberOfDevices) { if (ReferenceEquals(connection, null)) { throw new ArgumentNullException("connection"); } if (numberOfDevices <= 0) { throw new ArgumentOutOfRangeException("numberOfDevices", "You need at least one device."); } this.connection = connection; if (initializeWithDefault) { connection.SetBitsPerWord(BITS_PER_WORD); connection.SetSpiMode(SPI_MODE_0); connection.SetMaxSpeed(SPEED); connection.SetDelay(DELAY); } var requiredMemorySize = numberOfDevices * Tlc59711Device.COMMAND_SIZE; transferBuffer = connection.CreateTransferBuffer(requiredMemorySize, SpiTransferMode.Write); deviceCluster = new Tlc59711Cluster(transferBuffer.Tx, numberOfDevices); }
/// <summary> /// Initializes a new instance of the <see cref="Tlc59711DeviceChain"/> class. /// </summary> /// <param name="connection">The connection.</param> /// <param name="initializeWithDefault">if set to <c>true</c> [initialize with default].</param> /// <param name="numberOfDevices">The number of devices.</param> /// <exception cref="ArgumentNullException">connection.</exception> /// <exception cref="ArgumentOutOfRangeException">numberOfDevices - You need at least one device.</exception> public Tlc59711DeviceChain(INativeSpiConnection connection, bool initializeWithDefault, int numberOfDevices) { if (connection is null) { throw new ArgumentNullException("connection"); } if (numberOfDevices <= 0) { throw new ArgumentOutOfRangeException("numberOfDevices", "You need at least one device."); } this.connection = connection; if (initializeWithDefault) { connection.SetBitsPerWord(BitsPerWord); connection.SetSpiMode(SpiMode0); connection.SetMaxSpeed(Speed); connection.SetDelay(Delay); } var requiredMemorySize = numberOfDevices * Tlc59711Device.CommandSize; this.transferBuffer = connection.CreateTransferBuffer(requiredMemorySize, SpiTransferMode.Write); this.deviceCluster = new Tlc59711Cluster(this.transferBuffer.Tx, numberOfDevices); }
/// <summary> /// Creates a new instance of the <see cref="Tlc59711Connection"/> class and initializes it. /// </summary> /// <param name="connection">A open SPI connection</param> /// <param name="initializeWithDefault">If <c>true</c> the SPI connection will be initialized with common data transfers settings.</param> /// <param name="numberOfDevices">Number of <see cref="ITlc59711Device"/>s connected together.</param> public Tlc59711Connection(INativeSpiConnection connection, bool initializeWithDefault, int numberOfDevices) { if (ReferenceEquals(connection, null)) throw new ArgumentNullException("connection"); if (numberOfDevices <= 0) throw new ArgumentOutOfRangeException("numberOfDevices", "You need at least one device."); this.connection = connection; if (initializeWithDefault) { connection.SetBitsPerWord(BITS_PER_WORD); connection.SetSpiMode(SPI_MODE_0); connection.SetMaxSpeed(SPEED); connection.SetDelay(DELAY); } var requiredMemorySize = numberOfDevices * Tlc59711Device.COMMAND_SIZE; transferBuffer = connection.CreateTransferBuffer(requiredMemorySize, SpiTransferMode.Write); deviceCluster = new Tlc59711Cluster(transferBuffer.Tx, numberOfDevices); }