Esempio n. 1
0
        public byte[] SpiXfer(int handle, byte[] txBuff)
        {
            byte[]   rxBuff = new byte[txBuff.Length];
            GCHandle tx     = GCHandle.Alloc(txBuff, GCHandleType.Pinned);

            try
            {
                GCHandle rx = GCHandle.Alloc(rxBuff, GCHandleType.Pinned);
                try
                {
                    short ret = PiGpioNativeMethods.spiXfer((ushort)handle, tx.AddrOfPinnedObject(), tx.AddrOfPinnedObject(), (ushort)txBuff.Length);
                    if (ret < 0)
                    {
                        throw new PiGPIOException(ret);
                    }
                }
                finally
                {
                    rx.Free();
                }
            }
            finally
            {
                tx.Free();
            }
            return(rxBuff);
        }