public byte[] SpiRead(int handle, int count) { byte[] data = new byte[count]; GCHandle h = GCHandle.Alloc(data, GCHandleType.Pinned); try { short ret = PiGpioNativeMethods.spiRead((ushort)handle, h.AddrOfPinnedObject(), (ushort)data.Length); if (ret < 0) { throw new PiGPIOException(ret); } } finally { h.Free(); } return(data); }