#region << 版 本 注 释 >> /*-------------------------------------------------------------------- * 版权所有 (c) 2026 WenJY 保留所有权利。 * CLR版本:4.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 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 List _plcs; public HoistSdk(HoistConfig hoistConfig, List plcs) { _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) { GetHoistStatusResultDto result = new GetHoistStatusResultDto(); try { List paramStr = JsonConvert.DeserializeObject>(_hoistConfig.hoist_plc_param); List deviceParams = paramStr.Where(x => x.hostCode == hoistStatusDto.hoistCode).ToList(); if (string.IsNullOrEmpty(hoistStatusDto.hoistCode)) { deviceParams = paramStr; } if (deviceParams != null && deviceParams.Count > 0) { 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; } } catch (Exception e) { result.code = "99"; result.message = e.Message; } return result; } }