Meadow.Foundation.Sensors.Camera.UsefulSensors.TinyCodeReader
| TinyCodeReader | |
|---|---|
| Status | |
| Source code | GitHub |
| NuGet package |
Code Example
TinyCodeReader tinyCodeReader;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
tinyCodeReader = new TinyCodeReader(Device.CreateI2cBus());
return Task.CompletedTask;
}
public override Task Run()
{
//one time read
var qrCode = tinyCodeReader.ReadCode();
if (qrCode != null)
{
Resolver.Log.Info($"QR Code: {qrCode}");
}
else
{
Resolver.Log.Info("No QR Code Found");
}
//continuous read
tinyCodeReader.CodeRead += TinyCodeReader_CodeRead;
tinyCodeReader.StartUpdating(TimeSpan.FromSeconds(1));
return Task.CompletedTask;
}
private void TinyCodeReader_CodeRead(object sender, string e)
{
Resolver.Log.Info($"QRCode message: {e} ({DateTime.Now})");
}
Sample project(s) available on GitHub
API Reference
Class TinyCodeReader
Represents a Useful Sensor's Tiny Code Reader
Assembly: UsefulSensorsTinyCodeReader.dll
View Source
Declaration
public class TinyCodeReader : II2cPeripheral
Implements:
Meadow.Hardware.II2cPeripheral
Properties
IsRunning
Gets a value indicating whether the sensor is sampling/running
View Source
Declaration
public bool IsRunning { get; }
SamplePeriod
The sample period of the sensor (default 200ms)
View Source
Declaration
public TimeSpan SamplePeriod { get; set; }
DefaultI2cAddress
The default I2C address for the peripheral
View Source
Declaration
public byte DefaultI2cAddress { get; }
Methods
SetLed(bool)
Sets the LED on the Tiny Code Reader
View Source
Declaration
public void SetLed(bool enable)
Parameters
| Type | Name | Description |
|---|---|---|
System.Boolean | enable | enable if true, disable if false |
ReadCode()
Reads the string value of the QR code from the Tiny Code Reader
View Source
Declaration
public string? ReadCode()
Returns
System.String: the code as a string if avaliable, null if no code found
StartUpdating(TimeSpan?)
Start sampling the sensor
View Source
Declaration
public void StartUpdating(TimeSpan? samplePeriod = null)
Parameters
| Type | Name |
|---|---|
System.Nullable<System.TimeSpan> | samplePeriod |
StopUpdating()
Stop sampling the sensor
View Source
Declaration
public void StopUpdating()
Events
CodeRead
Event raised when a QR code is read
View Source
Declaration
public event EventHandler<string> CodeRead
Event Type
System.EventHandler<System.String>
Implements
Meadow.Hardware.II2cPeripheral