private void InitLibAndHandle() { FtResult result; if (_handle != IntPtr.Zero) { return; } LibMpsse.Init(); result = LibMpsseSpi.SPI_OpenChannel(_spiConfig.ChannelIndex, out _handle); CheckResult(result); if (_handle == IntPtr.Zero) { throw new SpiChannelNotConnectedException(FtResult.InvalidHandle); } result = LibMpsseSpi.SPI_InitChannel(_handle, ref _cfg); CheckResult(result); _currentGlobalConfig = _cfg; }
public void Dispose() { if (_isDisposed) return; _isDisposed = true; LibMpsse.Cleanup(); }
void InitLibAndHandle() { FtResult result; if (_handle != IntPtr.Zero) { return; } LibMpsse.Init(); var num_channels = 0; var channels = LibMpsseI2C.I2C_GetNumChannels(out num_channels); CheckResult(channels); //if (num_channels > 0) //{ // for (var i = 0; i < num_channels; i++) // { // FtDeviceInfo cInfo; // var channelInfoStatus = LibMpsseI2C.I2C_GetChannelInfo(i, out cInfo); // CheckResult(channelInfoStatus); // Debug.WriteLine($"Flags: {cInfo.Flags}"); // Debug.WriteLine($"Type: {cInfo.Type}"); // Debug.WriteLine($"ID: {cInfo.ID}"); // Debug.WriteLine($"LocId: {cInfo.LocId}"); // Debug.WriteLine($"SerialNumber: {cInfo.SerialNumber}"); // Debug.WriteLine($"Description: {cInfo.Description}"); // Debug.WriteLine($"ftHandle: {cInfo.ftHandle}"); // } //} result = LibMpsseI2C.I2C_OpenChannel(_i2cConfig.ChannelIndex, out _handle); CheckResult(result); if (_handle == IntPtr.Zero) { throw new I2CChannelNotConnectedException(FtResult.InvalidHandle); } result = LibMpsseI2C.I2C_InitChannel(_handle, ref _cfg); CheckResult(result); _currentGlobalConfig = _cfg; }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects). } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. LibMpsse.Cleanup(); disposedValue = true; } }
public void SetPinMode(int pin, PinMode mode) { if (mode == PinMode.Output) { Directions |= PowerOf2[pin]; } else { Directions &= ~PowerOf2[pin]; } var result = LibMpsse.FT_WriteGPIO(_i2cHandle, (short)Directions, (short)Values); if (result != FtdiMpsseI2CResult.Ok) { throw new GpioException(result, nameof(SetPinMode)); } }
public void DigitalWrite(int pin, PinState state) { if (state == PinState.High) { this.Values |= PowerOf2[pin]; } else { Values &= ~PowerOf2[pin]; } var result = LibMpsse.FT_WriteGPIO(_i2cHandle, (short)Directions, (short)Values); if (result != FtdiMpsseI2CResult.Ok) { if (Debugger.IsAttached) { Debugger.Break(); } throw new GpioException(result, nameof(DigitalWrite)); } }
protected void InitLibAndHandle(int channelIndex) { if (_i2cHandle != IntPtr.Zero) { return; } LibMpsse.Init(); var config = Config; var result = CheckResult(LibMpsse.I2C_OpenChannel(channelIndex, out _i2cHandle)); if (_i2cHandle == IntPtr.Zero) { throw new I2CNotConnectedException(FtdiMpsseI2CResult.InvalidAddress); } result = CheckResult(LibMpsse.I2C_InitChannel(_i2cHandle, ref config)); Config = config; }
protected FtdiMpsseI2CResult WriteGPIOMask(byte directions, byte values) { Values = values; Directions = directions; return(LibMpsse.FT_WriteGPIO(_i2cHandle, directions, values)); }
protected FtdiMpsseI2CResult WriteGPIOMask(byte values) { return(LibMpsse.FT_WriteGPIO(_i2cHandle, 0, values)); }
public FtdiMpsseI2CResult Write(byte deviceAddress, byte[] buffer, int sizeToTransfer, out int sizeTransfered, FtI2CTransferOptions options = FtI2CTransferOptions.I2C_TRANSFER_OPTIONS_START_BIT | FtI2CTransferOptions.I2C_TRANSFER_OPTIONS_STOP_BIT | FtI2CTransferOptions.I2C_TRANSFER_OPTIONS_BREAK_ON_NACK | FtI2CTransferOptions.I2C_TRANSFER_OPTIONS_FAST_TRANSFER_BYTES) { return(CheckResult(LibMpsse.I2C_DeviceWrite(_i2cHandle, deviceAddress, sizeToTransfer, buffer, out sizeTransfered, (int)options))); }