林豪 左 2 жил өмнө
parent
commit
ede69122fa

+ 2 - 5
WCS.Core/DataTrans/DataBlock.cs

@@ -64,7 +64,8 @@ namespace WCS.Core.DataTrans
                 lock (Entity.PLC)
                 {
                     sw.Start();
-                    data = Entity.PLC.Ex().Accessor.ReadBytes((ushort)Entity.NO, 0, (ushort)Entity.LENGTH, (ushort)Entity.DATALENGTH);
+                    //data = Entity.PLC.Ex().Accessor.ReadBytes((ushort)Entity.NO, 0, (ushort)Entity.LENGTH, (ushort)Entity.DATALENGTH);
+                    data = Entity.PLC.Ex().Accessor.ReadBytes((ushort)Entity.NO, 0, (ushort)Entity.LENGTH);
                     sw.Stop();
                 }
 
@@ -274,10 +275,6 @@ namespace WCS.Core.DataTrans
             var data = ReadBytes(ref bitStart, size);
             if (reverse)
                 data = data.Reverse().ToArray();
-            if (Entity.CODE == "SRM2_521" && type == typeof(short))
-            {
-                var c = 1;
-            }
             if (type == typeof(byte))
             {
                 return data.First();

+ 2 - 2
WCS.Core/DataTrans/Extentions.cs

@@ -528,9 +528,9 @@ namespace WCS.Core.DataTrans
             return GetEx<DataBlock>(source);
         }
 
-        public static PlcAccessor Ex(this WCS_PLC source)
+        public static PLCAccessor Ex(this WCS_PLC source)
         {
-            return GetEx<PlcAccessor>(source);
+            return GetEx<PLCAccessor>(source);
         }
 
         public static WCS_DEVICEPROTOCOL PROTOCOL(this IProtocol obj)

+ 33 - 11
WCS.Core/DataTrans/IPLCAccessor.cs

@@ -1,28 +1,50 @@
-using HslCommunication.Core;
-using WCS.Entity;
+using WCS.Entity;
 
 namespace WCS.Core.DataTrans
 {
-    public interface IPlcAccessorCreater
+    //public interface IPlcAccessorCreater
+    //{
+    //    IReadWriteNet Create(WCS_PLC data);
+    //}
+
+    //public interface IPlcAccessor : IReadWriteNet
+    //{
+    //    void WriteBytes(ushort db, ushort address, byte[] data);
+
+    //    byte[] ReadBytes(ushort db, ushort address, ushort length, ushort dataLength);
+    //}
+
+    //public class PlcAccessor : EntityEx<WCS_PLC>
+    //{
+    //    public static IPlcAccessorCreater Creater;
+    //    public IPlcAccessor Accessor { get; private set; }
+
+    //    public PlcAccessor(WCS_PLC entity) : base(entity)
+    //    {
+    //        Accessor = (IPlcAccessor)Creater.Create(entity);
+    //    }
+    //}
+
+    public interface IPLCAccessorCreater
     {
-        IReadWriteNet Create(WCS_PLC data);
+        IPLCAccessor Create(WCS_PLC data);
     }
 
-    public interface IPlcAccessor : IReadWriteNet
+    public interface IPLCAccessor
     {
         void WriteBytes(ushort db, ushort address, byte[] data);
 
-        byte[] ReadBytes(ushort db, ushort address, ushort length, ushort dataLength);
+        byte[] ReadBytes(ushort db, ushort address, ushort length);
     }
 
-    public class PlcAccessor : EntityEx<WCS_PLC>
+    public class PLCAccessor : EntityEx<WCS_PLC>
     {
-        public static IPlcAccessorCreater Creater;
-        public IPlcAccessor Accessor { get; private set; }
+        public static IPLCAccessorCreater Creater;
+        public IPLCAccessor Accessor { get; private set; }
 
-        public PlcAccessor(WCS_PLC entity) : base(entity)
+        public PLCAccessor(WCS_PLC entity) : base(entity)
         {
-            Accessor = (IPlcAccessor)Creater.Create(entity);
+            Accessor = Creater.Create(entity);
         }
     }
 }

+ 2 - 2
WCS.Core/IL/Generator.cs

@@ -3,7 +3,7 @@ using System.Linq;
 using System.Reflection;
 using System.Reflection.Emit;
 
-namespace WCS.Core.IL
+namespace WCS.Core
 {
     /// <summary>
     /// 动态创建接口实例
@@ -37,7 +37,7 @@ namespace WCS.Core.IL
             {
                 Type = tb.CreateTypeInfo().AsType();//.CreateType();
             }
-            catch (Exception)
+            catch (Exception ex)
             {
             }
             //myAssembly.Save(typeof(T).Name + ".dll");

+ 1 - 1
WCS.Core/IL/IProtocolProxy.cs

@@ -1,6 +1,6 @@
 using System;
 
-namespace WCS.Core.IL
+namespace WCS.Core
 {
     public interface IProtocolProxy
     {

+ 23 - 10
WCS.Service/PLCAccessors/PLCAccessorsCreater.cs

@@ -5,18 +5,31 @@ using WCS.Entity;
 
 namespace WCS.Service.PLCAccessors
 {
-    public class PlcAccessorsCreater : IPlcAccessorCreater
+    public class PlcAccessorsCreater : IPLCAccessorCreater
     {
-        public IReadWriteNet Create(WCS_PLC data)
+        //public IReadWriteNet Create(WCS_PLC data)
+        //{
+        //    return data.TYPE switch
+        //    {
+        //        PLCType.西门子 => new SiemensS7PLC((int)data.MODEL, data.IP),
+        //        PLCType.三菱 => new MelsecPLC(data.IP, data.PORT),
+        //        PLCType.AB => new AllenBradleyPLC(data.IP),
+        //        PLCType.汇川 => new HuiChuangPLC(data.IP),
+        //        _ => throw new Exception("不支持此PLC")
+        //    };
+        //}
+
+        public IPLCAccessor Create(WCS_PLC data)
         {
-            return data.TYPE switch
-            {
-                PLCType.西门子 => new SiemensS7PLC((int)data.MODEL, data.IP),
-                PLCType.三菱 => new MelsecPLC(data.IP, data.PORT),
-                PLCType.AB => new AllenBradleyPLC(data.IP),
-                PLCType.汇川 => new HuiChuangPLC(data.IP),
-                _ => throw new Exception("不支持此PLC")
-            };
+            if (data.TYPE == PLCType.西门子)
+                return new SiemensS7PLC(data.IP, data.PORT, data.RACK, data.SLOT);
+            else
+                throw new Exception("不支持此PLC");
         }
+
+        //IPLCAccessor IPLCAccessorCreater.Create(WCS_PLC data)
+        //{
+        //    throw new NotImplementedException();
+        //}
     }
 }

+ 64 - 38
WCS.Service/PLCAccessors/SiemensS7PLC.cs

@@ -1,55 +1,81 @@
-using HslCommunication.Profinet.Siemens;
-using WCS.Core;
-using WCS.Core.BaseExtensions;
-using WCS.Core.DataTrans;
-using WCS.Core.Virtual_PLC;
+using WCS.Core.DataTrans;
 
 namespace WCS.Service.PLCAccessors
 {
-    public class SiemensS7PLC : SiemensS7Net, IPlcAccessor
-    {
-        private SiemensS7Net plc;
+    //public class SiemensS7PLC : SiemensS7Net, IPlcAccessor
+    //{
+    //    private SiemensS7Net plc;
 
-        public SiemensS7PLC(SiemensPLCS type) : base(type)
-        {
-        }
+    //    public SiemensS7PLC(SiemensPLCS type) : base(type)
+    //    {
+    //    }
 
-        public SiemensS7PLC(SiemensPLCS type, string ip) : base(type, ip)
-        {
-            plc = new SiemensS7Net(type, ip);
-        }
+    //    public SiemensS7PLC(SiemensPLCS type, string ip) : base(type, ip)
+    //    {
+    //        plc = new SiemensS7Net(type, ip);
+    //    }
+
+    //    public SiemensS7PLC(int type, string ip) : base((SiemensPLCS)type, ip)
+    //    {
+    //        plc = new SiemensS7Net((SiemensPLCS)type, ip);
+    //    }
+
+    //    public byte[] ReadBytes(ushort db, ushort address, ushort length, ushort dataLength)
+    //    {
+    //        if (Configs.Any(SystemMode.虚拟plc))
+    //        {
+    //            return PlcData.Read(new PLCData { IP = plc.IpAddress, DB = db, Length = length, DataLength = dataLength });
+    //        }
+
+    //        var addr = "DB" + db + "." + address;
+    //        var res = plc.Read(addr, length);
+    //        if (res.IsSuccess)
+    //            return res.Content;
+    //        throw new WarnException("读取PLC数据失败:" + res.Message);
+    //    }
+
+    //    public void WriteBytes(ushort db, ushort address, byte[] data)
+    //    {
+    //        if (Configs.Any(SystemMode.虚拟plc))
+    //        {
+    //            PlcData.Write(new PLCData { IP = plc.IpAddress, DB = db }, address, data);
+    //        }
+    //        else
+    //        {
+    //            var res = plc.Write("D" + address, data);
+    //            if (!res.IsSuccess)
+    //                throw new WarnException("写入PLC数据失败:" + res.Message);
+    //        }
+    //    }
+    //}
+
+    public class SiemensS7PLC : IPLCAccessor
+    {
+        private PLC.Siemens.O.SimenssPlc plc;
 
-        public SiemensS7PLC(int type, string ip) : base((SiemensPLCS)type, ip)
+        public SiemensS7PLC(string ip, int port, int rack, int slot)
         {
-            plc = new SiemensS7Net((SiemensPLCS)type, ip);
+            plc = new PLC.Siemens.O.SimenssPlc(ip, rack, slot);
+            plc.Connect();
         }
 
-        public byte[] ReadBytes(ushort db, ushort address, ushort length, ushort dataLength)
+        public byte[] ReadBytes(ushort db, ushort address, ushort length)
         {
-            if (Configs.Any(SystemMode.虚拟plc))
-            {
-                return PlcData.Read(new PLCData { IP = plc.IpAddress, DB = db, Length = length, DataLength = dataLength });
-            }
-
-            var addr = "DB" + db + "." + address;
-            var res = plc.Read(addr, length);
-            if (res.IsSuccess)
-                return res.Content;
-            throw new WarnException("读取PLC数据失败:" + res.Message);
+            if (!plc.Connected)
+                plc.Connect();
+            var res = plc.ReadArea(PLC.Siemens.Protocol.Common.AreaType.DB, db, address, length, PLC.Siemens.Protocol.Common.DataType.Byte);
+            if (res == null)
+                throw new Exception("读取DB块数据失败");
+            return res.Data;
         }
 
         public void WriteBytes(ushort db, ushort address, byte[] data)
         {
-            if (Configs.Any(SystemMode.虚拟plc))
-            {
-                PlcData.Write(new PLCData { IP = plc.IpAddress, DB = db }, address, data);
-            }
-            else
-            {
-                var res = plc.Write("D" + address, data);
-                if (!res.IsSuccess)
-                    throw new WarnException("写入PLC数据失败:" + res.Message);
-            }
+            if (!plc.Connected)
+                plc.Connect();
+            var res = plc.WriteArea(PLC.Siemens.Protocol.Common.AreaType.DB, db, address, (ushort)data.Length, PLC.Siemens.Protocol.Common.DataType.Byte, data);
+            if (!res)
+                throw new Exception("写入DB块数据失败");
         }
     }
 }

+ 1 - 1
WCS.Service/Worker.cs

@@ -175,7 +175,7 @@ namespace WCS.Service
                 WMS.TaskException(d, s);
             };
 
-            PlcAccessor.Creater = new PLCAccessors.PlcAccessorsCreater();
+            PLCAccessor.Creater = new PLCAccessors.PlcAccessorsCreater();
             try
             {
                 Db.Do(db =>

+ 9 - 0
WCS.WebApi/WCSApi.cs

@@ -244,5 +244,14 @@ namespace WCS.WebApi
             }
             return res;
         }
+
+        /// <summary>
+        /// AGV调取的接口
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost]
+        public WcsAgvApiResponse agvCallback(AgvCallbackRequest agvCallback)
+        {
+        }
     }
 }

+ 142 - 0
WCS.WebApi/WcsAgvApiResponse.cs

@@ -0,0 +1,142 @@
+namespace WCS.WebApi
+{
+    /// <summary>
+    /// WCS给AGV的响应结果
+    /// </summary>
+    internal class WcsAgvApiResponse
+    {
+        /// <summary>
+        /// 返回码
+        /// </summary>
+        public string code { get; set; }
+
+        /// <summary>
+        /// 返回消息
+        /// </summary>
+        public string message { get; set; }
+
+        /// <summary>
+        /// 请求编号
+        /// </summary>
+        public string reqCode { get; set; }
+    }
+
+    /// <summary>
+    /// WCS给AGV的响应结果
+    /// </summary>
+    internal class AgvCallbackRequest
+    {
+        /// <summary>
+        /// 请求编号,每个请求都要一个唯一编号, 同一个请求重复提交, 使用同一编号
+        /// </summary>
+        public string reqCode { get; set; }
+
+        /// <summary>
+        /// 请求时间戳,格式: “yyyy-MM-dd HH:mm:ss”
+        /// </summary>
+        public string reqTime { get; set; }
+
+        /// <summary>
+        /// 地码 X 坐标(mm):任务完成时有值
+        /// </summary>
+        public string cooX { get; set; }
+
+        /// <summary>
+        /// 地码 Y 坐标(mm):任务完成时有值
+        /// </summary>
+        public string cooY { get; set; }
+
+        /// <summary>
+        /// 当前位置编号
+        /// 任务开始:该位置为任务起点
+        /// 走出储位:该位置为任务起点
+        /// 任务单取消:该位置为工作位编号
+        /// 任务结束:该位置为任务终点
+        /// 取放申请:取放料箱的点
+        /// </summary>
+        public string currentPositionCode { get; set; }
+
+        /// <summary>
+        /// 自定义字段,不超过2000个字符
+        /// </summary>
+        public string data { get; set; }
+
+        /// <summary>
+        /// 地图编号
+        /// </summary>
+        public string mapCode { get; set; }
+
+        /// <summary>
+        /// 地码编号:任务完成时有值
+        /// </summary>
+        public string mapDataCode { get; set; }
+
+        /// <summary>
+        /// 仓位编号:叉车与CTU任务时有值
+        /// </summary>
+        public string stgBinCode { get; set; }
+
+        /// <summary>
+        /// 方法名, 可使用任务类型做为方法名 由RCS-2000任务模板配置后并告知上层系统
+        /// 默认使用方式:
+        /// start : 任务开始
+        /// outbin : 走出储位
+        /// end : 任务结束
+        /// cancel : 任务单取消
+        /// apply:CTU料箱取放申请
+        /// </summary>
+        public string method { get; set; }
+
+        /// <summary>
+        /// 货架编号:背货架时有值
+        /// </summary>
+        public string podCode { get; set; }
+
+        /// <summary>
+        /// 180”,”0”,”90”,”-90” 分别对应地图的”左”,”右”,”上”,”下”:任务完成时有值
+        /// </summary>
+        public string podDir { get; set; }
+
+        /// <summary>
+        /// 物料编号
+        /// </summary>
+        public string materialLot { get; set; }
+
+        /// <summary>
+        /// AGV编号(同 agvCode )
+        /// </summary>
+        public string robotCode { get; set; }
+
+        /// <summary>
+        /// 当前任务单号
+        /// </summary>
+        public string taskCode { get; set; }
+
+        /// <summary>
+        /// 工作位,与RCS-2000端配置的位置名称一致。任务完成时有值,与生成任务单接口中的wbCode一致。
+        /// </summary>
+        public string wbCode { get; set; }
+
+        /// <summary>
+        /// 容器编号
+        /// </summary>
+        public string ctnrCode { get; set; }
+
+        /// <summary>
+        /// 容器类型
+        /// </summary>
+        public string ctnrType { get; set; }
+        /// <summary>
+        /// 巷道编号
+        /// </summary>
+        public string roadWayCode { get;set; }
+        /// <summary>
+        /// 巷道内顺序号 巷道尾是0,到巷道头依次递增1
+        /// </summary>
+        public string seq { get; set;}
+        /// <summary>
+        /// 设备编号,如梳齿式工作站、输送线等,一般使用于CTU场景。系统根据仓位定位到关联的设备编号。
+        /// </summary>
+        public string eqpCode { get; set;}
+    }
+}

+ 65 - 3
WCS.WorkEngineering/Works/SRM/SRMWork.cs

@@ -1,7 +1,7 @@
-using WCS.Core;
+using System;
+using WCS.Core;
 using WCS.Entity;
 using WCS.Entity.Protocol;
-using WCS.Service.Extensions;
 using WCS.Service.Handlers;
 
 namespace WCS.Service.Works.SRM
@@ -11,7 +11,69 @@ namespace WCS.Service.Works.SRM
     {
         protected override void Do(Device<ISRM520, ISRM521, ISRM537> obj)
         {
-            obj.Data.TaskID_1 = (int)22l;
+            if (obj.Data.VoucherNo_2 != obj.Data2.VoucherNo_2) throw new Exception("凭证号不一致");
+            if (obj.Data2.TaskFinishiID_1 != 0 || obj.Data2.TaskFinishiID_2 != 0)
+            {
+                obj.Data.OK_ACK_1 = 1;
+                obj.Data.OK_ACK_2 = 1;
+
+                obj.Data.TaskID_1 = 123456;
+                obj.Data.RowPos1_1 = 3;
+                obj.Data.TravelPos1_1 = 9;
+                obj.Data.LiftPos1_1 = 1;
+                obj.Data.ForkStartPos1_1 = WCS.Entity.Protocol.SRM.SRMForkPos.深度1;
+                obj.Data.RowPos2_1 = 3;
+                obj.Data.TravelPos2_1 = 1;
+                obj.Data.LiftPos2_1 = 1;
+                obj.Data.ForkDestPos2_1 = WCS.Entity.Protocol.SRM.SRMForkPos.深度1;
+                obj.Data.TaskType_1 = WCS.Entity.Protocol.SRM.SRMTaskType.取放货任务;
+                obj.Data.TaskSum_2 = 1;
+                var b = true;
+                if (b)
+                {
+                    obj.Data.TaskID_2 = 123456;
+                    obj.Data.RowPos1_2 = 3;
+                    obj.Data.Travelpos1_2 = 10;
+                    obj.Data.Liftpos1_2 = 1;
+                    obj.Data.ForkStartPos1_2 = WCS.Entity.Protocol.SRM.SRMForkPos.深度1;
+                    obj.Data.RowPos2_2 = 3;
+                    obj.Data.Travelpos2_2 = 2;
+                    obj.Data.Liftpos2_2 = 1;
+                    obj.Data.ForkStartPos2_2 = WCS.Entity.Protocol.SRM.SRMForkPos.深度1;
+                    obj.Data.TaskType_2 = WCS.Entity.Protocol.SRM.SRMTaskType.取放货任务;
+                }
+                obj.Data.VoucherNo_2++;
+                return;
+            }
+            if (obj.Data2.SrmRunStatus != WCS.Entity.Protocol.SRM.SRMFRunStatus.空闲) throw new Exception("任务执行中");
+           
+
+            obj.Data.TaskID_1 = 123456;
+            obj.Data.RowPos1_1 = 3;
+            obj.Data.TravelPos1_1 = 1; 
+            obj.Data.LiftPos1_1 = 1;
+            obj.Data.ForkStartPos1_1 = WCS.Entity.Protocol.SRM.SRMForkPos.深度1;
+            obj.Data.RowPos2_1 = 3;
+            obj.Data.TravelPos2_1 = 9;
+            obj.Data.LiftPos2_1 = 1;
+            obj.Data.ForkDestPos2_1 = WCS.Entity.Protocol.SRM.SRMForkPos.深度1;
+            obj.Data.TaskType_1 = WCS.Entity.Protocol.SRM.SRMTaskType.取放货任务;
+            obj.Data.TaskSum_2 = 1;
+            var a = true;
+            if (a)
+            {
+                obj.Data.TaskID_2 = 123456;
+                obj.Data.RowPos1_2 = 3;
+                obj.Data.Travelpos1_2 = 2;
+                obj.Data.Liftpos1_2 = 1;
+                obj.Data.ForkStartPos1_2 = WCS.Entity.Protocol.SRM.SRMForkPos.深度1;
+                obj.Data.RowPos2_2 = 3;
+                obj.Data.Travelpos2_2 = 10;
+                obj.Data.Liftpos2_2 = 1;
+                obj.Data.ForkStartPos2_2 = WCS.Entity.Protocol.SRM.SRMForkPos.深度1;
+                obj.Data.TaskType_2= WCS.Entity.Protocol.SRM.SRMTaskType.取放货任务;
+            }
+            obj.Data.VoucherNo_2++;
         }
 
         protected override bool SelectDevice(WCS_DEVICE dev)