From fd95043f62d5f974e90a8e6df080ccba1b750113 Mon Sep 17 00:00:00 2001 From: zhangxy Date: Thu, 19 Mar 2026 15:16:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=8D=87=E6=9C=BA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SLn.Wcs.ElevatorSdk/Class1.cs | 7 - SLn.Wcs.ElevatorSdk/Dto/ElevatorStatus.cs | 36 +++ .../Dto/ElevatorTaskFeedback.cs | 44 ++++ .../Dto/ElevatorTaskRequest.cs | 41 ++++ .../Dto/ElevatorTaskResponse.cs | 35 +++ SLn.Wcs.ElevatorSdk/IElevatorSdk.cs | 32 +++ Sln.Wcs.Common/StringChange.cs | 225 ++++++++++++++++++ 7 files changed, 413 insertions(+), 7 deletions(-) delete mode 100644 SLn.Wcs.ElevatorSdk/Class1.cs create mode 100644 SLn.Wcs.ElevatorSdk/Dto/ElevatorStatus.cs create mode 100644 SLn.Wcs.ElevatorSdk/Dto/ElevatorTaskFeedback.cs create mode 100644 SLn.Wcs.ElevatorSdk/Dto/ElevatorTaskRequest.cs create mode 100644 SLn.Wcs.ElevatorSdk/Dto/ElevatorTaskResponse.cs create mode 100644 SLn.Wcs.ElevatorSdk/IElevatorSdk.cs create mode 100644 Sln.Wcs.Common/StringChange.cs diff --git a/SLn.Wcs.ElevatorSdk/Class1.cs b/SLn.Wcs.ElevatorSdk/Class1.cs deleted file mode 100644 index 9726cae..0000000 --- a/SLn.Wcs.ElevatorSdk/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Sln.Wcs.ElevatorSdk -{ - public class Class1 - { - - } -} diff --git a/SLn.Wcs.ElevatorSdk/Dto/ElevatorStatus.cs b/SLn.Wcs.ElevatorSdk/Dto/ElevatorStatus.cs new file mode 100644 index 0000000..eefc16f --- /dev/null +++ b/SLn.Wcs.ElevatorSdk/Dto/ElevatorStatus.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sln.Wcs.ElevatorSdk.Dto +{ + public class ElevatorStatus + { + /// + /// 提升机编号 + /// + public string ElevatorId { get; set; } + + /// + /// 当前楼层 + /// + public int CurrentFloor { get; set; } + + /// + /// 运行状态(0:空闲,1:运行中,2:故障,3:维护) + /// + public int RunningStatus { get; set; } + + /// + /// 当前任务编号 + /// + public string CurrentTaskId { get; set; } + + /// + /// 是否在线 + /// + public bool IsOnline { get; set; } + } +} diff --git a/SLn.Wcs.ElevatorSdk/Dto/ElevatorTaskFeedback.cs b/SLn.Wcs.ElevatorSdk/Dto/ElevatorTaskFeedback.cs new file mode 100644 index 0000000..c5829f6 --- /dev/null +++ b/SLn.Wcs.ElevatorSdk/Dto/ElevatorTaskFeedback.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sln.Wcs.ElevatorSdk.Dto +{ + /// + /// 提升机任务反馈信息 + /// + public class ElevatorTaskFeedback + { + /// + /// 任务编号 + /// + public string TaskId { get; set; } + + /// + /// 提升机编号 + /// + public string ElevatorId { get; set; } + + /// + /// 任务状态 + /// + public int TaskStatus { get; set; } + + /// + /// 当前楼层 + /// + public int CurrentFloor { get; set; } + + /// + /// 完成时间 + /// + public DateTime? CompleteTime { get; set; } + + /// + /// 错误代码 + /// + public int ErrorCode { get; set; } + } +} diff --git a/SLn.Wcs.ElevatorSdk/Dto/ElevatorTaskRequest.cs b/SLn.Wcs.ElevatorSdk/Dto/ElevatorTaskRequest.cs new file mode 100644 index 0000000..8782282 --- /dev/null +++ b/SLn.Wcs.ElevatorSdk/Dto/ElevatorTaskRequest.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sln.Wcs.ElevatorSdk.Dto +{ + public class ElevatorTaskRequest + { + /// + /// 任务编号 + /// + public string TaskId { get; set; } + + /// + /// 提升机编号 + /// + public string ElevatorId { get; set; } + + /// + /// 起始楼层 + /// + public int FromFloor { get; set; } + + /// + /// 目标楼层 + /// + public int ToFloor { get; set; } + + /// + /// 任务类型 + /// + public int TaskType { get; set; } + + /// + /// 托盘编号 + /// + public string PalletId { get; set; } + } +} diff --git a/SLn.Wcs.ElevatorSdk/Dto/ElevatorTaskResponse.cs b/SLn.Wcs.ElevatorSdk/Dto/ElevatorTaskResponse.cs new file mode 100644 index 0000000..bf5d646 --- /dev/null +++ b/SLn.Wcs.ElevatorSdk/Dto/ElevatorTaskResponse.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sln.Wcs.ElevatorSdk.Dto +{ + /// + /// 提升机任务下发响应结果 + /// + public class ElevatorTaskResponse + { + /// + /// 是否成功 + /// + public bool Success { get; set; } + + /// + /// 响应代码 + /// + public int Code { get; set; } + + /// + /// 响应消息 + /// + public string Message { get; set; } + + /// + /// 任务编号 + /// + public string TaskId { get; set; } + } + +} diff --git a/SLn.Wcs.ElevatorSdk/IElevatorSdk.cs b/SLn.Wcs.ElevatorSdk/IElevatorSdk.cs new file mode 100644 index 0000000..8488e69 --- /dev/null +++ b/SLn.Wcs.ElevatorSdk/IElevatorSdk.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Sln.Wcs.ElevatorSdk.Dto; + +namespace Sln.Wcs.ElevatorSdk +{ + internal interface IElevatorSdk + { + /// + /// 获取所有提升机的实时状态 + /// + /// 提升机状态集合 + Task> GetElevatorStatusListAsync(); + + /// + /// 下发提升机任务 + /// + /// 任务下发请求 + /// 任务下发结果 + Task DispatchTaskAsync(ElevatorTaskRequest request); + + /// + /// 获取提升机任务执行反馈 + /// + /// 任务编号 + /// 任务反馈信息 + Task GetTaskFeedbackAsync(string taskId); + } +} diff --git a/Sln.Wcs.Common/StringChange.cs b/Sln.Wcs.Common/StringChange.cs new file mode 100644 index 0000000..1060768 --- /dev/null +++ b/Sln.Wcs.Common/StringChange.cs @@ -0,0 +1,225 @@ +using System; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; + +#region << 版 本 注 释 >> + +/*-------------------------------------------------------------------- +* 版权所有 (c) 2024 WenJY 保留所有权利。 +* CLR版本:4.0.30319.42000 +* 机器名称:LAPTOP-E0N2L34V +* 命名空间:SlnMesnac.Common +* 唯一标识:496f8d2b-70e3-4a05-ae18-a9b0fcd06b82 +* +* 创建者:WenJY +* 电子邮箱:wenjy@mesnac.com +* 创建时间:2024-03-27 21:58:35 +* 版本:V1.0.0 +* 描述: +* +*-------------------------------------------------------------------- +* 修改人: +* 时间: +* 修改说明: +* +* 版本:V1.0.0 +*--------------------------------------------------------------------*/ + +#endregion << 版 本 注 释 >> + +namespace Sln.Wcs.Common +{ + public class StringChange + { + /// + /// 将字符串强制转换成int,转换失败则返回0 + /// + /// + /// + public int ParseToInt(string str) + { + int returnInt = 0; + if (str == null || str.Trim().Length < 1) + { + return returnInt; + } + if (int.TryParse(str, out returnInt)) + { + return returnInt; + } + else + { + return 0; + } + } + + /// + /// char数组转Array + /// + /// + /// + /// + public string CharArrayToString(char[] cha, int len) + { + string str = ""; + for (int i = 0; i < len; i++) + { + str += string.Format("{0}", cha[i]); + } + + return str; + } + + public string bytesToHexStr(byte[] bytes, int iLen)//e.g. { 0x01, 0x01} ---> " 01 01" + { + string returnStr = ""; + if (bytes != null) + { + for (int i = 0; i < iLen; i++) + { + returnStr += bytes[i].ToString("X2"); + } + } + return returnStr; + } + + public byte[] HexStrTorbytes(string strHex)//e.g. " 01 01" ---> { 0x01, 0x01} + { + strHex = strHex.Replace(" ", ""); + if ((strHex.Length % 2) != 0) + strHex += " "; + byte[] returnBytes = new byte[strHex.Length / 2]; + for (int i = 0; i < returnBytes.Length; i++) + returnBytes[i] = Convert.ToByte(strHex.Substring(i * 2, 2), 16); + return returnBytes; + } + + public string StringToHexString(string s, Encoding encode) + { + byte[] b = encode.GetBytes(s); //按照指定编码将string编程字节数组 + string result = string.Empty; + for (int i = 0; i < b.Length; i++) //逐字节变为16进制字符,以%隔开 + { + result += "%" + Convert.ToString(b[i], 16); + } + return result; + } + + public string HexStringToString(string hs, Encoding encode) + { + //以%分割字符串,并去掉空字符 + string[] chars = hs.Split(new char[] { '%' }, StringSplitOptions.RemoveEmptyEntries); + byte[] b = new byte[chars.Length]; + //逐个字符变为16进制字节数据 + for (int i = 0; i < chars.Length; i++) + { + b[i] = Convert.ToByte(chars[i], 16); + } + //按照指定编码将字节数组变为字符串 + return encode.GetString(b); + } + + public byte[] Swap16Bytes(byte[] OldU16) + { + byte[] ReturnBytes = new byte[2]; + ReturnBytes[1] = OldU16[0]; + ReturnBytes[0] = OldU16[1]; + return ReturnBytes; + } + + /// 64Base码 + /// 保存路径 + /// 文件名称 + /// + public bool Base64ToImage(string strbase64, string path, string filename) + { + bool Flag = false; + try + { + //base64编码的文本 转为 图片 + //图片名称 + byte[] arr = Convert.FromBase64String(strbase64);//将指定的字符串(它将二进制数据编码为 Base64 数字)转换为等效的 8 位无符号整数数组。 + using (MemoryStream ms = new MemoryStream(arr)) + { + Bitmap bmp = new Bitmap(ms);//加载图像 + if (!Directory.Exists(path))//判断保存目录是否存在 + { + Directory.CreateDirectory(path); + } + bmp.Save((path + "\\" + filename + ".png"), System.Drawing.Imaging.ImageFormat.Png);//将图片以JPEG格式保存在指定目录(可以选择其他图片格式) + ms.Close();//关闭流并释放 + if (File.Exists(path + "\\" + filename + ".png"))//判断是否存在 + { + Flag = true; + } + } + } + catch (Exception ex) + { + Console.WriteLine("图片保存失败:" + ex.Message); + } + return Flag; + } + + /// + /// 获取时间戳 + /// + /// + public long GetTimeStamp() + { + TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); + return Convert.ToInt64(ts.TotalSeconds); + } + + public byte[] ConvertFloatToINt(byte[] floatBytes) + { + byte[] intBytes = new byte[floatBytes.Length / 2]; + for (int i = 0; i < intBytes.Length; i++) + { + intBytes[i] = floatBytes[i * 2]; + } + return intBytes; + } + + //CRC异或校验 + public byte CalculateVerify(byte[] pMessage, int iLength) + { + UInt16 i; + byte iVerify = 0; + + iVerify = pMessage[0]; + for (i = 1; i < iLength; i++) + { + iVerify = (byte)(iVerify ^ pMessage[i]); + } + return iVerify; + } + + public int HexStringToNegative(string strNumber) + { + int iNegate = 0; + int iNumber = Convert.ToInt32(strNumber, 16); + if (iNumber > 127) + { + int iComplement = iNumber - 1; + string strNegate = string.Empty; + char[] binchar = Convert.ToString(iComplement, 2).PadLeft(8, '0').ToArray(); + foreach (char ch in binchar) + { + if (Convert.ToInt32(ch) == 48) + { + strNegate += "1"; + } + else + { + strNegate += "0"; + } + } + iNegate = -Convert.ToInt32(strNegate, 2); + } + return iNegate; + } + } +} \ No newline at end of file