/// <summary>Executes the command.</summary> /// <returns>The command's exit code.</returns> /// <remarks> /// NOTE: This test app uses the base class's <see cref="CreateI2cDevice"/> method to create a device.<br/> /// Real-world usage would simply create an instance of an <see cref="I2cDevice"/> implementation: /// <code>using (var i2cDevice = new UnixI2cDevice(connectionSettings))</code> /// </remarks> public int Execute() { if (FirstRegister == null) { Console.WriteLine($"Device={Device}, BusId={BusId}, DeviceAddress={DeviceAddress} (0x{DeviceAddress:X2}), ByteCount={ByteCount}"); } else { Console.WriteLine($"Device={Device}, BusId={BusId}, DeviceAddress={DeviceAddress} (0x{DeviceAddress:X2}), FirstRegister={ FirstRegister} (0x{FirstRegister:X2}), ByteCount={ByteCount}"); } var connectionSettings = new I2cConnectionSettings(BusId, DeviceAddress); using (var i2cDevice = CreateI2cDevice(connectionSettings)) { // Set to first address if needed. if (FirstRegister != null) { i2cDevice.WriteByte((byte)FirstRegister); } // Read bytes of data. var buffer = new byte[ByteCount]; i2cDevice.Read(buffer.AsSpan()); Console.WriteLine($"Bytes Read:{Environment.NewLine}{HexStringUtilities.FormatByteData(buffer)}"); } return(0); }
/// <summary>Executes the command.</summary> /// <returns>The command's exit code.</returns> /// <remarks> /// NOTE: This test app uses the base class's <see cref="CreateI2cDevice"/> method to create a device.<br/> /// Real-world usage would simply create an instance of an <see cref="I2cDevice"/> implementation: /// <code>using (var i2c = new UnixI2cDevice(connectionSettings))</code> /// </remarks> public int Execute() { Console.WriteLine($"ByteCount={ByteCount}, BusId={BusId}, DeviceAddress={DeviceAddress}, Device={Device}"); var connectionSettings = new I2cConnectionSettings(BusId, DeviceAddress); using (var i2c = CreateI2cDevice(connectionSettings)) { // Read bytes of data var buffer = new byte[ByteCount]; i2c.Read(buffer.AsSpan()); Console.WriteLine($"Bytes read:{Environment.NewLine}{HexStringUtilities.FormatByteData(buffer)}"); } return(0); }
/// <summary>Executes the command.</summary> /// <returns>The command's exit code.</returns> /// <remarks> /// NOTE: This test app uses the base class's <see cref="CreateI2cDevice"/> method to create a device.<br/> /// Real-world usage would simply create an instance of an <see cref="I2cDevice"/> implementation: /// <code>using (var i2cDevice = new UnixI2cDevice(connectionSettings))</code> /// </remarks> public int Execute() { Console.WriteLine($"Device={Device}, BusId={BusId}, DeviceAddress={DeviceAddress} (0x{DeviceAddress:X2}), ByteCount={ByteCount}"); var connectionSettings = new I2cConnectionSettings(BusId, DeviceAddress); using (var i2cDevice = CreateI2cDevice(connectionSettings)) { // Write random bytes of data var buffer = new byte[ByteCount]; new Random().NextBytes(buffer); Console.WriteLine($"Writing Random Bytes:{Environment.NewLine}{HexStringUtilities.FormatByteData(buffer)}"); i2cDevice.Write(buffer.AsSpan()); } return(0); }
/// <summary>Executes the command.</summary> /// <returns>The command's exit code.</returns> /// <remarks> /// NOTE: This test app uses the base class's <see cref="CreateSpiDevice"/> method to create a device.<br/> /// Real-world usage would simply create an instance of a <see cref="SpiDevice"/> implementation: /// <code>using (var spi = new UnixSpiDevice(connectionSettings))</code> /// </remarks> public int Execute() { Console.WriteLine($"ByteCount={ByteCount}, BusId={BusId}, ChipSelectLine={ChipSelectLine}, Mode={Mode}, DataBitLength={DataBitLength}, ClockFrequency={ClockFrequency}, Device={Device}"); var connectionSettings = new SpiConnectionSettings(BusId, ChipSelectLine) { ClockFrequency = ClockFrequency, DataBitLength = DataBitLength, Mode = Mode, }; using (var spiDevice = CreateSpiDevice(connectionSettings)) { // Read bytes of data var buffer = new byte[ByteCount]; spiDevice.Read(buffer.AsSpan()); Console.WriteLine($"Bytes read:{Environment.NewLine}{HexStringUtilities.FormatByteData(buffer)}"); } return(0); }