Browse Source

version update to 1.0.7

chenkui 2 weeks ago
parent
commit
50758fdf86

+ 2 - 2
SecsGem.Core.Application/Properties/AssemblyInfo.cs

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
 //通过使用 "*",如下所示:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.6")]
-[assembly: AssemblyFileVersion("1.0.0.6")]
+[assembly: AssemblyVersion("1.0.0.7")]
+[assembly: AssemblyFileVersion("1.0.0.7")]

+ 10 - 2
SecsGem.Core.Application/SecGemApplication.cs

@@ -166,7 +166,7 @@ namespace SecsGem.Core.Application
         /// <param name="e"></param>
         private void SecsGemEquipment_OnDisConnectionChanged(object sender, string e)
         {
-            EquipmentCommand.WriteWarningLog(e);
+            EquipmentCommand.WriteErrorLog(e);
         }
 
         /// <summary>
@@ -283,7 +283,7 @@ namespace SecsGem.Core.Application
                         {"ControlState",(int)_controlState },
                     });
                 }
-                else
+                else if(_controlState==ControlState.OnlineLocal)
                 {
                     EV.Notify(ControlStateLOCAL, new SerializableDictionary<string, object>()
                     {
@@ -291,6 +291,14 @@ namespace SecsGem.Core.Application
                         {"ControlState",(int)_controlState },
                     });
                 }
+                else if(_controlState==ControlState.HostOffline)
+                {
+                    EV.Notify(EquipmentOFFLINE, new SerializableDictionary<string, object>()
+                    {
+                        {_clockStatusVariableName, DateTime.Now.ToString(SecsGemDataUtil.GetSystemTimeFormat(_moduleName))},
+                        {"ControlState",(int)_controlState },
+                    });
+                }
             }
             return true;
         }

+ 2 - 2
SecsGem.Core/Properties/AssemblyInfo.cs

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
 //通过使用 "*",如下所示:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.6")]
-[assembly: AssemblyFileVersion("1.0.0.6")]
+[assembly: AssemblyVersion("1.0.0.7")]
+[assembly: AssemblyFileVersion("1.0.0.7")]

+ 83 - 76
SecsGem.Core/Responser/S2F13Responser.cs

@@ -1,76 +1,83 @@
-using Aitex.Core.Util;
-using SecsGem.Core.EnumData;
-using SecsGem.Core.ItemModel;
-using SecsGem.Core.Utility;
-using SecsGem.Core.Variables;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace SecsGem.Core.Responser
-{
-    public class S2F13Responser : SecsMessageResponser
-    {
-        /// <summary>
-        /// 回复
-        /// </summary>
-        /// <param name="secsMessage"></param>
-        /// <returns></returns>
-        public override SecsMessage Reply(string moduleName,SecsMessage secsMessage)
-        {
-            Item item = secsMessage.Data as ListItem;
-            List<int> ids = new List<int>();
-            if (item.Count() == 0)
-            {
-                ids = SecsGemDataUtil.GetAllEquipmentConstantIds(moduleName);
-            }
-            else
-            {
-                for(int i=0;i<item.Count(); i++)
-                {
-                    Item innerItem = item.DataItems[i];
-                    int svid = -1;
-                    int.TryParse(innerItem.FirstValue(),out svid);
-                    ids.Add(svid);
-                }
-            }
-            return CreateF2F14ReplyMessage(moduleName,ids, secsMessage.Header);
-        }
-
-        /// <summary>
-        /// S2F13回复消息S2F14
-        /// </summary>
-        /// <param name="svIds"></param>
-        /// <param name="uniqueId"></param>
-        /// <returns></returns>
-        private SecsMessage CreateF2F14ReplyMessage(string moduleName,List<int> svIds, SecsMessageHeader sender)
-        {
-
-            SecsMessageHeader header = Singleton<SecsMessageHeaderBuilder>.Instance.BuilderReplyHeader(sender);
-
-            Item item = new ListItem();
-            for (int i = 0; i < svIds.Count; i++)
-            {
-                EquipmentConstant equipmentConstant = SecsGemDataUtil.GetEquipmentConstantById(moduleName,svIds[i]);
-                if (equipmentConstant != null)
-                {
-                    if (equipmentConstant.Value != null)
-                    {
-                        item.AddItem(equipmentConstant.ItemValue);
-                    }
-                    else
-                    {
-                        item.AddItem(ItemUtil.GetEmptyItem(equipmentConstant.ValueType));
-                    }
-                }
-                else
-                {
-                    item.AddItem(ItemUtil.GetEmptyItem(DataFormat.U1));
-                }
-            }
-            return new SecsMessage(header, item);
-        }
-    }
-}
+using Aitex.Core.Util;
+using SecsGem.Core.EnumData;
+using SecsGem.Core.ItemModel;
+using SecsGem.Core.Utility;
+using SecsGem.Core.Variables;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecsGem.Core.Responser
+{
+    public class S2F13Responser : SecsMessageResponser
+    {
+        /// <summary>
+        /// 回复
+        /// </summary>
+        /// <param name="secsMessage"></param>
+        /// <returns></returns>
+        public override SecsMessage Reply(string moduleName,SecsMessage secsMessage)
+        {
+            Item item = secsMessage.Data as ListItem;
+            List<int> ids = new List<int>();
+            if (item.Count() == 0)
+            {
+                ids = SecsGemDataUtil.GetAllEquipmentConstantIds(moduleName);
+            }
+            else
+            {
+                for(int i=0;i<item.Count(); i++)
+                {
+                    Item innerItem = item.DataItems[i];
+                    int svid = -1;
+                    int.TryParse(innerItem.FirstValue(),out svid);
+                    ids.Add(svid);
+                }
+            }
+            return CreateF2F14ReplyMessage(moduleName,ids, secsMessage.Header);
+        }
+
+        /// <summary>
+        /// S2F13回复消息S2F14
+        /// </summary>
+        /// <param name="svIds"></param>
+        /// <param name="uniqueId"></param>
+        /// <returns></returns>
+        private SecsMessage CreateF2F14ReplyMessage(string moduleName,List<int> svIds, SecsMessageHeader sender)
+        {
+
+            SecsMessageHeader header = Singleton<SecsMessageHeaderBuilder>.Instance.BuilderReplyHeader(sender);
+
+            Item item = new ListItem();
+            for (int i = 0; i < svIds.Count; i++)
+            {
+                EquipmentConstant equipmentConstant = SecsGemDataUtil.GetEquipmentConstantById(moduleName,svIds[i]);
+                if (equipmentConstant != null)
+                {
+                    if (equipmentConstant.Value != null)
+                    {
+                        if (equipmentConstant.ItemValue != null)
+                        {
+                            item.AddItem(equipmentConstant.ItemValue);
+                        }
+                        else
+                        {
+                            item.AddItem(ItemUtil.GetEmptyItem(equipmentConstant.ValueType));
+                        }
+                    }
+                    else
+                    {
+                        item.AddItem(ItemUtil.GetEmptyItem(equipmentConstant.ValueType));
+                    }
+                }
+                else
+                {
+                    item.AddItem(ItemUtil.GetEmptyItem(DataFormat.U1));
+                }
+            }
+            return new SecsMessage(header, item);
+        }
+    }
+}

+ 166 - 161
SecsGem.Core/Responser/S2F35Responser.cs

@@ -1,161 +1,166 @@
-using Aitex.Core.RT.OperationCenter;
-using Aitex.Core.Util;
-using SecsGem.Core.EnumData;
-using SecsGem.Core.ItemModel;
-using SecsGem.Core.SecsEnumData;
-using SecsGem.Core.Utility;
-using SecsGem.Core.Variables;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace SecsGem.Core.Responser
-{
-    public class S2F35Responser : SecsMessageResponser
-    {
-        /// <summary>
-        /// 回复
-        /// </summary>
-        /// <param name="secsMessage"></param>
-        /// <returns></returns>
-        public override SecsMessage Reply(string moduleName,SecsMessage secsMessage)
-        {
-            Item item = secsMessage.Data as ListItem;
-            Item dataIdItem = item.DataItems[0];
-            ListItem rootItem = item.DataItems[1] as ListItem;
-            SecsLRACK LDRACK = SecsLRACK.Accept;
-            List<int> ids = new List<int>(); 
-            if (rootItem.Count() != 0)
-            {
-                Dictionary<int, List<int>> dic = new Dictionary<int, List<int>>();
-                for (int i = 0; i < rootItem.Count(); i++)
-                {
-                    ListItem leafItem = rootItem.DataItems[i] as ListItem;
-                    if (leafItem == null)
-                    {
-                        LDRACK = SecsLRACK.DeniedInvalidFormat;
-                        return CreateF2F35ReplyMessage(secsMessage.Header, LDRACK);
-                    }
-                    Item ceidItem = leafItem.DataItems[0];
-                    int ceid = int.Parse(ceidItem.GetValue());
-                    List<int> rpids = null;
-                    LDRACK = CheckLeafItemData(moduleName,ceid, leafItem, ref rpids);
-                    if (LDRACK != SecsLRACK.Accept)
-                    {
-                        return CreateF2F35ReplyMessage(secsMessage.Header, LDRACK);
-                    }
-                    if (!dic.ContainsKey(ceid))
-                    {
-                        dic.Add(ceid, rpids);
-                    }
-                    else
-                    {
-                        return CreateF2F35ReplyMessage(secsMessage.Header,  SecsLRACK.DeniedCeidDefined);
-                    }
-                }
-                if (dic.Count != 0)
-                {
-                    AnalyseDic(moduleName, dic);
-                }
-            }
-            return CreateF2F35ReplyMessage(secsMessage.Header, LDRACK);
-        }
-        /// <summary>
-        /// 分析字典内容
-        /// </summary>
-        /// <param name="dic"></param>
-        private void AnalyseDic(string moduleName,Dictionary<int, List<int>> dic)
-        {
-            for (int i = 0; i < dic.Keys.Count; i++)
-            {
-                int ceid = dic.Keys.ElementAt(i);
-                List<int> rpids = dic[ceid];
-                if (rpids.Count == 0)//删除关联
-                {
-                    SecsGemDataUtil.RemoveCollectionEventLink(moduleName,ceid);
-                }
-                else//增加关联
-                {
-                    SecsGemDataUtil.LinkReportUnderCollectionEvemt(moduleName,ceid,rpids);
-                }
-            }
-            OP.DoOperation($"{moduleName}.{SecsGemConstData.EquipmentVariableSaveOperation}");
-        }
-        /// <summary>
-        /// 检验每个报告Item的情况
-        /// </summary>
-        /// <param name="leafItem"></param>
-        /// <returns></returns>
-        private SecsLRACK CheckLeafItemData(string moduleName,int ceid, ListItem leafItem, ref List<int> rpids)
-        {
-            rpids = new List<int>();
-            Item rpidsItem = leafItem.DataItems[1] as ListItem;
-            if (rpidsItem == null)
-            {
-                return SecsLRACK.DeniedInvalidFormat;
-            }
-            for (int j = 0; j < rpidsItem.Count(); j++)
-            {
-                Item svidItem = rpidsItem.DataItems[j];
-                int rpid = int.Parse(svidItem.GetValue());
-                rpids.Add(rpid);
-            }
-
-            if (!SecsGemDataUtil.IsCollectionEventContained(moduleName,ceid))
-            {
-                return SecsLRACK.DeniedCeidNotExist;
-            }
-            if (rpidsItem.Count() != 0)
-            {
-                if (SecsGemDataUtil.IsContainLink(moduleName, ceid))
-                {
-                    return SecsLRACK.DeniedCeidDefined;
-                }
-                else
-                {
-                    if (rpids.Count!=0&& !CheckRpidExist(moduleName,rpids))
-                    {
-                        return SecsLRACK.DeniedRpidNotExist;
-                    }
-                }
-            }
-            return SecsLRACK.Accept;
-        }
-        /// <summary>
-        /// 检验Rpid是否存在
-        /// </summary>
-        /// <param name="vids"></param>
-        /// <returns></returns>
-        private bool CheckRpidExist(string moduleNane,List<int> rpids)
-        {
-            for (int i = 0; i < rpids.Count; i++)
-            {
-                if (SecsGemDataUtil.IsReportContained(moduleNane,rpids[i]))
-                {
-                    continue;
-                }
-                else
-                {
-                    return false;
-                }
-            }
-            return true;
-        }
-
-        /// <summary>
-        /// S2F33回复消息S2F34
-        /// </summary>
-        /// <param name="ecids"></param>
-        /// <param name="uniqueId"></param>
-        /// <returns></returns>
-        private SecsMessage CreateF2F35ReplyMessage(SecsMessageHeader sender, SecsLRACK LRACK)
-        {
-            SecsMessageHeader header = Singleton<SecsMessageHeaderBuilder>.Instance.BuilderReplyHeader(sender);
-
-            Item item = new BinaryItem(new byte[] { (byte)LRACK });
-            return new SecsMessage(header, item);
-        }
-    }
-}
+using Aitex.Core.RT.OperationCenter;
+using Aitex.Core.Util;
+using SecsGem.Core.EnumData;
+using SecsGem.Core.ItemModel;
+using SecsGem.Core.SecsEnumData;
+using SecsGem.Core.Utility;
+using SecsGem.Core.Variables;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecsGem.Core.Responser
+{
+    public class S2F35Responser : SecsMessageResponser
+    {
+        /// <summary>
+        /// 回复
+        /// </summary>
+        /// <param name="secsMessage"></param>
+        /// <returns></returns>
+        public override SecsMessage Reply(string moduleName,SecsMessage secsMessage)
+        {
+            Item item = secsMessage.Data as ListItem;
+            Item dataIdItem = item.DataItems[0];
+            ListItem rootItem = item.DataItems[1] as ListItem;
+            SecsLRACK LDRACK = SecsLRACK.Accept;
+            List<int> ids = new List<int>(); 
+            if (rootItem.Count() != 0)
+            {
+                Dictionary<int, List<int>> dic = new Dictionary<int, List<int>>();
+                for (int i = 0; i < rootItem.Count(); i++)
+                {
+                    ListItem leafItem = rootItem.DataItems[i] as ListItem;
+                    if (leafItem == null)
+                    {
+                        LDRACK = SecsLRACK.DeniedInvalidFormat;
+                        return CreateF2F35ReplyMessage(secsMessage.Header, LDRACK);
+                    }
+                    Item ceidItem = leafItem.DataItems[0];
+                    int ceid = int.Parse(ceidItem.GetValue());
+                    List<int> rpids = null;
+                    LDRACK = CheckLeafItemData(moduleName,ceid, leafItem, ref rpids);
+                    if (LDRACK != SecsLRACK.Accept)
+                    {
+                        return CreateF2F35ReplyMessage(secsMessage.Header, LDRACK);
+                    }
+                    if (!dic.ContainsKey(ceid))
+                    {
+                        dic.Add(ceid, rpids);
+                    }
+                    else
+                    {
+                        return CreateF2F35ReplyMessage(secsMessage.Header,  SecsLRACK.DeniedCeidDefined);
+                    }
+                }
+                if (dic.Count != 0)
+                {
+                    AnalyseDic(moduleName, dic);
+                }
+            }
+            else
+            {
+                SecsGemDataUtil.RemoveAllCeidLinks(moduleName);
+                OP.DoOperation($"{moduleName}.{SecsGemConstData.EquipmentVariableSaveOperation}");
+            }
+            return CreateF2F35ReplyMessage(secsMessage.Header, LDRACK);
+        }
+        /// <summary>
+        /// 分析字典内容
+        /// </summary>
+        /// <param name="dic"></param>
+        private void AnalyseDic(string moduleName,Dictionary<int, List<int>> dic)
+        {
+            for (int i = 0; i < dic.Keys.Count; i++)
+            {
+                int ceid = dic.Keys.ElementAt(i);
+                List<int> rpids = dic[ceid];
+                if (rpids.Count == 0)//删除关联
+                {
+                    SecsGemDataUtil.RemoveCollectionEventLink(moduleName,ceid);
+                }
+                else//增加关联
+                {
+                    SecsGemDataUtil.LinkReportUnderCollectionEvemt(moduleName,ceid,rpids);
+                }
+            }
+            OP.DoOperation($"{moduleName}.{SecsGemConstData.EquipmentVariableSaveOperation}");
+        }
+        /// <summary>
+        /// 检验每个报告Item的情况
+        /// </summary>
+        /// <param name="leafItem"></param>
+        /// <returns></returns>
+        private SecsLRACK CheckLeafItemData(string moduleName,int ceid, ListItem leafItem, ref List<int> rpids)
+        {
+            rpids = new List<int>();
+            Item rpidsItem = leafItem.DataItems[1] as ListItem;
+            if (rpidsItem == null)
+            {
+                return SecsLRACK.DeniedInvalidFormat;
+            }
+            for (int j = 0; j < rpidsItem.Count(); j++)
+            {
+                Item svidItem = rpidsItem.DataItems[j];
+                int rpid = int.Parse(svidItem.GetValue());
+                rpids.Add(rpid);
+            }
+
+            if (!SecsGemDataUtil.IsCollectionEventContained(moduleName,ceid))
+            {
+                return SecsLRACK.DeniedCeidNotExist;
+            }
+            if (rpidsItem.Count() != 0)
+            {
+                if (SecsGemDataUtil.IsContainLink(moduleName, ceid))
+                {
+                    return SecsLRACK.DeniedCeidDefined;
+                }
+                else
+                {
+                    if (rpids.Count!=0&& !CheckRpidExist(moduleName,rpids))
+                    {
+                        return SecsLRACK.DeniedRpidNotExist;
+                    }
+                }
+            }
+            return SecsLRACK.Accept;
+        }
+        /// <summary>
+        /// 检验Rpid是否存在
+        /// </summary>
+        /// <param name="vids"></param>
+        /// <returns></returns>
+        private bool CheckRpidExist(string moduleNane,List<int> rpids)
+        {
+            for (int i = 0; i < rpids.Count; i++)
+            {
+                if (SecsGemDataUtil.IsReportContained(moduleNane,rpids[i]))
+                {
+                    continue;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// S2F33回复消息S2F34
+        /// </summary>
+        /// <param name="ecids"></param>
+        /// <param name="uniqueId"></param>
+        /// <returns></returns>
+        private SecsMessage CreateF2F35ReplyMessage(SecsMessageHeader sender, SecsLRACK LRACK)
+        {
+            SecsMessageHeader header = Singleton<SecsMessageHeaderBuilder>.Instance.BuilderReplyHeader(sender);
+
+            Item item = new BinaryItem(new byte[] { (byte)LRACK });
+            return new SecsMessage(header, item);
+        }
+    }
+}

File diff suppressed because it is too large
+ 527 - 509
SecsGem.Core/SecsReplyMessageFactory.cs


File diff suppressed because it is too large
+ 882 - 866
SecsGem.Core/Utility/SecsGemDataUtil.cs


+ 96 - 96
SecsGem.Core/Validator/S2F35Validator.cs

@@ -1,96 +1,96 @@
-using SecsGem.Core.EnumData;
-using SecsGem.Core.ItemModel;
-using SecsGem.Core.Utility;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace SecsGem.Core.Validator
-{
-    public class S2F35Validator :SecsMessageValidator
-    {
-        /// <summary>
-        /// 检验
-        /// </summary>
-        /// <param name="message"></param>
-        /// <returns></returns>
-        public override ValidateType Validate(SecsMessage message)
-        {
-            ValidateType rootValidateType=base.Validate(message);
-            if (rootValidateType != ValidateType.OK)
-            {
-                return rootValidateType;
-            }
-
-            Item item = message.Data;
-            if (item == null)
-            {
-                return ValidateType.IllegalData;
-            }
-            if (!item.IsArray)
-            {
-                return ValidateType.IllegalData;
-            }
-            //内部格式"<L <U4 DATAID><L <L <U4 CEID1><L <U4 RPID1><U4 RPID1>> >..> >
-            ListItem listItem = item as ListItem;
-            if(item.Count()==0)
-            {
-                return ValidateType.IllegalData;
-            }
-            //DataID
-            Item dataIdItem = listItem.DataItems[0];
-            if(!ItemUtil.IsInteger(dataIdItem))
-            {
-                return ValidateType.IllegalData;
-            }
-            //集合
-            if (!listItem.DataItems[1].IsArray)
-            {
-                return ValidateType.IllegalData;
-            }
-            Item dataLstItem = listItem.DataItems[1] as ListItem;
-            if(dataLstItem.Count()==0)
-            {
-                return ValidateType.IllegalData;
-            }
-            for(int i = 0; i < dataLstItem.Count(); i++)
-            {
-                //集合
-                if(!dataLstItem.DataItems[i].IsArray)
-                {
-                    return ValidateType.IllegalData;
-                }
-                ListItem innerItem= dataLstItem.DataItems[i] as ListItem;
-                if(innerItem.Count()<2)
-                {
-                    return ValidateType.IllegalData;
-                }
-                //rpid
-                Item ceidItem = innerItem.DataItems[0];
-                if(!ItemUtil.IsInteger(ceidItem))
-                {
-                    return ValidateType.IllegalData;
-                }
-                //集合
-                Item rpidsItem = innerItem.DataItems[1];
-                if(!rpidsItem.IsArray)
-                {
-                    return ValidateType.IllegalData;
-                }
-                Item rpidLstItem = rpidsItem as ListItem;
-                for(int j=0;j< rpidLstItem.Count();j++)
-                {
-                    //vid
-                    Item vidItem = rpidLstItem.DataItems[j];
-                    if(!ItemUtil.IsInteger(vidItem))
-                    {
-                        return ValidateType.IllegalData;
-                    }
-                }
-            }
-            return ValidateType.OK;
-        }
-    }
-}
+using SecsGem.Core.EnumData;
+using SecsGem.Core.ItemModel;
+using SecsGem.Core.Utility;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SecsGem.Core.Validator
+{
+    public class S2F35Validator :SecsMessageValidator
+    {
+        /// <summary>
+        /// 检验
+        /// </summary>
+        /// <param name="message"></param>
+        /// <returns></returns>
+        public override ValidateType Validate(SecsMessage message)
+        {
+            ValidateType rootValidateType=base.Validate(message);
+            if (rootValidateType != ValidateType.OK)
+            {
+                return rootValidateType;
+            }
+
+            Item item = message.Data;
+            if (item == null)
+            {
+                return ValidateType.IllegalData;
+            }
+            if (!item.IsArray)
+            {
+                return ValidateType.IllegalData;
+            }
+            //内部格式"<L <U4 DATAID><L <L <U4 CEID1><L <U4 RPID1><U4 RPID1>> >..> >
+            ListItem listItem = item as ListItem;
+            if(item.Count()==0)
+            {
+                return ValidateType.OK;
+            }
+            //DataID
+            Item dataIdItem = listItem.DataItems[0];
+            if(!ItemUtil.IsInteger(dataIdItem))
+            {
+                return ValidateType.IllegalData;
+            }
+            //集合
+            if (!listItem.DataItems[1].IsArray)
+            {
+                return ValidateType.IllegalData;
+            }
+            Item dataLstItem = listItem.DataItems[1] as ListItem;
+            if(dataLstItem.Count()==0)
+            {
+                return ValidateType.IllegalData;
+            }
+            for(int i = 0; i < dataLstItem.Count(); i++)
+            {
+                //集合
+                if(!dataLstItem.DataItems[i].IsArray)
+                {
+                    return ValidateType.IllegalData;
+                }
+                ListItem innerItem= dataLstItem.DataItems[i] as ListItem;
+                if(innerItem.Count()<2)
+                {
+                    return ValidateType.IllegalData;
+                }
+                //rpid
+                Item ceidItem = innerItem.DataItems[0];
+                if(!ItemUtil.IsInteger(ceidItem))
+                {
+                    return ValidateType.IllegalData;
+                }
+                //集合
+                Item rpidsItem = innerItem.DataItems[1];
+                if(!rpidsItem.IsArray)
+                {
+                    return ValidateType.IllegalData;
+                }
+                Item rpidLstItem = rpidsItem as ListItem;
+                for(int j=0;j< rpidLstItem.Count();j++)
+                {
+                    //vid
+                    Item vidItem = rpidLstItem.DataItems[j];
+                    if(!ItemUtil.IsInteger(vidItem))
+                    {
+                        return ValidateType.IllegalData;
+                    }
+                }
+            }
+            return ValidateType.OK;
+        }
+    }
+}

+ 45 - 2
SecsGem.Hsms.Core/NetClientChannel.cs

@@ -1,4 +1,5 @@
 using Aitex.Core.RT.OperationCenter;
+using CommunityToolkit.HighPerformance.Buffers;
 using MECF.Framework.Common.Equipment;
 using SecsGem.Core;
 using SecsGem.Core.Encoder;
@@ -59,6 +60,8 @@ namespace SecsGem.Hsms.Core
 
         private byte[] receiveBuffer;
 
+        private ArraySegment<byte> _receiveSegment;
+
         private Pipe pipe;
 
         private CancellationTokenSource _cancellationTokenSource;
@@ -90,6 +93,7 @@ namespace SecsGem.Hsms.Core
             this._clientSocket = clientSocket;
             this.encoder = encoder;
             receiveBuffer = new byte[receiveBufferLength];
+            _receiveSegment= new ArraySegment<byte>(receiveBuffer);
             pipe = new Pipe(new PipeOptions(useSynchronizationContext: true));
             _pipeDecoder = new PipeDecoder(pipe.Reader, pipe.Writer,_cancellationTokenSource.Token);
             
@@ -98,7 +102,7 @@ namespace SecsGem.Hsms.Core
             _pipeDecoder.OnAnalyseMessageEventHandler += _pipeDecoder_OnAnalyseMessageEventHandler;
             _pipeDecoder.OnSendMessageEventHandler += _pipeDecoder_OnSendMessageEventHandler;
             _pipeDecoder.OnReplyMessageEventHandler += _pipeDecoder_OnReplyMessageEventHandler;
-            Task.Run(() => StartPipeDecoderProducerAsync(_cancellationTokenSource.Token));
+             // Task.Run(() => StartPipeDecoderProducerAsync(_cancellationTokenSource.Token));
             Task.Run(() => StartPipeDecoderConsumerAsync(_cancellationTokenSource.Token));
             
             if (options.SupportHeartCheck)
@@ -113,6 +117,8 @@ namespace SecsGem.Hsms.Core
                 Dispose();
             }, null, Timeout.Infinite, Timeout.Infinite);
             ChannelStateChanged(ClientChannelState.Connected);
+
+            clientSocket.BeginReceive(receiveBuffer, 0, receiveBuffer.Length, SocketFlags.None, ReceiveCallback, clientSocket);
         }
 
 
@@ -208,7 +214,7 @@ namespace SecsGem.Hsms.Core
             if(controlState==ControlState.EquipmentOffline||controlState==ControlState.HostOffline)
             {
                 if (secsMessage.Header.Stream != 1 ||
-                    (secsMessage.Header.Stream==1&& secsMessage.Header.Function != 1 && secsMessage.Header.Function != 17&&secsMessage.Header.Function!=13))
+                    (secsMessage.Header.Stream==1&& secsMessage.Header.Function != 1 && secsMessage.Header.Function != 17&&secsMessage.Header.Function!=13&&secsMessage.Header.Function==15))
                 {
                     reply = SecsReplyMessageFactory.CreateSxF0Message(secsMessage.Header);
                 }
@@ -266,6 +272,43 @@ namespace SecsGem.Hsms.Core
             }
         }
         /// <summary>
+        /// 接收回调
+        /// </summary>
+        /// <param name="ar"></param>
+        private void ReceiveCallback(IAsyncResult ar)
+        {
+            try
+            {
+                int count = this._clientSocket.EndReceive(ar);
+                if (count != 0)
+                {
+                    byte[] byt = new byte[count];
+                    Array.Copy(receiveBuffer, 0, byt, 0, count);
+                    Memory<byte> bufferMemory = byt.AsMemory().Slice(0, count);
+                    HsmsLogMamager.Instance.WriteReceivedBuffer(bufferMemory.ToArray());
+                    if (heatCheck != null)
+                    {
+                        heatCheck.UpdateActiveTime();
+                    }
+                    pipe.Writer.WriteAsync(bufferMemory, _cancellationTokenSource.Token).ConfigureAwait(false);
+
+                }
+                else
+                {
+                    HsmsLogMamager.Instance.Error($"client id [{this.Id} remote disconected");
+                    Dispose();
+                    return;
+                }
+                _clientSocket.BeginReceive(receiveBuffer, 0, receiveBuffer.Length, SocketFlags.None, ReceiveCallback, _clientSocket);
+
+            }
+            catch (Exception ex)
+            {
+                HsmsLogMamager.Instance.Error($"client id [{this.Id}] end receive error", ex);
+                Dispose();
+            }
+        }
+        /// <summary>
         /// 侦听数据数据达到,写入管道
         /// </summary>
         /// <param name="cancellation"></param>

+ 333 - 317
SecsGem.Hsms.Core/PipeDecoder.cs

@@ -1,317 +1,333 @@
-using Aitex.Core.Util;
-using SecsGem.Core;
-using SecsGem.Core.EnumData;
-using SecsGem.Core.ItemModel;
-using SecsGem.Core.Utility;
-using SecsGem.Core.Validator;
-using System;
-using System.Buffers;
-using System.Buffers.Binary;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO.Pipelines;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using System.Runtime.Remoting.Channels;
-using System.Runtime.Remoting.Messaging;
-using System.Text;
-using System.Threading;
-using System.Threading.Channels;
-using System.Threading.Tasks;
-
-namespace SecsGem.Hsms.Core
-{
-    public class PipeDecoder
-    {
-        private readonly PipeReader _reader;
-        public PipeWriter Input { get; }
-
-        public event EventHandler<SecsMessage> OnSendResponse;
-
-        public event DelegateEvent.MessageEventHander OnAnalyseMessageEventHandler;
-
-        public event DelegateEvent.MessageEventHander OnSendMessageEventHandler;
-
-        public event DelegateEvent.MessageEventHander OnReplyMessageEventHandler;
-
-        public event EventHandler<string> OnDisConnection;
-
-        public PipeDecoder(PipeReader reader, PipeWriter input,CancellationToken cancellationToken)
-        {
-            _reader = reader;
-            Input = input;
-        }
-
-        public Task StartAsync(CancellationToken cancellation)
-        => DecodeLoopAsync(cancellation);
-
-
-        private async Task DecodeLoopAsync(
-            CancellationToken cancellation)
-        {
-            var totalLengthBytes = new byte[4];
-            var messageHeaderBytes = new byte[10];
-            // PipeReader peek first
-            ReadOnlySequence<byte> buffer = new ReadOnlySequence<byte>() ;
-            try
-            {
-                buffer = await PipeReadAsync(_reader, required: 4, cancellation).ConfigureAwait(false);
-            }
-            catch(Exception ex)
-            {
-                HsmsLogMamager.Instance.Error("PipeReadAsync error", ex);
-                Dispose();
-                return;
-            }
-            while (true)
-            {
-                try
-                {
-                    // 0: get total message length 4 bytes
-                    if (IsBufferInsufficient(_reader, ref buffer, required: 4))
-                    {
-                        buffer = await PipeReadAsync(_reader, required: 4, cancellation).ConfigureAwait(false);
-                    }
-                    var totalLengthSeq = buffer.Slice(buffer.Start, 4);
-                    totalLengthSeq.CopyTo(totalLengthBytes);
-                    uint messageLength = BinaryPrimitives.ReadUInt32BigEndian(totalLengthBytes);
-                    buffer = buffer.Slice(totalLengthSeq.End);
-                    HsmsLogMamager.Instance.WriteReceivedBuffer("length buffer",totalLengthBytes);
-
-                    // 1: get message header 10 bytes
-                    if (IsBufferInsufficient(_reader, ref buffer, required: 10))
-                    {
-                        buffer = await PipeReadAsync(_reader, required: 10, cancellation).ConfigureAwait(false);
-                    }
-                    var messageHaderSeq = buffer.Slice(buffer.Start, 10);
-                    messageHaderSeq.CopyTo(messageHeaderBytes);
-                    Singleton<SecsMessageHeaderDecoder>.Instance.DecodeHsmsHeader(messageHeaderBytes, out var header);
-                    buffer = buffer.Slice(messageHaderSeq.End);
-                    HsmsLogMamager.Instance.WriteReceivedBuffer("header buffer",messageHeaderBytes);
-
-                    if (messageLength > 10 && buffer.Length < messageLength - 10)
-                    {
-                        if (IsBufferInsufficient(_reader, ref buffer, (int)(messageLength - 10)))
-                        {
-                            buffer = await PipeReadAsync(_reader, (int)(messageLength - 10), cancellation).ConfigureAwait(false);
-                        }
-                    }
-
-                    if (messageLength == 10) // only message header
-                    {
-                        if (header.SType == SType.DataMessage)
-                        {
-                            SecsMessage secsMessage = new SecsMessage(header, null);
-                            AnalyseMessageEvent(secsMessage);
-                        }
-                        else
-                        {
-                            if ((byte)header.SType % 2 == 0)
-                            {
-                                SecsMessage replyMessage = new SecsMessage(header, null);
-                                ReplyMessageEvent(replyMessage);
-                            }
-                            else if (header.SType == SType.SelectRequest)
-                            {
-                                HsmsLogMamager.Instance.Info("received host selected request");
-                                SendSelectResponse(SType.SelectResponse, header.TransactionId);
-                            }
-                        }
-                    }
-                    //存在Item数据
-                    else if (buffer.Length >= messageLength - 10)
-                    {
-                        var dataBuffer= new byte[messageLength-10];
-                        var dataSeq = buffer.Slice(buffer.Start, messageLength-10);
-                        dataSeq.CopyTo(dataBuffer);
-
-                        HsmsLogMamager.Instance.WriteReceivedBuffer("data item buffer", messageHeaderBytes);
-                        int startIndex = 0;
-                        Item item = null;
-                        try
-                        {
-                            item = ItemDecoder.Decode(dataBuffer, ref startIndex);
-                            if (item == null)
-                            {
-                                Dispose();
-                                break;
-                            }
-                        }
-                        catch (Exception ex)
-                        {
-                            HsmsLogMamager.Instance.Error("DecodeLoopAsync decode item error", ex);
-                            Dispose();
-                            break;
-                        }
-                        SecsMessage secsMessage = new SecsMessage(header, item);
-                        
-                        buffer = buffer.Slice(dataSeq.End);
-                        if (header.SType == SType.DataMessage)
-                        {
-                            if(header.Function % 2 == 0)//回复指令
-                            {
-                                ReplyMessageEvent(secsMessage);
-                            }
-                            else//Host主动指令
-                            {
-                                AnalyseMessageEvent(secsMessage);
-                            }
-                        }
-                    }
-                }
-                catch (Exception ex)
-                {
-                    HsmsLogMamager.Instance.Error("DecodeLoopAsync error", ex);
-                    Dispose();
-                    break;
-                }
-            }
-        }
-
-        /// <summary>
-        /// 数组不足
-        /// </summary>
-        /// <param name="reader"></param>
-        /// <param name="remainedBuffer"></param>
-        /// <param name="required"></param>
-        /// <returns></returns>
-        private bool IsBufferInsufficient(PipeReader reader, ref ReadOnlySequence<byte> remainedBuffer, int required)
-        {
-            if (remainedBuffer.Length >= required)
-            {
-                return false;
-            }
-
-            reader.AdvanceTo(remainedBuffer.Start);
-            return !PipeTryRead(reader, required, ref remainedBuffer);
-        }
-
-        //管道尝试读取
-        private bool PipeTryRead(PipeReader reader, int required, ref ReadOnlySequence<byte> buffer)
-        {
-            if (reader.TryRead(out var result))
-            {
-                buffer = result.Buffer;
-                if (buffer.Length >= required)
-                {
-                    return true;
-                }
-                else
-                {
-                    reader.AdvanceTo(consumed: buffer.Start, examined: buffer.End);
-                }
-            }
-            return false;
-        }
-        //管道读取缓存
-        private ValueTask<ReadOnlySequence<byte>> PipeReadAsync(PipeReader reader, int required, CancellationToken cancellation)
-        {
-            ReadOnlySequence<byte> buffer = ReadOnlySequence<byte>.Empty;
-            if (PipeTryRead(reader, required, ref buffer))
-            {
-                return new ValueTask<ReadOnlySequence<byte>>(buffer);
-            }
-
-            return SlowPipeReadAsync(reader, required, cancellation);
-        }
-        /// <summary>
-        /// 阻塞读取超出长度
-        /// </summary>
-        /// <param name="reader"></param>
-        /// <param name="required"></param>
-        /// <param name="cancellation"></param>
-        /// <returns></returns>
-        async ValueTask<ReadOnlySequence<byte>> SlowPipeReadAsync(PipeReader reader, int required, CancellationToken cancellation)
-        {
-            while (true)
-            {
-                var result = await reader.ReadAsync(cancellation).ConfigureAwait(false);
-                var buffer = result.Buffer;
-
-                if (buffer.Length >= required)
-                {
-                    return buffer;
-                }
-                reader.AdvanceTo(consumed: buffer.Start, examined: buffer.End);
-            }
-        }
-        /// <summary>
-        /// 发送状态select回复
-        /// </summary>
-        /// <param name="msgType"></param>
-        /// <param name="id"></param>
-        private void SendSelectResponse(SType msgType,int id)
-        {
-            SecsMessage secsMessage = SecsReplyMessageFactory.CreateSelectedReplyMessage(id);
-            if(OnSendResponse!=null)
-            {
-                OnSendResponse(this,secsMessage);
-            }
-
-        }
-        /// <summary>
-        /// 接收到回复消息
-        /// </summary>
-        /// <param name="secsMessage"></param>
-        private void ReplyMessageEvent(SecsMessage secsMessage)
-        {
-            if (OnReplyMessageEventHandler != null)
-            {
-                OnReplyMessageEventHandler(secsMessage.Header.TransactionId, secsMessage);
-            }
-        }
-        /// <summary>
-        /// 发送消息
-        /// </summary>
-        /// <param name="secsMessage"></param>
-        private void SendMessageEvent(SecsMessage secsMessage)
-        {
-            if (OnSendMessageEventHandler != null)
-            {
-                OnSendMessageEventHandler(secsMessage.Header.TransactionId, secsMessage);
-            }
-        }
-        /// <summary>
-        /// 解析消息
-        /// </summary>
-        /// <param name="secsMessage"></param>
-        private void AnalyseMessageEvent(SecsMessage secsMessage)
-        {
-            HsmsLogMamager.Instance.WriteHostInfo(SmlSerializationUtil.SerializeItemToString(secsMessage));
-            try
-            {
-                SecsMessageValidator secsMessageValidator = ValidatorFactory.CreateValidator(secsMessage);
-                secsMessageValidator.DeviceId = GlobalData.DeviceId;
-                //判定消息格式 
-                ValidateType validateType = secsMessageValidator.Validate(secsMessage);
-                if (validateType == ValidateType.OK)
-                {
-                    if (OnAnalyseMessageEventHandler != null)//回调分析事件
-                    {
-                        OnAnalyseMessageEventHandler(secsMessage.Header.TransactionId, secsMessage);
-                    }
-                }
-                else//错误格式
-                {
-                    SecsMessage errorMessage = SecsReplyMessageFactory.CreateErrorMessageReply(validateType, secsMessage.Header);
-                    SendMessageEvent(errorMessage);
-                }
-            }
-            catch(Exception ex)
-            {
-                HsmsLogMamager.Instance.Error("AnalyseMessage error", ex);
-                Dispose();
-            }
-        }
-        /// <summary>
-        /// 释放资源
-        /// </summary>
-        private void Dispose()
-        {
-            if(OnDisConnection!=null)
-            {
-                OnDisConnection(this,"");
-            }
-        }
-    }
-}
+using Aitex.Core.Util;
+using SecsGem.Core;
+using SecsGem.Core.EnumData;
+using SecsGem.Core.ItemModel;
+using SecsGem.Core.Utility;
+using SecsGem.Core.Validator;
+using System;
+using System.Buffers;
+using System.Buffers.Binary;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO.Pipelines;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Runtime.Remoting.Channels;
+using System.Runtime.Remoting.Messaging;
+using System.Text;
+using System.Threading;
+using System.Threading.Channels;
+using System.Threading.Tasks;
+
+namespace SecsGem.Hsms.Core
+{
+    public class PipeDecoder
+    {
+        private readonly PipeReader _reader;
+        public PipeWriter Input { get; }
+
+        public event EventHandler<SecsMessage> OnSendResponse;
+
+        public event DelegateEvent.MessageEventHander OnAnalyseMessageEventHandler;
+
+        public event DelegateEvent.MessageEventHander OnSendMessageEventHandler;
+
+        public event DelegateEvent.MessageEventHander OnReplyMessageEventHandler;
+
+        public event EventHandler<string> OnDisConnection;
+
+        public PipeDecoder(PipeReader reader, PipeWriter input,CancellationToken cancellationToken)
+        {
+            _reader = reader;
+            Input = input;
+        }
+
+        public Task StartAsync(CancellationToken cancellation)
+        => DecodeLoopAsync(cancellation);
+
+
+        private async Task DecodeLoopAsync(
+            CancellationToken cancellation)
+        {
+            var totalLengthBytes = new byte[4];
+            var messageHeaderBytes = new byte[10];
+            // PipeReader peek first
+            ReadOnlySequence<byte> buffer = new ReadOnlySequence<byte>() ;
+            try
+            {
+                buffer = await PipeReadAsync(_reader, required: 4, cancellation).ConfigureAwait(false);
+            }
+            catch(Exception ex)
+            {
+                HsmsLogMamager.Instance.Error("PipeReadAsync error", ex);
+                Dispose();
+                return;
+            }
+            while (true)
+            {
+                try
+                {
+                    // 0: get total message length 4 bytes
+                    if (IsBufferInsufficient(_reader, ref buffer, required: 4))
+                    {
+                        buffer = await PipeReadAsync(_reader, required: 4, cancellation).ConfigureAwait(false);
+                    }
+                    var totalLengthSeq = buffer.Slice(buffer.Start, 4);
+                    totalLengthSeq.CopyTo(totalLengthBytes);
+                    uint messageLength = BinaryPrimitives.ReadUInt32BigEndian(totalLengthBytes);
+                    buffer = buffer.Slice(totalLengthSeq.End);
+                    HsmsLogMamager.Instance.WriteReceivedBuffer("length buffer",totalLengthBytes);
+
+                    // 1: get message header 10 bytes
+                    if (IsBufferInsufficient(_reader, ref buffer, required: 10))
+                    {
+                        buffer = await PipeReadAsync(_reader, required: 10, cancellation).ConfigureAwait(false);
+                    }
+                    var messageHaderSeq = buffer.Slice(buffer.Start, 10);
+                    messageHaderSeq.CopyTo(messageHeaderBytes);
+                    Singleton<SecsMessageHeaderDecoder>.Instance.DecodeHsmsHeader(messageHeaderBytes, out var header);
+                    buffer = buffer.Slice(messageHaderSeq.End);
+                    HsmsLogMamager.Instance.WriteReceivedBuffer("header buffer",messageHeaderBytes);
+
+                    if (messageLength > 10 && buffer.Length < messageLength - 10)
+                    {
+                        if (IsBufferInsufficient(_reader, ref buffer, (int)(messageLength - 10)))
+                        {
+                            buffer = await PipeReadAsync(_reader, (int)(messageLength - 10), cancellation).ConfigureAwait(false);
+                        }
+                    }
+
+                    if (messageLength == 10) // only message header
+                    {
+                        if (header.SType == SType.DataMessage)
+                        {
+                            SecsMessage secsMessage = new SecsMessage(header, null);
+                            AnalyseMessageEvent(secsMessage);
+                        }
+                        else
+                        {
+                            if ((byte)header.SType % 2 == 0)
+                            {
+                                SecsMessage replyMessage = new SecsMessage(header, null);
+                                ReplyMessageEvent(replyMessage);
+                            }
+                            else if (header.SType == SType.SelectRequest)
+                            {
+                                HsmsLogMamager.Instance.Info("received host selected request");
+                                SendSelectResponse(header.TransactionId);
+                            }
+                            else if (header.SType == SType.LinkTestRequest)
+                            {
+                                HsmsLogMamager.Instance.Info("received host linktest request");
+                                SendLinkTestResponse(header.TransactionId);
+                            }
+                        }
+                    }
+                    //存在Item数据
+                    else if (buffer.Length >= messageLength - 10)
+                    {
+                        var dataBuffer= new byte[messageLength-10];
+                        var dataSeq = buffer.Slice(buffer.Start, messageLength-10);
+                        dataSeq.CopyTo(dataBuffer);
+
+                        HsmsLogMamager.Instance.WriteReceivedBuffer("data item buffer", messageHeaderBytes);
+                        int startIndex = 0;
+                        Item item = null;
+                        try
+                        {
+                            item = ItemDecoder.Decode(dataBuffer, ref startIndex);
+                            if (item == null)
+                            {
+                                Dispose();
+                                break;
+                            }
+                        }
+                        catch (Exception ex)
+                        {
+                            HsmsLogMamager.Instance.Error("DecodeLoopAsync decode item error", ex);
+                            Dispose();
+                            break;
+                        }
+                        SecsMessage secsMessage = new SecsMessage(header, item);
+                        
+                        buffer = buffer.Slice(dataSeq.End);
+                        if (header.SType == SType.DataMessage)
+                        {
+                            if(header.Function % 2 == 0)//回复指令
+                            {
+                                ReplyMessageEvent(secsMessage);
+                            }
+                            else//Host主动指令
+                            {
+                                AnalyseMessageEvent(secsMessage);
+                            }
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    HsmsLogMamager.Instance.Error("DecodeLoopAsync error", ex);
+                    Dispose();
+                    break;
+                }
+            }
+        }
+
+        /// <summary>
+        /// 数组不足
+        /// </summary>
+        /// <param name="reader"></param>
+        /// <param name="remainedBuffer"></param>
+        /// <param name="required"></param>
+        /// <returns></returns>
+        private bool IsBufferInsufficient(PipeReader reader, ref ReadOnlySequence<byte> remainedBuffer, int required)
+        {
+            if (remainedBuffer.Length >= required)
+            {
+                return false;
+            }
+
+            reader.AdvanceTo(remainedBuffer.Start);
+            return !PipeTryRead(reader, required, ref remainedBuffer);
+        }
+
+        //管道尝试读取
+        private bool PipeTryRead(PipeReader reader, int required, ref ReadOnlySequence<byte> buffer)
+        {
+            if (reader.TryRead(out var result))
+            {
+                buffer = result.Buffer;
+                if (buffer.Length >= required)
+                {
+                    return true;
+                }
+                else
+                {
+                    reader.AdvanceTo(consumed: buffer.Start, examined: buffer.End);
+                }
+            }
+            return false;
+        }
+        //管道读取缓存
+        private ValueTask<ReadOnlySequence<byte>> PipeReadAsync(PipeReader reader, int required, CancellationToken cancellation)
+        {
+            ReadOnlySequence<byte> buffer = ReadOnlySequence<byte>.Empty;
+            if (PipeTryRead(reader, required, ref buffer))
+            {
+                return new ValueTask<ReadOnlySequence<byte>>(buffer);
+            }
+
+            return SlowPipeReadAsync(reader, required, cancellation);
+        }
+        /// <summary>
+        /// 阻塞读取超出长度
+        /// </summary>
+        /// <param name="reader"></param>
+        /// <param name="required"></param>
+        /// <param name="cancellation"></param>
+        /// <returns></returns>
+        async ValueTask<ReadOnlySequence<byte>> SlowPipeReadAsync(PipeReader reader, int required, CancellationToken cancellation)
+        {
+            while (true)
+            {
+                var result = await reader.ReadAsync(cancellation).ConfigureAwait(false);
+                var buffer = result.Buffer;
+
+                if (buffer.Length >= required)
+                {
+                    return buffer;
+                }
+                reader.AdvanceTo(consumed: buffer.Start, examined: buffer.End);
+            }
+        }
+        /// <summary>
+        /// 发送状态select回复
+        /// </summary>
+        /// <param name="msgType"></param>
+        /// <param name="id"></param>
+        private void SendSelectResponse(int id)
+        {
+            SecsMessage secsMessage = SecsReplyMessageFactory.CreateSelectedReplyMessage(id);
+            if(OnSendResponse!=null)
+            {
+                OnSendResponse(this,secsMessage);
+            }
+        }
+        /// <summary>
+        /// 发送LinkTest回复
+        /// </summary>
+        /// <param name="id"></param>
+        private void SendLinkTestResponse(int id)
+        {
+            SecsMessage secsMessage = SecsReplyMessageFactory.CreateLinkTestReplyMessage(id);
+            if (OnSendResponse != null)
+            {
+                OnSendResponse(this, secsMessage);
+            }
+        }
+        /// <summary>
+        /// 接收到回复消息
+        /// </summary>
+        /// <param name="secsMessage"></param>
+        private void ReplyMessageEvent(SecsMessage secsMessage)
+        {
+            if (OnReplyMessageEventHandler != null)
+            {
+                OnReplyMessageEventHandler(secsMessage.Header.TransactionId, secsMessage);
+            }
+        }
+        /// <summary>
+        /// 发送消息
+        /// </summary>
+        /// <param name="secsMessage"></param>
+        private void SendMessageEvent(SecsMessage secsMessage)
+        {
+            if (OnSendMessageEventHandler != null)
+            {
+                OnSendMessageEventHandler(secsMessage.Header.TransactionId, secsMessage);
+            }
+        }
+        /// <summary>
+        /// 解析消息
+        /// </summary>
+        /// <param name="secsMessage"></param>
+        private void AnalyseMessageEvent(SecsMessage secsMessage)
+        {
+            HsmsLogMamager.Instance.WriteHostInfo(SmlSerializationUtil.SerializeItemToString(secsMessage));
+            try
+            {
+                SecsMessageValidator secsMessageValidator = ValidatorFactory.CreateValidator(secsMessage);
+                secsMessageValidator.DeviceId = GlobalData.DeviceId;
+                //判定消息格式 
+                ValidateType validateType = secsMessageValidator.Validate(secsMessage);
+                if (validateType == ValidateType.OK)
+                {
+                    if (OnAnalyseMessageEventHandler != null)//回调分析事件
+                    {
+                        OnAnalyseMessageEventHandler(secsMessage.Header.TransactionId, secsMessage);
+                    }
+                }
+                else//错误格式
+                {
+                    SecsMessage errorMessage = SecsReplyMessageFactory.CreateErrorMessageReply(validateType, secsMessage.Header);
+                    SendMessageEvent(errorMessage);
+                }
+            }
+            catch(Exception ex)
+            {
+                HsmsLogMamager.Instance.Error("AnalyseMessage error", ex);
+                Dispose();
+            }
+        }
+        /// <summary>
+        /// 释放资源
+        /// </summary>
+        private void Dispose()
+        {
+            if(OnDisConnection!=null)
+            {
+                OnDisConnection(this,"");
+            }
+        }
+    }
+}

+ 2 - 2
SecsGem.Hsms.Core/Properties/AssemblyInfo.cs

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
 //通过使用 "*",如下所示:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.6")]
-[assembly: AssemblyFileVersion("1.0.0.6")]
+[assembly: AssemblyVersion("1.0.0.7")]
+[assembly: AssemblyFileVersion("1.0.0.7")]