Remarks
Sc16is762 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
private Sc16is762? expander = null;
private ISerialPort? portA = null;
private ISerialPort? portB = null;
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
var address = Sc16is762.Addresses.Address_0x4D;
try
{
expander = new Sc16is762(
Device.CreateI2cBus(),
new Meadow.Units.Frequency(1.8432, Meadow.Units.Frequency.UnitType.Megahertz),
address);
portA = expander.PortA.CreateSerialPort();
portB = expander.PortB.CreateSerialPort();
}
catch (Exception ex)
{
Resolver.Log.Error($"Failed to initialize 0x{(byte)address:X2}: {ex.Message}");
await Task.Delay(1000);
}
}
public override Task Run()
{
if (expander == null || portA == null || portB == null)
{
return Task.CompletedTask;
}
PollingApp();
while (true)
{
Thread.Sleep(1000);
}
}
private void PollingApp()
{
Task.Run(() =>
{
if (portA != null)
{
_ = PollProc(portA);
}
});
}
private async Task PollProc(ISerialPort port)
{
var readBuffer = new byte[64];
while (true)
{
try
{
Resolver.Log.Info($"Writing");
port.Write(Encoding.ASCII.GetBytes("ping\n"));
Resolver.Log.Info($"Reading");
var count = port.Read(readBuffer, 0, readBuffer.Length);
Resolver.Log.Info($"Read {count} bytes");
Resolver.Log.Info($"{BitConverter.ToString(readBuffer, 0, count)}");
await Task.Delay(5000);
}
catch (Exception ex)
{
Resolver.Log.Error($"Poll error: {ex.Message}");
await Task.Delay(5000);
}
}
}
Sample project(s) available on GitHub
Syntax
public class Sc16is762 : Sc16is7x2, ISerialController, II2cPeripheral, ISpiPeripheral
Constructors
Sc16is762(II2cBus, Frequency, Addresses, IDigitalInterruptPort?)
Initializes a new instance of the Sc16is762 class using an I2C bus, oscillator frequency, an address, and an optional IRQ digital interrupt port.
Declaration
public Sc16is762(II2cBus i2cBus, Frequency oscillatorFrequency, Sc16is7x2.Addresses address = Addresses.Address_0x48, IDigitalInterruptPort? irq = null)
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | The I2C bus for communication. |
Frequency | oscillatorFrequency | The oscillator frequency of the device. |
Sc16is7x2.Addresses | address | The I2C address of the device (default is 0x48). |
IDigitalInterruptPort | irq | An optional digital interrupt port for IRQ (Interrupt Request). |
Remarks
Sc16is762 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
private Sc16is762? expander = null;
private ISerialPort? portA = null;
private ISerialPort? portB = null;
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
var address = Sc16is762.Addresses.Address_0x4D;
try
{
expander = new Sc16is762(
Device.CreateI2cBus(),
new Meadow.Units.Frequency(1.8432, Meadow.Units.Frequency.UnitType.Megahertz),
address);
portA = expander.PortA.CreateSerialPort();
portB = expander.PortB.CreateSerialPort();
}
catch (Exception ex)
{
Resolver.Log.Error($"Failed to initialize 0x{(byte)address:X2}: {ex.Message}");
await Task.Delay(1000);
}
}
public override Task Run()
{
if (expander == null || portA == null || portB == null)
{
return Task.CompletedTask;
}
PollingApp();
while (true)
{
Thread.Sleep(1000);
}
}
private void PollingApp()
{
Task.Run(() =>
{
if (portA != null)
{
_ = PollProc(portA);
}
});
}
private async Task PollProc(ISerialPort port)
{
var readBuffer = new byte[64];
while (true)
{
try
{
Resolver.Log.Info($"Writing");
port.Write(Encoding.ASCII.GetBytes("ping\n"));
Resolver.Log.Info($"Reading");
var count = port.Read(readBuffer, 0, readBuffer.Length);
Resolver.Log.Info($"Read {count} bytes");
Resolver.Log.Info($"{BitConverter.ToString(readBuffer, 0, count)}");
await Task.Delay(5000);
}
catch (Exception ex)
{
Resolver.Log.Error($"Poll error: {ex.Message}");
await Task.Delay(5000);
}
}
}
Sc16is762(ISpiBus, Frequency, IDigitalOutputPort?, IDigitalInterruptPort?)
Initializes a new instance of the Sc16is762 class using an SPI bus, oscillator frequency, an optional chip select digital output port, and an optional IRQ digital interrupt port.
Declaration
public Sc16is762(ISpiBus spiBus, Frequency oscillatorFrequency, IDigitalOutputPort? chipSelect = null, IDigitalInterruptPort? irq = null)
Parameters
Type | Name | Description |
---|---|---|
ISpiBus | spiBus | The SPI bus for communication. |
Frequency | oscillatorFrequency | The oscillator frequency of the device. |
IDigitalOutputPort | chipSelect | An optional digital output port for chip select (CS). |
IDigitalInterruptPort | irq | An optional digital interrupt port for IRQ (Interrupt Request). |
Remarks
Sc16is762 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
private Sc16is762? expander = null;
private ISerialPort? portA = null;
private ISerialPort? portB = null;
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
var address = Sc16is762.Addresses.Address_0x4D;
try
{
expander = new Sc16is762(
Device.CreateI2cBus(),
new Meadow.Units.Frequency(1.8432, Meadow.Units.Frequency.UnitType.Megahertz),
address);
portA = expander.PortA.CreateSerialPort();
portB = expander.PortB.CreateSerialPort();
}
catch (Exception ex)
{
Resolver.Log.Error($"Failed to initialize 0x{(byte)address:X2}: {ex.Message}");
await Task.Delay(1000);
}
}
public override Task Run()
{
if (expander == null || portA == null || portB == null)
{
return Task.CompletedTask;
}
PollingApp();
while (true)
{
Thread.Sleep(1000);
}
}
private void PollingApp()
{
Task.Run(() =>
{
if (portA != null)
{
_ = PollProc(portA);
}
});
}
private async Task PollProc(ISerialPort port)
{
var readBuffer = new byte[64];
while (true)
{
try
{
Resolver.Log.Info($"Writing");
port.Write(Encoding.ASCII.GetBytes("ping\n"));
Resolver.Log.Info($"Reading");
var count = port.Read(readBuffer, 0, readBuffer.Length);
Resolver.Log.Info($"Read {count} bytes");
Resolver.Log.Info($"{BitConverter.ToString(readBuffer, 0, count)}");
await Task.Delay(5000);
}
catch (Exception ex)
{
Resolver.Log.Error($"Poll error: {ex.Message}");
await Task.Delay(5000);
}
}
}
Sc16is762(Frequency, IDigitalInterruptPort?)
Initializes a new instance of the Sc16is762 class using an oscillator frequency and an optional IRQ digital interrupt port.
Declaration
public Sc16is762(Frequency oscillatorFrequency, IDigitalInterruptPort? irq)
Parameters
Type | Name | Description |
---|---|---|
Frequency | oscillatorFrequency | The oscillator frequency of the device. |
IDigitalInterruptPort | irq | An optional digital interrupt port for IRQ (Interrupt Request). |
Remarks
Sc16is762 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
Code Example
private Sc16is762? expander = null;
private ISerialPort? portA = null;
private ISerialPort? portB = null;
public override async Task Initialize()
{
Resolver.Log.Info("Initialize...");
var address = Sc16is762.Addresses.Address_0x4D;
try
{
expander = new Sc16is762(
Device.CreateI2cBus(),
new Meadow.Units.Frequency(1.8432, Meadow.Units.Frequency.UnitType.Megahertz),
address);
portA = expander.PortA.CreateSerialPort();
portB = expander.PortB.CreateSerialPort();
}
catch (Exception ex)
{
Resolver.Log.Error($"Failed to initialize 0x{(byte)address:X2}: {ex.Message}");
await Task.Delay(1000);
}
}
public override Task Run()
{
if (expander == null || portA == null || portB == null)
{
return Task.CompletedTask;
}
PollingApp();
while (true)
{
Thread.Sleep(1000);
}
}
private void PollingApp()
{
Task.Run(() =>
{
if (portA != null)
{
_ = PollProc(portA);
}
});
}
private async Task PollProc(ISerialPort port)
{
var readBuffer = new byte[64];
while (true)
{
try
{
Resolver.Log.Info($"Writing");
port.Write(Encoding.ASCII.GetBytes("ping\n"));
Resolver.Log.Info($"Reading");
var count = port.Read(readBuffer, 0, readBuffer.Length);
Resolver.Log.Info($"Read {count} bytes");
Resolver.Log.Info($"{BitConverter.ToString(readBuffer, 0, count)}");
await Task.Delay(5000);
}
catch (Exception ex)
{
Resolver.Log.Error($"Poll error: {ex.Message}");
await Task.Delay(5000);
}
}
}