You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.6 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Sln.Wcs.ElevatorSdk.Dto;
using Sln.Wcs.Plc;
namespace Sln.Wcs.ElevatorSdk
{
public class ElevatorSdk : IElevatorSdk
{
private readonly IServiceProvider _service;
public List<PlcAbsractFactory> plcList;
public ElevatorSdk(IServiceProvider services)
{
_service = services;
plcList = _service.GetRequiredService<List<PlcAbsractFactory>>();
}
public async Task<ElevatorInfo> DispatchTaskAsync(ElevatorInfo request)
{
var response = new ElevatorInfo();
var plc = plcList.Where(e => e.ConfigKey == request.plcKey).FirstOrDefault();
if (plc != null && plc.IsConnected)
{
plc.writeStringByAddress("提升机当前任务ID", request.CurrentTaskId);
plc.writeStringByAddress("当前流程ID", request.CurrentTaskId);
plc.writeInt16ByAddress("提升机起始楼层", request.FromFloor);
plc.writeInt16ByAddress("提升机终点楼层", request.ToFloor);
plc.writeInt16ByAddress("任务类型", request.TaskType);
plc.writeBoolByAddress("开始任务", true);
response.TaskId = request.TaskId;
response.FromFloor = request.FromFloor;
response.ToFloor = request.ToFloor;
response.TaskType = request.TaskType;
if (plc.readInt16ByAddress("任务当前状态") == 1)
{
response.TaskStatus = 1;
}
else
{
response.TaskStatus = 0;
}
}
return response;
}
public async Task<List<ElevatorInfo>> GetElevatorStatusListAsync()
{
var infoList = new List<ElevatorInfo>();
if (plcList != null)
{
foreach (var plc in plcList)
{
var info = new ElevatorInfo();
info.ElevatorId = plc.readStringByAddress("提升机ID", 10);
info.CurrentTaskId = plc.readStringByAddress("提升机当前任务ID", 10);
info.CurrentFloor = plc.readInt16ByAddress("提升机当前楼层");
info.RunningStatus = plc.readInt16ByAddress("提升机运行状态");
info.TaskId = plc.readStringByAddress("当前流程ID", 10);
info.TaskStatus = plc.readInt16ByAddress("任务当前状态");
info.TaskType = plc.readInt16ByAddress("任务类型");
infoList.Add(info);
}
}
else {
throw new Exception("PLC列表为空");
}
return infoList;
}
public async Task<ElevatorInfo> GetTaskFeedbackAsync(ElevatorInfo request)
{
var response = new ElevatorInfo();
var plc = plcList.Where(e => e.ConfigKey == request.plcKey).FirstOrDefault();
if (plc != null)
{
response.TaskId = plc.readStringByAddress("当前流程ID", 10);
response.FromFloor = plc.readInt16ByAddress("提升机起始楼层");
response.ToFloor = plc.readInt16ByAddress("提升机终点楼层");
response.TaskType = plc.readInt16ByAddress("任务类型");
response.TaskStatus = plc.readInt16ByAddress("任务当前状态");
}
return response;
}
}
}