Raspberry.IO.InterIntegratedCircuit.I2cDriver.Execute C# (CSharp) Method

Execute() private method

Executes the specified transaction.
private Execute ( int deviceAddress, Raspberry.IO.InterIntegratedCircuit.I2cTransaction transaction ) : void
deviceAddress int The address of the device.
transaction Raspberry.IO.InterIntegratedCircuit.I2cTransaction The transaction.
return void
        internal void Execute(int deviceAddress, I2cTransaction transaction)
        {
            lock (driverLock)
            {
                var control = bscAddress + (int)Interop.BCM2835_BSC_C;

                foreach (I2cAction action in transaction.Actions)
                {
                    if (action is I2cWriteAction)
                    {
                        Write(deviceAddress, action.Buffer);
                    }
                    else if (action is I2cReadAction)
                    {
                        Read(deviceAddress, action.Buffer);
                    }
                    else
                    {
                        throw new InvalidOperationException("Only read and write transactions are allowed.");
                    }
                }

                WriteUInt32Mask(control, Interop.BCM2835_BSC_S_DONE, Interop.BCM2835_BSC_S_DONE);
            }
        }

Usage Example

コード例 #1
0
        /// <summary>
        /// Executes the specified transaction.
        /// </summary>
        /// <param name="transaction">The transaction.</param>
        public void Execute(I2cTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException("transaction");
            }

            driver.Execute(deviceAddress, transaction);
        }