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.

136 lines
4.7 KiB
C#

#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2026 WenJY
* CLR4.0.30319.42000
* Mr.Wen's MacBook Pro
* Sln.Wcs.HoistSdk
* 6BE2CE90-15BA-43B1-88B0-78853870ECDA
*
* WenJY
*
* 2026-05-06 14:09:47
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
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.Plc.Service;
namespace Sln.Wcs.HoistSdk;
public class HoistSdk:IHoistSdk
{
private readonly HoistConfig hoistConfig;
private readonly List<IPlc> _plcs;
public HoistSdk(HoistConfig hoistConfig, List<IPlc> plcs)
{
this.hoistConfig = hoistConfig;
_plcs = plcs;
}
public HoistControlResultDto HoistControl(HoistControlDto hoistControlDto)
{
HoistControlResultDto result = new HoistControlResultDto();
try
{
var plc = _plcs.Where(x => x.ConfigKey.Equals(hoistControlDto.hoistCode)).ToList().First();
var res = plc.writeInt16ByAddress(hoistConfig.hoist_control_addr, (int)hoistControlDto.action);
if (res)
{
result.code = "0";
result.message = "写入成功";
}
else
{
result.code = "99";
result.message = "写入失败";
}
}
catch (Exception e)
{
result.code = "99";
result.message = e.Message;
}
return result;
}
public HoistTaskExeResultDto HoistTaskExecutor(HoistTaskExeDto hoistTaskExeDto)
{
throw new NotImplementedException();
}
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)
{
transferStationStatus.Add(plc.readInt16ByAddress(item));
}
result.transferStationStatus = transferStationStatus.ToArray();
//读取读写器触发状态
List<int> readerTriggerStatus = new List<int>();
foreach (var item in hoistStatusDto.readerTriggerStatus)
{
readerTriggerStatus.Add(plc.readInt16ByAddress(item));
}
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)
{
result.code = "99";
result.message = e.Message;
}
return result;
}
}