public async Task<bool> Init() { var config = new FtChannelConfig { ClockRate = ConnectionSpeed, LatencyTimer = LatencyTimer }; _i2cConfig = _i2cConfig ?? I2CConfiguration.ChannelZeroConfiguration; _cfg = config; InitLibAndHandle(); return true; }
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; }
protected SpiDevice(FtChannelConfig config, SpiConfiguration spiConfig) { _spiConfig = spiConfig ?? SpiConfiguration.ChannelZeroConfiguration; _cfg = config; InitLibAndHandle(); }
protected SpiDevice(FtChannelConfig config) : this(config, null) { }
private void EnforceRightConfiguration() { if (_currentGlobalConfig.configOptions != _cfg.configOptions) { LibMpsseSpi.SPI_ChangeCS(_handle, _cfg.configOptions); _currentGlobalConfig = _cfg; } }
public static extern FtResult I2C_InitChannel(System.IntPtr handle, ref FtChannelConfig config);
public extern static FtResult SPI_InitChannel(IntPtr handle, ref FtChannelConfig config);
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; }