47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using eCIAv2.Library.Config;
|
|
using eCIAv2.Library.Devices.DIIO;
|
|
using eCIAv2.Library.Devices.Scanner;
|
|
using eCIAv2.Library.Services;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace eCIAv2.Library.Devices
|
|
{
|
|
public class DeviceManager
|
|
{
|
|
private readonly Dictionary<string, IDevice> _devices = new();
|
|
|
|
public DeviceManager(DeviceFactory factory, ConfigService config)
|
|
{
|
|
foreach (var dicConfig in config.GetConfig().Configs)
|
|
{
|
|
//scanner
|
|
foreach(var device in dicConfig.Value.Device.Scanners)
|
|
{
|
|
var scanner = factory.Create<IScanner>();
|
|
scanner.DeviceName = device.Name;
|
|
|
|
_devices.Add(device.Name, scanner);
|
|
}
|
|
|
|
//dio
|
|
foreach (var device in dicConfig.Value.Device.DIOs)
|
|
{
|
|
var dio = factory.Create<IDIO>();
|
|
dio.DeviceName = device.Name;
|
|
|
|
_devices.Add(device.Name, dio);
|
|
}
|
|
}
|
|
}
|
|
|
|
public T GetDevice<T>(string name) where T : IDevice
|
|
{
|
|
return (T)_devices[name];
|
|
}
|
|
}
|
|
}
|