Files
WMS/HHWMS.Web/Support/PLC/PlcFactory.cs
T

33 lines
909 B
C#

using System;
using Microsoft.Extensions.Logging;
namespace HHWMS.Web.Support.PLC
{
public enum PlcType
{
Siemens,
Modbus,
Mitsubishi
}
public class PlcFactory
{
private readonly ILoggerFactory _loggerFactory;
public PlcFactory(ILoggerFactory loggerFactory)
{
_loggerFactory = loggerFactory;
}
public IPlcDevice CreatePlc(PlcType plcType)
{
return plcType switch
{
PlcType.Siemens => new SiemensPlc(_loggerFactory.CreateLogger<SiemensPlc>()),
PlcType.Modbus => new ModbusPlc(_loggerFactory.CreateLogger<ModbusPlc>()),
PlcType.Mitsubishi => new MitsubishiPlc(_loggerFactory.CreateLogger<MitsubishiPlc>()),
_ => throw new ArgumentException("不支持的PLC类型", nameof(plcType))
};
}
}
}