public void Read(byte[] buffer) { int sizeTransfered = 0; var result = LibMpsseI2C.I2C_DeviceRead( _handle, _deviceAddress, buffer.Length, buffer, out sizeTransfered, FtI2CTransferOptions.StartBit); CheckResult(result); }
public byte[] Read(int sizeToTransfer) { byte[] buffer = new byte[1]; int sizeTransfered = 0; var result = LibMpsseI2C.I2C_DeviceRead( _handle, _deviceAddress, sizeToTransfer, buffer, out sizeTransfered, FtI2CTransferOptions.StartBit); CheckResult(result); return(buffer); }
public bool SetGPIOOn(byte pin) { if (_handle == IntPtr.Zero) { return(false); } _gpo = (byte)(_gpo | (byte)(1 << pin)); lock (_lock) { var status = LibMpsseI2C.FT_WriteGPIO(_handle, _direction, _gpo); CheckResult(status); } return(true); }
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; }
public bool ReadGPIO(byte pin, out bool value) { if (_handle == IntPtr.Zero) { value = false; return(false); } lock (_lock) { int valTest; var status = LibMpsseI2C.FT_ReadGPIO(_handle, out valTest); var valShift = (valTest >> pin) & 1; value = valShift == 1; CheckResult(status); } return(true); }
//Parts of this code are from http://www.chd.at/sites/default/files/files/FTDI.cs //pin = pin number; dir = 0:=input; 1:=output public bool SetGPIODirection(byte pin, byte dir) { if (_handle == IntPtr.Zero) { return(false); } if (dir == 1) { _direction |= (byte)(1 << pin); } else { _direction &= ((byte)~(1 << pin)); } _gpo &= ((byte)~(1 << pin)); lock (_lock) { var status = LibMpsseI2C.FT_WriteGPIO(_handle, _direction, _gpo); CheckResult(status); } return(true); }
public FtResult Read(byte[] buffer, int sizeToTransfer, out int sizeTransfered, FtI2CTransferOptions options) { //EnforceRightConfiguration(); return(LibMpsseI2C.I2C_DeviceRead(_handle, _deviceAddress, sizeToTransfer, buffer, out sizeTransfered, options)); }
public FtResult Write(byte[] buffer, int sizeToTransfer, out int sizeTransfered, FtI2CTransferOptions options) { return(LibMpsseI2C.I2C_DeviceWrite(_handle, _deviceAddress, sizeToTransfer, buffer, out sizeTransfered, options)); }