|
|
|
|
@ -23,23 +23,25 @@
|
|
|
|
|
|
|
|
|
|
#endregion << 版 本 注 释 >>
|
|
|
|
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Sln.Wcs.HoistSdk.Config;
|
|
|
|
|
using Sln.Wcs.HoistSdk.Dto.GetHoistStatus;
|
|
|
|
|
using Sln.Wcs.HoistSdk.Dto.HoistControl;
|
|
|
|
|
using Sln.Wcs.HoistSdk.Dto.HoistTaskExecutor;
|
|
|
|
|
using Sln.Wcs.Model.Configs;
|
|
|
|
|
using Sln.Wcs.Plc.Service;
|
|
|
|
|
|
|
|
|
|
namespace Sln.Wcs.HoistSdk;
|
|
|
|
|
|
|
|
|
|
public class HoistSdk:IHoistSdk
|
|
|
|
|
{
|
|
|
|
|
private readonly HoistConfig hoistConfig;
|
|
|
|
|
private readonly HoistConfig _hoistConfig;
|
|
|
|
|
|
|
|
|
|
private readonly List<IPlc> _plcs;
|
|
|
|
|
|
|
|
|
|
public HoistSdk(HoistConfig hoistConfig, List<IPlc> plcs)
|
|
|
|
|
{
|
|
|
|
|
this.hoistConfig = hoistConfig;
|
|
|
|
|
_hoistConfig = hoistConfig;
|
|
|
|
|
_plcs = plcs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -49,7 +51,7 @@ public class HoistSdk:IHoistSdk
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var plc = _plcs.Where(x => x.ConfigKey.Equals(hoistControlDto.hoistCode)).ToList().First();
|
|
|
|
|
var res = plc.writeInt16ByAddress(hoistConfig.hoist_control_addr, (int)hoistControlDto.action);
|
|
|
|
|
var res = plc.writeInt16ByAddress(_hoistConfig.hoist_control_addr, (int)hoistControlDto.action);
|
|
|
|
|
if (res)
|
|
|
|
|
{
|
|
|
|
|
result.code = "0";
|
|
|
|
|
@ -76,55 +78,58 @@ public class HoistSdk:IHoistSdk
|
|
|
|
|
|
|
|
|
|
public GetHoistStatusResultDto GetHoistStatus(GetHoistStatusDto hoistStatusDto)
|
|
|
|
|
{
|
|
|
|
|
//一号提升机
|
|
|
|
|
//反馈任务执行指令:是否可以下发任务
|
|
|
|
|
//当前楼层
|
|
|
|
|
//接驳位状态:1-5楼
|
|
|
|
|
//读写器触发状态:1-5楼
|
|
|
|
|
//自动状态:true/1-自动模式
|
|
|
|
|
//屏蔽调度:true/1-屏蔽中
|
|
|
|
|
//状态指示:0-静态;1-上升;2-下降;3-进料;4-出料
|
|
|
|
|
|
|
|
|
|
GetHoistStatusResultDto result = new GetHoistStatusResultDto();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var plc = _plcs.Where(x => x.ConfigKey.Equals(hoistStatusDto.hoistCode)).ToList().First();
|
|
|
|
|
|
|
|
|
|
result.hoistCode = hoistStatusDto.hoistCode;
|
|
|
|
|
result.canDispatchTask = plc.readInt16ByAddress(hoistStatusDto.canDispatchTask);
|
|
|
|
|
result.currentFloor = plc.readInt16ByAddress(hoistStatusDto.currentFloor);
|
|
|
|
|
|
|
|
|
|
//读取接驳位状态
|
|
|
|
|
List<int> transferStationStatus = new List<int>();
|
|
|
|
|
foreach (var item in hoistStatusDto.transferStationStatus)
|
|
|
|
|
List<dynamic> paramStr = JsonConvert.DeserializeObject<List<dynamic>>(_hoistConfig.hoist_plc_param);
|
|
|
|
|
|
|
|
|
|
List<dynamic> deviceParams = paramStr.Where(x => x.hostCode == hoistStatusDto.hoistCode).ToList();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(hoistStatusDto.hoistCode))
|
|
|
|
|
{
|
|
|
|
|
transferStationStatus.Add(plc.readInt16ByAddress(item));
|
|
|
|
|
deviceParams = paramStr;
|
|
|
|
|
}
|
|
|
|
|
result.transferStationStatus = transferStationStatus.ToArray();
|
|
|
|
|
|
|
|
|
|
//读取读写器触发状态
|
|
|
|
|
List<int> readerTriggerStatus = new List<int>();
|
|
|
|
|
foreach (var item in hoistStatusDto.readerTriggerStatus)
|
|
|
|
|
if (deviceParams != null && deviceParams.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
readerTriggerStatus.Add(plc.readInt16ByAddress(item));
|
|
|
|
|
foreach (var item in deviceParams)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (item.hostCode == hoistStatusDto.hoistCode)
|
|
|
|
|
{
|
|
|
|
|
// var plc = _plcs.Where(x => x.ConfigKey.Equals(item.hostCode)).FirstOrDefault();
|
|
|
|
|
// if (plc == null)
|
|
|
|
|
// {
|
|
|
|
|
// result.code = "99";
|
|
|
|
|
// result.message = $"未找到PLC: {item.hostCode}";
|
|
|
|
|
// result.hoistCode = hoistStatusDto.hoistCode;
|
|
|
|
|
// return result;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
foreach (var param in item.deviceParams)
|
|
|
|
|
{
|
|
|
|
|
//int value = plc.readInt16ByAddress(param.paramAddress);
|
|
|
|
|
|
|
|
|
|
param.paramValue = param.objId;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string jsonOutput = JsonConvert.SerializeObject(deviceParams, Formatting.Indented);
|
|
|
|
|
|
|
|
|
|
result.code = "0";
|
|
|
|
|
result.message = "状态更新成功";
|
|
|
|
|
result.hoistCode = hoistStatusDto.hoistCode;
|
|
|
|
|
result.deviceParamStr = jsonOutput;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.code = "99";
|
|
|
|
|
result.message = $"未获取到设备参数:{hoistStatusDto.hoistCode}";
|
|
|
|
|
result.hoistCode = hoistStatusDto.hoistCode;
|
|
|
|
|
}
|
|
|
|
|
result.readerTriggerStatus = readerTriggerStatus.ToArray();
|
|
|
|
|
|
|
|
|
|
result.isAutoMode = plc.readInt16ByAddress(hoistStatusDto.isAutoMode);
|
|
|
|
|
result.isDispatchBlocked = plc.readInt16ByAddress(hoistStatusDto.isDispatchBlocked);
|
|
|
|
|
result.stateIndicator = plc.readInt16ByAddress(hoistStatusDto.stateIndicator);
|
|
|
|
|
|
|
|
|
|
// hoistStatusDto.hoistCode = "";
|
|
|
|
|
// hoistStatusDto.canDispatchTask = "D3101";
|
|
|
|
|
// hoistStatusDto.currentFloor = "D3102";
|
|
|
|
|
// hoistStatusDto.transferStationStatus = new List<string>(){"D3104","D3105","D3106","D3107","D3108"};
|
|
|
|
|
// hoistStatusDto.readerTriggerStatus = new List<string>(){"D3109","D3110","D3111","D3112","D3113"};
|
|
|
|
|
// hoistStatusDto.isAutoMode = "D3124";
|
|
|
|
|
// hoistStatusDto.isDispatchBlocked = "D3125";
|
|
|
|
|
// hoistStatusDto.stateIndicator = "D3127";
|
|
|
|
|
|
|
|
|
|
result.code = "0";
|
|
|
|
|
result.message = "状态更新成功";
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
@ -133,4 +138,5 @@ public class HoistSdk:IHoistSdk
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|