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); }
byte[] IPiGPIO.BSpiXfer(int gpioCS, byte[] txBuffer) { byte[] rxBuffer = new byte[txBuffer.Length]; GCHandle tx = GCHandle.Alloc(tx, GCHandleType.Pinned); try { GCHandle rx = GCHandle.Alloc(rxBuffer, GCHandleType.Pinned); try { short ret = PiGpioNativeMethods.bspiXfer((ushort)gpioCS, tx.AddrOfPinnedObject(), rx.AddrOfPinnedObject(), (ushort)txBuffer.Length); if (ret < 0) { throw new PiGPIOException(ret); } } finally { rx.Free(); } } finally { tx.Free(); } return(rxBuffer); }
public byte[] I2CReadBytes(int handle, int num) { byte[] data = new byte[num]; GCHandle h = GCHandle.Alloc(data, GCHandleType.Pinned); try { short ret = PiGpioNativeMethods.i2cReadDevice((ushort)handle, h.AddrOfPinnedObject(), (ushort)num); if (ret < 0) { throw new PiGPIOException(ret); } if (ret < num) { byte[] real = new byte[ret]; Array.Copy(data, real, ret); return(real); } else { return(data); } } finally { h.Free(); } }
public CallbackInfo AddCallback(int gpio, Edge edge, GpioCallback callback) { List <CallbackInfo> callbacks; lock (this.m_callbacks) { if (this.m_callbacks.ContainsKey(gpio)) { callbacks = this.m_callbacks[gpio]; } else { short ret = PiGpioNativeMethods.SetAlertFunc((ushort)gpio, this.GpioAlertCallback); if (ret < 0) { throw new PiGPIOException(ret); } callbacks = new List <CallbackInfo>(); this.m_callbacks.Add(gpio, callbacks); } } CallbackInfo cbi = new CallbackInfo((uint)gpio, 0, edge, callback); lock (callbacks) { callbacks.Add(cbi); } return(cbi); }
public void Write(int gpio, bool value) { short ret = PiGpioNativeMethods.Write((ushort)gpio, (ushort)(value ? 1 : 0)); if (ret < 0) { throw new PiGPIOException(ret); } }
/// <inheritDoc /> public void SetPullUpDown(int gpio, PullUpDown pud) { short ret = PiGpioNativeMethods.SetPullUpDown((ushort)gpio, (ushort)pud); if (ret < 0) { throw new PiGPIOException(ret); } }
/// <inheritDoc /> public void GlitchFilter(int gpio, int steady) { short ret = PiGpioNativeMethods.GlitchFilter((ushort)gpio, (ushort)steady); if (ret < 0) { throw new PiGPIOException(ret); } }
public void BSpiOpen(int gpioCS, int gpioMiso, int gpioMosi, int gpioClk, int bauds, int flags) { short ret = PiGpioNativeMethods.bspiOpen((ushort)gpioCS, (ushort)gpioMiso, (ushort)gpioMosi, (ushort)gpioClk, (ushort)bauds, unchecked ((ushort)flags)); if (ret < 0) { throw new PiGPIOException(ret); } }
public void ClearBits_32_53(int bits) { short ret = PiGpioNativeMethods.clearBits_32_53(unchecked ((uint)bits)); if (ret < 0) { throw new PiGPIOException(ret); } }
/// <inheritDoc /> public void NoiseFilter(int gpio, int steady, int active) { short ret = PiGpioNativeMethods.NoiseFilter((ushort)gpio, (ushort)steady, (ushort)active); if (ret < 0) { throw new PiGPIOException(ret); } }
public void BSpiClose(int gpioCS) { short ret = PiGpioNativeMethods.bspiClose((ushort)gpioCS); if (ret < 0) { throw new PiGPIOException(ret); } }
public void SetBits_0_31(int bits) { short ret = PiGpioNativeMethods.setBits_0_31(unchecked ((uint)bits)); if (ret < 0) { throw new PiGPIOException(ret); } }
/// <inheritDoc /> public void SetMode(int gpio, Mode mode) { short ret = PiGpioNativeMethods.SetMode((ushort)gpio, (ushort)mode); if (ret < 0) { throw new PiGPIOException(ret); } }
public void SpiClose(int handle) { short ret = PiGpioNativeMethods.spiClose((ushort)handle); if (ret < 0) { throw new PiGPIOException(ret); } }
/// <inheritDoc /> public Mode GetMode(int gpio) { short value = PiGpioNativeMethods.GetMode((ushort)gpio); if (value < 0) { throw new PiGPIOException(value); } return((Mode)value); }
public bool Read(int gpio) { short ret = PiGpioNativeMethods.Read((ushort)gpio); if (ret < 0) { throw new PiGPIOException(ret); } return(ret != 0); }
public int FileOpen(string file, int mode) { short ret = PiGpioNativeMethods.fileOpen(file, (short)mode); if (ret < 0) { throw new PiGPIOException(ret); } return(ret); }
public int I2COpen(int bus, int address, int flags) { short ret = PiGpioNativeMethods.I2COpen((ushort)bus, (ushort)address, (ushort)flags); if (ret < 0) { throw new PiGPIOException(ret); } return(ret); }
public int SpiOpen(int chan, int baud, int flags) { short ret = PiGpioNativeMethods.spiOpen((ushort)chan, (ushort)baud, (ushort)flags); if (ret < 0) { throw new PiGPIOException(ret); } return(ret); }
public void SpiWrite(int handle, byte[] data) { GCHandle h = GCHandle.Alloc(data, GCHandleType.Pinned); try { short ret = PiGpioNativeMethods.spiWrite((ushort)handle, h.AddrOfPinnedObject(), (ushort)data.Length); if (ret < 0) { throw new PiGPIOException(ret); } } finally { h.Free(); } }
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); }
public PiGpio() { //Disable internal signal handling uint cfg = PiGpioNativeMethods.cfgGetInternals(); cfg = unchecked ((uint)(cfg & ~PiGpioNativeMethods.PI_CFG_SIGHANDLER)); short cfgRet = PiGpioNativeMethods.cfgSetInternals(cfg); if (cfgRet < 0) { throw new PiGPIOException(cfgRet); } int ret = PiGpioNativeMethods.Initialise(); if (ret < 0) { throw new PiGPIOException(ret); } }
public int ReadBits_32_53() { return(unchecked ((int)PiGpioNativeMethods.readBits_32_53())); }
public int PigpioVersion() { return(unchecked ((int)PiGpioNativeMethods.Version())); }
public void Dispose() { PiGpioNativeMethods.Terminate(); }
public int HardwareRevision() { return(unchecked ((int)PiGpioNativeMethods.HardwareRevision())); }