[성현모] DeviceManager, Factory 리팩토링, DIO, Scanner 추가
This commit is contained in:
15
eCIAv2.Library/Devices/DIIO/IDIO.cs
Normal file
15
eCIAv2.Library/Devices/DIIO/IDIO.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using eCIAv2.Library.Config;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace eCIAv2.Library.Devices.DIIO
|
||||
{
|
||||
public interface IDIO : IDevice
|
||||
{
|
||||
public string GetDI();
|
||||
public string SetDO();
|
||||
}
|
||||
}
|
||||
23
eCIAv2.Library/Devices/DIIO/NMF.cs
Normal file
23
eCIAv2.Library/Devices/DIIO/NMF.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace eCIAv2.Library.Devices.DIIO
|
||||
{
|
||||
public class NMF : IDIO
|
||||
{
|
||||
public string DeviceName { get; set; }
|
||||
|
||||
public string GetDI()
|
||||
{
|
||||
return "NMF DI";
|
||||
}
|
||||
|
||||
public string SetDO()
|
||||
{
|
||||
return "NMF DO";
|
||||
}
|
||||
}
|
||||
}
|
||||
24
eCIAv2.Library/Devices/DeviceFactory.cs
Normal file
24
eCIAv2.Library/Devices/DeviceFactory.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace eCIAv2.Library.Devices
|
||||
{
|
||||
public class DeviceFactory
|
||||
{
|
||||
private readonly IServiceProvider _provider;
|
||||
|
||||
public DeviceFactory(IServiceProvider provider)
|
||||
{
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
public T Create<T>()
|
||||
{
|
||||
return _provider.GetRequiredService<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
46
eCIAv2.Library/Devices/DeviceManager.cs
Normal file
46
eCIAv2.Library/Devices/DeviceManager.cs
Normal file
@ -0,0 +1,46 @@
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
13
eCIAv2.Library/Devices/IDevice.cs
Normal file
13
eCIAv2.Library/Devices/IDevice.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace eCIAv2.Library.Devices
|
||||
{
|
||||
public interface IDevice
|
||||
{
|
||||
public string DeviceName { get; set; }
|
||||
}
|
||||
}
|
||||
23
eCIAv2.Library/Devices/Scanner/Cognex.cs
Normal file
23
eCIAv2.Library/Devices/Scanner/Cognex.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace eCIAv2.Library.Devices.Scanner
|
||||
{
|
||||
public class Cognex : IScanner
|
||||
{
|
||||
public string DeviceName { get; set; } = string.Empty;
|
||||
|
||||
public Action<string> OnRecvData()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string Trigger()
|
||||
{
|
||||
return DeviceName;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
eCIAv2.Library/Devices/Scanner/IScanner.cs
Normal file
14
eCIAv2.Library/Devices/Scanner/IScanner.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace eCIAv2.Library.Devices.Scanner
|
||||
{
|
||||
public interface IScanner : IDevice
|
||||
{
|
||||
public string Trigger();
|
||||
public Action<string> OnRecvData();
|
||||
}
|
||||
}
|
||||
23
eCIAv2.Library/Devices/Scanner/Zebra.cs
Normal file
23
eCIAv2.Library/Devices/Scanner/Zebra.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace eCIAv2.Library.Devices.Scanner
|
||||
{
|
||||
public class Zebra : IScanner
|
||||
{
|
||||
public string DeviceName { get; set; } = string.Empty;
|
||||
|
||||
public Action<string> OnRecvData()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string Trigger()
|
||||
{
|
||||
return DeviceName;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user