| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using OxyPlot;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using TeamAAS_VP.Core.Robots;
- using TeamAAS_VP.Interfaces;
- using TeamAAS_VP.Models;
- namespace TeamAAS_VP.Core.PLCs
- {
- public class PlcService
- {
- private readonly Dictionary<Guid, IPlc> _plcCollection;
- public PlcService()
- {
- _plcCollection = new Dictionary<Guid, IPlc>();
- }
- public bool CreatePlc(Guid id, PlcInfo plcInfo)
- {
- IPlc plc;
- if (plcInfo.CommunicationType == Enums.CommunicationType.OPC_UA_Client)
- {
- plc = new OPCuaClientPLC(plcInfo);
- }
- else if (plcInfo.CommunicationType == Enums.CommunicationType.Mitsubishi_MC)
- {
- plc = new MitsubishiMcPLC(plcInfo);
- }
- else
- {
- return false;
- }
- if (_plcCollection.ContainsKey(id))
- {
- var currenplc = _plcCollection[id];
- currenplc.Dispose();
- }
- _plcCollection[id] = plc;
- return true;
- }
- public Task<bool> CreateRobotAsync(Guid id, PlcInfo plcInfo)
- {
- IPlc plc;
- if (plcInfo.CommunicationType == Enums.CommunicationType.OPC_UA_Client)
- {
- plc = new OPCuaClientPLC(plcInfo);
- }
- else if (plcInfo.CommunicationType == Enums.CommunicationType.Mitsubishi_MC)
- {
- plc = new MitsubishiMcPLC(plcInfo);
- }
- else
- {
- return Task.FromResult(false);
- }
- if (_plcCollection.ContainsKey(id))
- {
- var currenplc = _plcCollection[id];
- currenplc.Dispose();
- }
- _plcCollection[id] = plc;
- return Task.FromResult(true);
- }
- public IPlc GetPlc(Guid id)
- {
- if (!_plcCollection.ContainsKey(id))
- {
- return null;
- }
- return _plcCollection[id];
- }
- public Task<IPlc> GetPlcAsync(Guid id)
- {
- if (!_plcCollection.ContainsKey(id))
- {
- return null;
- }
- return Task.FromResult(_plcCollection[id]);
- }
- public void UnRegisterPlc(Guid id)
- {
- if (_plcCollection.ContainsKey(id))
- {
- var plc = _plcCollection[id];
- plc.Dispose();
- }
- }
- public Task UnRegisterPlcAsync(Guid id)
- {
- if (_plcCollection.ContainsKey(id))
- {
- var plc = _plcCollection[id];
- plc.Dispose();
- }
- return Task.CompletedTask;
- }
- }
- }
|