Remarks

Sc16is762
Status Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.ICs.IOExpanders.Sc16is7x2

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

Characteristic Locus
Inheritance object Sc16is7x2 > Sc16is762
Implements ISerialController II2cPeripheral ISpiPeripheral
Inherited Members Sc16is7x2.PortA Sc16is7x2.PortB Sc16is7x2.CreateSerialPort(SerialPortName, int, int, Parity, StopBits, int) Sc16is7x2.CreateRs485SerialPort(Sc16is7x2.Sc16SerialPortName, int, int, Parity, StopBits, bool) Sc16is7x2.DefaultI2cAddress Sc16is7x2.MaxI2cBusSpeed Sc16is7x2.DefaultSpiBusMode Sc16is7x2.DefaultSpiBusSpeed Sc16is7x2.SpiBusMode Sc16is7x2.SpiBusSpeed object.Equals(object) object.Equals(object, object) object.GetHashCode() object.GetType() object.MemberwiseClone() object.ReferenceEquals(object, object) object.ToString()
Namespace Meadow.Foundation.ICs.IOExpanders
Assembly Sc16is7x2.dll

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 Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.ICs.IOExpanders.Sc16is7x2

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

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 Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.ICs.IOExpanders.Sc16is7x2

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

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 Status badge: working
Source code GitHub
Datasheet(s) GitHub
NuGet package NuGet Gallery for Meadow.Foundation.ICs.IOExpanders.Sc16is7x2

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