浏览代码

增加自动识别方法

xuwei 4 年之前
父节点
当前提交
dfd07c2fbc

+ 40 - 5
PLC/PLC_S/Core/PLC_S_Core.cs

@@ -14,7 +14,7 @@ namespace PLC_S
         {
             if (OracleString == null)
             {
-                INIHelper ini = INIHelper.IniFile($@"PLC_S_INI\PLC_S_S.ini");
+                INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_S.ini");
 
                 string ip = ini.Read("Oracle", "Server");
                 string port = ini.Read("Oracle", "Port");
@@ -83,7 +83,7 @@ namespace PLC_S
         public static PLC_S_S Get()
         {
             PLC_S_S plcs = new PLC_S_S();
-            INIHelper ini = INIHelper.IniFile($@"PLC_S_INI\PLC_S_S.ini");
+            INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_S.ini");
 
             plcs.PLCServiceType = ini.Read("PLCService", "PLCServiceType");
             plcs.AutoStart = ini.Read("PLCService", "AutoStart").ToBoolean();
@@ -101,7 +101,7 @@ namespace PLC_S
         }
         public static void Set(PLC_S_S plcs)
         {
-            INIHelper ini = INIHelper.IniFile($@"PLC_S_INI\PLC_S_S.ini");
+            INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_S.ini");
 
             ini.Write("PLCService", "PLCServiceType", plcs.PLCServiceType);
             ini.Write("PLCService", "AutoStart", plcs.AutoStart.ToString());
@@ -116,7 +116,7 @@ namespace PLC_S
         }
         public static void SetPort(int port)
         {
-            INIHelper ini = INIHelper.IniFile($@"PLC_S_INI\PLC_S_S.ini");
+            INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_S.ini");
 
             ini.Write("PLCService", "Port", port.ToString());
         }
@@ -133,7 +133,7 @@ namespace PLC_S
 
         public static MES_S Get()
         {
-            INIHelper ini = INIHelper.IniFile($@"PLC_S_INI\PLC_S_S.ini");
+            INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_S.ini");
             MES_S m = new MES_S();
             m.IP = ini.Read("iBOSS.MES", "IP");
             m.Port = ini.Read("iBOSS.MES", "Port").ToInt32();
@@ -149,6 +149,41 @@ namespace PLC_S
         }
     }
 
+    //xuwei add 2022-03-12
+    /// <summary>
+    /// 自动识别模块
+    /// </summary>
+    public class PLC_S_GA
+    {
+        public string PLC_IP;
+        public int PLC_PORT;
+
+        public string PLC_FLAG_CODE; //扫码结果
+        public string PLC_FLAG_CODENUM;
+
+        public string PLC_GOODSCODE_CODE; //产品型号
+        public string PLC_GOODSCODE_CODENUM;
+
+        public string PLC_BARCODE_CODE; //条码
+        public string PLC_BARCODE_CODENUM;
+
+        public string PLC_GOODSTYPE_CODE; //产品类型
+        public string PLC_GOODSTYPE_CODENUM;
+
+        public string PLC_SEMIREWORK_CODE; //半检返工
+        public string PLC_SEMIREWORK_CODENUM;
+
+        public string PLC_GOODSLEVEL_CODE; //产品等级
+        public string PLC_GOODSLEVEL_CODENUM;
+
+        public string PROCEDURE_ID; //工序ID
+        public string PROCEDURE_USERCODE; //工序工号
+        public string PROCEDURE_CHECKID; //工序验证ID
+
+        public string WORKSTATION_ID; //工位ID
+        public string WORKSTATION_NAME; //工位名称
+    }
+
     /// <summary>
     /// 产品型号、登记、高压标识
     /// </summary>

+ 7 - 4
PLC/PLC_S/Core/PLC_Server.cs

@@ -27,14 +27,17 @@ namespace PLC_S
 
             switch (PLC_S_S.PLCServiceType)
             {
+
+                //自动识别模块 xuwei add 2022-03-12=====================
+                case "GA":
+                    ServerSocket = new GoodsAuto();
+                    break;
+                //======================================================
+
                 // 产品型号
                 case "GC":
                     ServerSocket = new GoodsCode();
                     break;
-                //// 产品等级
-                //case "GL":
-                //    ServerSocket = new GoodsLevel();
-                //    break;
                 // 工序计件
                 case "PW":
                     ServerSocket = new PieceWork();

+ 3 - 0
PLC/PLC_S/PLC_S.csproj

@@ -39,6 +39,7 @@
     <Compile Include="Proxy\WCFProxy.cs" />
     <Compile Include="Proxy\WCFProxySetting.cs" />
     <Compile Include="Proxy\WorkPiece.cs" />
+    <Compile Include="ServerModel\GoodsAuto.cs" />
     <Compile Include="ServerModel\GoodsCode.cs" />
     <Compile Include="Core\IShowLog.cs" />
     <Compile Include="Core\PLC_S_Core.cs" />
@@ -72,6 +73,8 @@
     <Reference Include="System.ServiceModel" />
   </ItemGroup>
   <ItemGroup>
+    <None Include="PLC_S_INI\PLC_S_GA.ini" />
+    <None Include="PLC_S_INI\PLC_S_GC.ini" />
     <None Include="PLC_S_INI\PLC_S_PW.ini">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>

+ 28 - 0
PLC/PLC_S/PLC_S_INI/PLC_S_GA.ini

@@ -0,0 +1,28 @@
+;自动识别模块
+[GA01]
+PLC_IP=172.18.36.194
+PLC_PORT=102
+PLC_FLAG_CODE=D
+PLC_FLAG_CODENUM=
+;产品型号
+PLC_GOODSCODE_CODE=D
+PLC_GOODSCODE_CODENUM=
+;产品条码
+PLC_BARCODE_CODE=D
+PLC_BARCODE_CODENUM=
+;产品类型
+PLC_GOODSTYPE_CODE=D
+PLC_GOODSTYPE_CODENUM=
+;半检返工标识 0:正常,1:半检返工中, 2:半检返修 3:报废
+PLC_SEMIREWORK_CODE=D
+PLC_SEMIREWORK_CODENUM=
+;产品等级
+PLC_GOODSLEVEL_CODE=
+PLC_GOODSLEVEL_CODENUM=
+;工序
+PROCEDURE_ID=
+PROCEDURE_USERCODE=
+PROCEDURE_CHECKID=
+;工位
+WORKSTATION_ID=
+WORKSTATION_NAME=

+ 773 - 0
PLC/PLC_S/ServerModel/GoodsAuto.cs

@@ -0,0 +1,773 @@
+
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+
+using Curtain.DataAccess;
+using Curtain.Extension.ExObjectConvert;
+using Curtain.Extension.ExSystemData;
+using Curtain.Framework.Json;
+using Curtain.Helpers;
+using Curtain.Log;
+using Curtain.Net.Sockets.PLC;
+using Curtain.Net.Sockets.PLC.Model;
+using Curtain.Net.Sockets.PLC.Model.Siemens;
+using PLC_S.Proxy;
+
+namespace PLC_S.ServerModel
+{
+    /// <summary>
+    /// 自动返回产品型号等信息 xuwei add 2022-01-10
+    /// </summary>
+    public class GoodsAuto : SocketServer<SimpleSocketServerModel>, IShowFormLog, IWindowsServer
+    {
+        public Dictionary<string, PLC_S_GA> PLC_FLAGS = new Dictionary<string, PLC_S_GA>();
+        public const string M_NAME = "GA";
+        private MES_S _mes_s = null;
+
+        private readonly Logger logger = Logger.CreateLogger(M_NAME);
+        private readonly LogInfo logger_t = new LogInfo();
+        private readonly LogInfo logger_e = new LogInfo();
+
+        private bool _S_STOP = false;
+
+        public int Interval
+        {
+            get;
+            set;
+        }
+        public string EPTS_CODE
+        {
+            get;
+            set;
+        }
+        public GoodsAuto()
+        {
+            logger.FileExistDays = 30;
+            logger.FilePrefix = "";
+            logger.FileSuffix = M_NAME;
+            logger.LevelOneFile = true;
+            logger.FileNameWithoutDate = true;
+
+            logger_t.SubFolderFormat = "<name>";
+            logger_t.FileExistDays = 30;
+            logger_t.LevelOneFile = true;
+
+            logger_e.FileExistDays = 10;
+
+            this.Model.FormatType = CommandFormatType.StartStopChar;
+
+            this.ServerStarting += ServerSocket_ServerStarting;
+            this.ServerStarted += ServerSocket_ServerStarted;
+            this.ServerStoping += ServerSocket_ServerStoping;
+            this.ServerStoped += ServerSocket_ServerStoped;
+
+            this.ServerMessage += ServerSocket_ServerMessage;
+            this.Received += ServerSocket_Received;
+
+            _mes_s = MES_S.Get();
+        }
+
+        #region Server
+        public IFormLogShow FormLogShow
+        {
+            get;
+            set;
+        }
+
+        private void ServerSocket_ServerStarting(object sender, CancelEventArgs e)
+        {
+            try
+            {
+                _S_STOP = false;
+                logger.OutputTrace($"{M_NAME}_ServerStarting");
+            }
+            catch { }
+        }
+        private void ServerSocket_ServerStarted(object sender, EventArgs e)
+        {
+            try
+            {
+                _S_STOP = false;
+                logger.OutputTrace($"{M_NAME}_ServerStarted");
+            }
+            catch { }
+        }
+        private void ServerSocket_ServerStoping(object sender, CancelEventArgs e)
+        {
+            try
+            {
+                _S_STOP = false;
+                logger.OutputTrace($"{M_NAME}_ServerStoping");
+            }
+            catch { }
+        }
+        private void ServerSocket_ServerStoped(object sender, EventArgs e)
+        {
+            try
+            {
+                _S_STOP = false;
+                logger.OutputTrace($"{M_NAME}_ServerStoped");
+            }
+            catch { }
+        }
+        private void ServerSocket_ServerMessage(object sender, ServerMessageEventArgs e)
+        {
+            try
+            {
+                _S_STOP = false;
+                string message = e.ToString();
+                string cip = e?.Client?.IP;
+                if (e.Type == ServerMessageType.Debug)
+                {
+                    Logger.Debug(message, $"{M_NAME}-T[{cip}]", logger_t);
+                }
+                if (e.Type == ServerMessageType.Error)
+                {
+                    Logger.Error(e.Exception, message, $"{M_NAME}-E[{cip}]", logger_e);
+                }
+                if (e.Type == ServerMessageType.Trace)
+                {
+                    Logger.Trace(message, $"{M_NAME}-T[{cip}]", logger_t);
+                }
+                if (e.Type == ServerMessageType.Warning)
+                {
+                    Logger.Warn(message, $"{M_NAME}-E[{cip}]", logger_e);
+                }
+                FormLogShow?.ShowLog("ServerMessage=" + message);
+            }
+            catch { }
+        }
+        #endregion
+
+        /// <summary>
+        /// 返回产品型号
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void ServerSocket_Received(object sender, ReceiveSession e)
+        {
+            PLC_S_GA plc_s = null;
+            string cIP = e?.Client?.IP;
+            string logKeyT = $"{M_NAME}-T[{cIP}]";
+            string logKeyE = $"{M_NAME}-E[{cIP}]";
+
+            _S_STOP = false;
+
+            SocketClient<SiemensS7_1200Model> plc = null;
+            Logger LoggerT = null;
+            try
+            {
+                LoggerT = Logger.CreateLogger(logKeyT, logger_t);
+                lock (LoggerT)
+                {
+                    LoggerT.BeginTracking();
+
+                    string outputMessage = e.ToString();
+                    Logger.Trace(outputMessage, logKeyT, logger_t);
+                    FormLogShow?.ShowLog(outputMessage);
+
+                    #region 【必须】判断接收数据是否为空
+                    if (string.IsNullOrWhiteSpace(e.Content))
+                    {
+                        outputMessage = "接收数据为空";
+                        Logger.Warn(outputMessage, logKeyT, logger_t);
+                        Logger.Warn(outputMessage, logKeyE, logger_e);
+                        FormLogShow?.ShowLog(outputMessage);
+                        return;
+                    }
+                    #endregion
+
+                    #region 【必须】判断接收设备代码是否为空
+                    outputMessage = e.Content;
+                    Logger.Trace(outputMessage, logKeyT, logger_t);
+                    FormLogShow?.ShowLog(outputMessage);
+
+                    string[] c = e.Content.Split('#');
+                    string flag = null;
+                    if (c.Length > 0)
+                    {
+                        flag = c[0];
+                    }
+                    string barCode = null;
+                    if (c.Length > 1)
+                    {
+                        barCode = c[1];
+                    }
+
+                    if (string.IsNullOrWhiteSpace(flag))
+                    {
+                        outputMessage = $"[{e.Content}]接收设备代码为空";
+                        Logger.Warn(outputMessage, logKeyT, logger_t);
+                        Logger.Warn(outputMessage, logKeyE, logger_e);
+                        FormLogShow?.ShowLog(outputMessage);
+                        return;
+                    }
+                    #endregion
+
+                    #region 【必须】读取INI配置文件
+                    plc_s = GetPLC_S_GA(flag, e, logKeyE);
+                    if (plc_s == null)
+                    {
+                        outputMessage = $"[{e.Content}]设备代码[{flag}]未找到ini配置或有错误";
+                        Logger.Error(null, outputMessage, logKeyT, logger_t);
+                        Logger.Error(null, outputMessage, logKeyE, logger_e);
+                        FormLogShow?.ShowLog(outputMessage);
+                        return;
+                    }
+                    #endregion
+
+                    #region 【必须】建立PLC连接
+                    outputMessage = $"[{e.Content}]PLC_Connect={JsonHelper.FromObject(plc_s)}";
+                    Logger.Trace(outputMessage, logKeyT, logger_t);
+                    FormLogShow?.ShowLog(outputMessage);
+
+                    plc = new SocketClient<SiemensS7_1200Model>();
+                    plc.Connect(plc_s.PLC_IP, plc_s.PLC_PORT);
+                    PLCResult p_r;
+                    #endregion
+
+                    #region 【必须】判断接收条码格式是否正确
+                    if (string.IsNullOrWhiteSpace(barCode) ||
+                        barCode == "0" ||
+                        barCode.Length != 11 ||
+                        barCode.StartsWith("0") ||
+                        barCode.StartsWith("ERROR")
+                        )
+                    {
+                        outputMessage = $"[{e.Content}]接收条码格式错误";
+                        Logger.Warn(outputMessage, logKeyT, logger_t);
+                        Logger.Warn(outputMessage, logKeyE, logger_e);
+                        FormLogShow?.ShowLog(outputMessage);
+                        SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
+                        return;
+                    }
+                    #endregion
+
+                    #region 【可选】产品型号写入
+                    if (!string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODENUM))
+                    {
+                        string intCode = GetSeatCoverCode(barCode, e, logKeyE);
+                        if (intCode == null)
+                        {
+                            outputMessage = $"[{e.Content}]此条码[{barCode}]不存在";
+                            Logger.Warn(outputMessage, logKeyT, logger_t);
+                            Logger.Warn(outputMessage, logKeyE, logger_e);
+                            FormLogShow?.ShowLog(outputMessage);
+                            SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
+                            return;
+                        }
+                        outputMessage = $"[{e.Content}]产品条码={barCode}[{intCode}]";
+                        Logger.Trace(outputMessage, logKeyT, logger_t);
+                        FormLogShow?.ShowLog(outputMessage);
+                        if (string.IsNullOrWhiteSpace(intCode))
+                        {
+                            outputMessage = $"[{e.Content}]此条码[{barCode}]未设置型号代码";
+                            Logger.Error(null, outputMessage, logKeyT, logger_t);
+                            Logger.Error(null, outputMessage, logKeyE, logger_e);
+                            FormLogShow?.ShowLog(outputMessage);
+                            SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
+                            return;
+                        }
+                        outputMessage = $"[{e.Content}]SET_GOODSCODE=[{intCode}]{plc_s.PLC_GOODSCODE_CODE + plc_s.PLC_GOODSCODE_CODENUM}";
+                        Logger.Trace(outputMessage, logKeyT, logger_t);
+                        FormLogShow?.ShowLog(outputMessage);
+                        p_r = plc.Write<short>(plc_s.PLC_GOODSCODE_CODE, plc_s.PLC_GOODSCODE_CODENUM, (short)(intCode.ToInt32()));
+                        outputMessage = $"[{e.Content}]END_GOODSCODE=[{p_r}]{plc_s.PLC_GOODSCODE_CODE + plc_s.PLC_GOODSCODE_CODENUM}";
+                        Logger.Trace(outputMessage, logKeyT, logger_t);
+                        FormLogShow?.ShowLog(outputMessage);
+                    }
+                    #endregion
+
+                    #region 【可选】产品类型写入
+                    if (!string.IsNullOrEmpty(plc_s.PLC_GOODSTYPE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSTYPE_CODENUM))
+                    {
+                        Int16 goodsType = Convert.ToInt16(GetGoodsType(barCode, e, logKeyT));
+                        outputMessage = $"[{e.Content}]SET_GoodsType=[{goodsType}]{plc_s.PLC_GOODSTYPE_CODE + plc_s.PLC_GOODSTYPE_CODENUM}";
+                        Logger.Trace(outputMessage, logKeyT, logger_t);
+                        FormLogShow?.ShowLog(outputMessage);
+                        p_r = plc?.Write<short>(plc_s.PLC_GOODSTYPE_CODE, plc_s.PLC_GOODSTYPE_CODENUM, goodsType);
+                        outputMessage = $"[{e.Content}]END_GoodsType=[{p_r.ToString()}]{plc_s.PLC_GOODSTYPE_CODE + plc_s.PLC_GOODSTYPE_CODENUM}";
+                        Logger.Trace(outputMessage, logKeyT, logger_t);
+                        FormLogShow?.ShowLog(outputMessage);
+                    }
+                    #endregion
+
+                    #region 【可选】产品条码写入
+                    if (!string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODENUM))
+                    {
+                        outputMessage = $"[{e.Content}]SET_BarCode=[{barCode}]{plc_s.PLC_BARCODE_CODE + plc_s.PLC_BARCODE_CODENUM}";
+                        Logger.Trace(outputMessage, logKeyT, logger_t);
+                        FormLogShow?.ShowLog(outputMessage);
+                        p_r = plc.Write<string>(plc_s.PLC_BARCODE_CODE, plc_s.PLC_BARCODE_CODENUM, barCode);
+                        outputMessage = $"[{e.Content}]END_BarCode=[{p_r}]{plc_s.PLC_BARCODE_CODE + plc_s.PLC_BARCODE_CODENUM}";
+                        Logger.Trace(outputMessage, logKeyT, logger_t);
+                        FormLogShow?.ShowLog(outputMessage);
+                    }
+                    #endregion
+
+                    #region 【可选】半检返工标识写入
+                    if (!string.IsNullOrEmpty(plc_s.PLC_SEMIREWORK_CODE) && !string.IsNullOrEmpty(plc_s.PLC_SEMIREWORK_CODENUM))
+                    {
+                        Int16 goodsType = Convert.ToInt16(GetSemiReWork(barCode, e, logKeyT));
+                        outputMessage = $"[{e.Content}]SET_SemiRework=[{goodsType}]{plc_s.PLC_SEMIREWORK_CODE + plc_s.PLC_SEMIREWORK_CODENUM}";
+                        Logger.Trace(outputMessage, logKeyT, logger_t);
+                        FormLogShow?.ShowLog(outputMessage);
+                        p_r = plc?.Write<short>(plc_s.PLC_SEMIREWORK_CODE, plc_s.PLC_SEMIREWORK_CODENUM, goodsType);
+                        outputMessage = $"[{e.Content}]END_SemiRework=[{p_r.ToString()}]{plc_s.PLC_SEMIREWORK_CODE + plc_s.PLC_SEMIREWORK_CODENUM}";
+                        Logger.Trace(outputMessage, logKeyT, logger_t);
+                        FormLogShow?.ShowLog(outputMessage);
+                    }
+                    #endregion
+
+                    #region 【可选】产品等级写入
+                    if (!string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL_CODENUM))
+                    {
+                        Int16 goodsLevel = Convert.ToInt16(GetGoodsLevel(barCode, e, logKeyT));
+                        outputMessage = $"[{e.Content}]SET_GoodsLevel=[{goodsLevel}]{plc_s.PLC_GOODSLEVEL_CODE + plc_s.PLC_GOODSLEVEL_CODENUM}";
+                        Logger.Trace(outputMessage, logKeyT, logger_t);
+                        FormLogShow?.ShowLog(outputMessage);
+                        p_r = plc?.Write<short>(plc_s.PLC_GOODSLEVEL_CODE, plc_s.PLC_GOODSLEVEL_CODENUM, goodsLevel);
+                        outputMessage = $"[{e.Content}]END_GoodsLevel=[{p_r.ToString()}]{plc_s.PLC_GOODSLEVEL_CODE + plc_s.PLC_GOODSLEVEL_CODENUM}";
+                        Logger.Trace(outputMessage, logKeyT, logger_t);
+                        FormLogShow?.ShowLog(outputMessage);
+                    }
+                    #endregion
+
+                    #region 【可选】工序验证
+                    if (!string.IsNullOrEmpty(plc_s.PROCEDURE_CHECKID))
+                    {
+                        Int16 plc_flag = Convert.ToInt16(GetProcedureCheck(barCode, plc_s.PROCEDURE_CHECKID, e, logKeyT, logKeyE));
+                        SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
+                        return;
+                    }
+                    #endregion
+
+                    #region 【可选】工序计件
+                    if (!string.IsNullOrEmpty(plc_s.PROCEDURE_ID) && (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE) || !string.IsNullOrEmpty(plc_s.WORKSTATION_ID)) )
+                    {
+                        string p_id = GetFlowId(barCode, e, logKeyE);
+                        Int16 plc_flag = 0;
+                        if (p_id != plc_s.PROCEDURE_ID.ToString())
+                        {
+                            string userCode = "";
+
+                            //默认读取userCode
+                            if(!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE))
+                            {
+                                userCode = plc_s.PROCEDURE_USERCODE;
+                            }
+
+                            //优先从工位取userCode
+                            if (!string.IsNullOrEmpty(plc_s.WORKSTATION_ID))
+                            {
+                                userCode = GetUserCodeFromWorkStation(plc_s.WORKSTATION_ID, e, logKeyE);
+                                outputMessage = $"[{e.Content}]DB_UserCode=[{userCode}]";
+                                Logger.Trace(outputMessage, logKeyT, logger_t);
+                                FormLogShow?.ShowLog(outputMessage);
+                            }
+
+                            //工序计件
+                            string result = SmartDeviceProxy.Instance.Invoke<string>(
+                                p => p.AddWorkPieceByStatus3(
+                                    _mes_s.AccountCode,
+                                    userCode,
+                                    null,
+                                    Convert.ToInt32(plc_s.PROCEDURE_ID),
+                                    barCode,
+                                    null));
+
+                            outputMessage = $"[{e.Content}]MES_Result=[{result}]";
+                            Logger.Trace(outputMessage, logKeyT, logger_t);
+                            FormLogShow?.ShowLog(outputMessage);
+
+                            // 返回状态(成功、失败)
+                            if (result != "OK")
+                            {
+                                plc_flag = 3;
+                                if (result == "EE")
+                                {
+                                    plc_flag = 4;
+                                    outputMessage = $"MES服务端异常(详情参见MES端日志)";
+                                }
+                                else if (result == "EU-01")
+                                {
+                                    outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
+                                }
+                                else
+                                {
+                                    outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
+                                }
+                                Logger.Error(null, outputMessage, logKeyT, logger_t);
+                                Logger.Error(null, outputMessage, logKeyE, logger_e);
+                                FormLogShow?.ShowLog(outputMessage);
+                                SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
+                                return;
+                            }
+                        }
+                    }
+                    #endregion
+
+                    #region 【必须】写入PLC扫码结果 【1:通过,2:扫码异常,3:工序异常,0:复位】
+                    SendCode(plc_s, e, logKeyT, logKeyE, plc, 1);
+                    #endregion
+
+                }
+            }
+            catch (Exception ex)
+            {
+                FormLogShow?.ShowLog($"[{e.Content}]ERROR={ex.Message}");
+                if (plc_s != null)
+                {
+                    Logger.Error(ex, $"[{e.Content}]ERROR", logKeyT, logger_t);
+                    Logger.Error(ex, $"[{e.Content}]ERROR", logKeyE, logger_e);
+                    SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
+                }
+                else
+                {
+                    Logger.Error(ex, $"[{e.Content}]ERROR-NOFLAG", logKeyT, logger_t);
+                    Logger.Error(ex, $"[{e.Content}]ERROR-NOFLAG", logKeyE, logger_e);
+                }
+            }
+            finally
+            {
+                LoggerT?.EndTracking();
+                plc?.Disconnect();
+                plc?.Close();
+            }
+        }
+
+        private void SendCode(PLC_S_GA plc_s, ReceiveSession e, string loggerNameT, string loggerNameE, SocketClient<SiemensS7_1200Model> plc, short code)
+        {
+            try
+            {
+                string outputMessage = $"[{e.Content}]SET_FLAG_CODE=[{code}]{plc_s.PLC_FLAG_CODE + plc_s.PLC_FLAG_CODENUM}";
+                Logger.Trace(outputMessage, loggerNameT, logger_t);
+                FormLogShow?.ShowLog(outputMessage);
+                PLCResult p_r = plc?.Write<short>(plc_s.PLC_FLAG_CODE, plc_s.PLC_FLAG_CODENUM, (short)code);
+                outputMessage = $"[{e.Content}]SET_FLAG_CODE=[{p_r}]{plc_s.PLC_FLAG_CODE + plc_s.PLC_FLAG_CODENUM}";
+                Logger.Trace(outputMessage, loggerNameT, logger_t);
+                FormLogShow?.ShowLog(outputMessage);
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex, $"[{e.Content}]ERROR-SendCode", loggerNameT, logger_t);
+                Logger.Error(ex, $"[{e.Content}]ERROR-SendCode", loggerNameE, logger_e);
+                FormLogShow?.ShowLog($"[{e.Content}]ERROR-SendCode={ex.Message}");
+            }
+        }
+
+        private string GetGoodsCode(string barCode, ReceiveSession e, string loggerName)
+        {
+            try
+            {
+                using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
+                {
+                    string sqlStr = @"
+                        SELECT
+	                        G.GOODSCODE
+                        FROM
+	                        TP_PM_GROUTINGDAILYDETAIL GDD
+                        WHERE
+	                        GDD.BARCODE = :BARCODE
+                    ";
+                    object result = conn.ExecuteDatatable(sqlStr, new CDAParameter(":BARCODE", barCode));
+                    return result == null ? "" : result.ToString();
+                }
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsCode", loggerName, logger_e);
+                FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsCode={ex.Message}");
+                return null;
+            }
+        }
+
+        private string GetSeatCoverCode(string barCode, ReceiveSession e, string loggerName)
+        {
+            try
+            {
+                using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
+                {
+                    string sqlStr = @"
+                        SELECT
+	                        G.SEATCOVERCODE 
+                        FROM
+	                        TP_PM_GROUTINGDAILYDETAIL GDD
+	                        INNER JOIN TP_MST_GOODS G ON G.GOODSID = GDD.GOODSID 
+                        WHERE
+	                        GDD.BARCODE = :BARCODE
+                    ";
+                    object result = conn.ExecuteDatatable(sqlStr, new CDAParameter(":BARCODE", barCode));
+                    return result == null ? "" : result.ToString();
+                }
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex, $"[{e.Content}]ERROR-GetSeatCoverCode", loggerName, logger_e);
+                FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSeatCoverCode={ex.Message}");
+                return null;
+            }
+        }
+
+        private string GetGoodsType(string barCode, ReceiveSession e, string loggerName)
+        {
+            try
+            {
+                using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
+                {
+                    string sqlStr = @"
+                        SELECT
+	                        -- G.GOODSCODE,
+	                        -- G.SEATCOVERCODE,
+	                        CASE 
+                                WHEN T.GOODSTYPECODE = '001001001' THEN 2 --连体
+							    WHEN T.GOODSTYPECODE = '001001002' THEN 3 --分体
+							    WHEN T.GOODSTYPECODE = '001001003' THEN 1 --智能
+							    WHEN T.GOODSTYPECODE = '001001004' THEN 1 --智能高压
+							    ELSE 0 --其他
+						    END AS GOODSTYPE
+                        FROM
+	                        TP_PM_GROUTINGDAILYDETAIL GDD
+	                        INNER JOIN TP_MST_GOODS G ON G.GOODSID = GDD.GOODSID 
+	                        INNER JOIN TP_MST_GOODSTYPE T ON G.GOODSTYPEID = T.GOODSTYPEID
+                        WHERE
+	                        GDD.BARCODE = :BARCODE --'10006800247'
+                        ";
+                    string goodsType = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
+                    return goodsType;
+                }
+
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsType", loggerName, logger_e);
+                FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsType={ex.Message}");
+                return "0";
+            }
+        }
+
+        private string GetFlowId(string barCode, ReceiveSession e, string loggerName)
+        {
+            try
+            {
+                using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
+                {
+                    string sqlStr = @"
+                        SELECT
+	                        GDD.FLOWPROCEDUREID
+                        FROM
+	                        TP_PM_INPRODUCTION GDD
+                        WHERE
+	                        GDD.BARCODE = :BARCODE
+                    ";
+                    object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
+                    return result == null ? "0" : result.ToString();
+                }
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex, $"[{e.Content}]ERROR-GetFlowId", loggerName, logger_e);
+                FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetFlowId={ex.Message}");
+                return "0";
+            }
+        }
+
+        private string GetUserCodeFromWorkStation(string workStationId, ReceiveSession e, string loggerName)
+        {
+            try
+            {
+                using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
+                {
+                    string sqlStr = @"
+                        SELECT
+	                        T.USERCODE
+                        FROM
+	                        TP_MST_WORKSTATION T
+	                        INNER JOIN TP_MST_USER U ON U.USERCODE = T.USERCODE 
+                        WHERE
+	                        T.WORKSTATIONID = :WORKSTATIONID
+                    ";
+                    object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":WORKSTATIONID", workStationId));
+                    return result == null ? "0" : result.ToString();
+                }
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex, $"[{e.Content}]ERROR-GetUserCodeFromWorkStation", loggerName, logger_e);
+                FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetUserCodeFromWorkStation={ex.Message}");
+                return "0";
+            }
+
+        }
+        
+        private string GetSemiReWork(string barCode, ReceiveSession e, string loggerName)
+        {
+            try
+            {
+                using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
+                {
+                    string sqlStr = @"
+                        SELECT
+	                        P.ISREWORKFLAG 
+                        FROM
+	                        TP_PM_INPRODUCTION P
+                        WHERE
+	                        P.BARCODE = :BARCODE
+                    ";
+                    object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
+                    //返工标识(0:正常,1:半检返工中, 2:半检返修)
+                    //没找到记录表明产品报废写 3
+                    string resultFlag = "0";
+                    if(result !=null)
+                    {
+                        if (result.ToString() == "0") resultFlag = "1"; //正常
+                        if (result.ToString() == "1" || result.ToString() == "2") resultFlag = "2";//返工
+                    }
+                    else
+                    {
+                        resultFlag = "3";//报废
+                    }
+                    return resultFlag;
+                }
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex, $"[{e.Content}]ERROR-GetSemiReWork", loggerName, logger_e);
+                FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSemiReWork={ex.Message}");
+                return "0";
+            }
+
+        }
+
+        private string GetGoodsLevel(string barCode, ReceiveSession e, string loggerName)
+        {
+            try
+            {
+                using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
+                {
+                    string sqlStr = @"
+                        SELECT
+	                        GDD.GOODSLEVELTYPEID
+                        FROM
+	                        TP_PM_GROUTINGDAILYDETAIL GDD
+                        WHERE
+	                        GDD.BARCODE = :BARCODE
+                    ";
+                    object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":WORKSTATIONID", barCode));
+                    return result == null ? "0" : result.ToString();
+                }
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsLevel", loggerName, logger_e);
+                FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsLevel={ex.Message}");
+                return "0";
+            }
+
+        }
+
+        private string GetProcedureCheck(string barCode,string procedureId, ReceiveSession e, string loggerNameT, string loggerNameE)
+        {
+            try
+            {
+                using (IDataAccess dataAccess = PLC_S_DataAccess.GetDataAccess())
+                {
+                    CDAParameter[] parameters = new CDAParameter[]
+                    {
+                            new CDAParameter("in_procedureid", procedureId),
+                            new CDAParameter("in_barcode", barCode),
+                            new CDAParameter("out_errType",DataType.Int32, ParameterDirection.Output),
+                            new CDAParameter("out_errMsg",DataType.VarChar, 4000, ParameterDirection.Output),
+                            new CDAParameter("out_goodsID",DataType.Int32, ParameterDirection.Output),
+                            new CDAParameter("out_goodsCode",DataType.VarChar, 400, ParameterDirection.Output),
+                            new CDAParameter("out_goodsType",DataType.Int32, ParameterDirection.Output),
+                    };
+                    
+                    int ii = dataAccess.ExecuteSPNonQuery("PRO_PM_CheckBarcode_PLC", parameters);
+
+                    Int16 plc_flag = 0;
+                    if (!int.TryParse(parameters[2].Value + "", out int errtype))
+                    {
+                        errtype = 4;
+                    }
+                    // 其他情况显示MES异常
+                    if (errtype == 4)
+                    {
+                        plc_flag = 4;
+                    }
+                    else if (errtype == 0)
+                    {
+                        plc_flag = 1;
+                    }
+                    else // errtype == 1 || errtype == 2 || errtype == 3
+                    {
+                        // 无效条码,显示不可到达
+                        plc_flag = 3;
+                    }
+                    string outputMessage = $"[{e.Content}]MESSAGE=[{errtype}][{parameters[3].Value}]";
+                    Logger.Trace(outputMessage, loggerNameT, logger_t);
+                    FormLogShow?.ShowLog(outputMessage);
+                    return plc_flag.ToString();
+                }
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex, $"[{e.Content}]ERROR-GetProcedureCheck", loggerNameE, logger_e);
+                FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetProcedureCheck={ex.Message}");
+                return "0";
+            }
+        }
+
+        private PLC_S_GA GetPLC_S_GA(string flag, ReceiveSession e, string loggerName)
+        {
+            try
+            {
+                flag = M_NAME + flag;
+                if (PLC_FLAGS.ContainsKey(flag))
+                {
+                    return PLC_FLAGS[flag];
+                }
+                else
+                {
+                    PLC_S_GA plc_s = new PLC_S_GA();
+                    INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
+
+                    plc_s.PLC_IP = ini.Read(flag, "PLC_IP");
+                    plc_s.PLC_PORT = ini.Read(flag, "PLC_PORT").ToInt32();
+
+                    plc_s.PLC_FLAG_CODE = ini.Read(flag, "PLC_FLAG_CODE");
+                    plc_s.PLC_FLAG_CODENUM = ini.Read(flag, "PLC_FLAG_CODENUM");
+
+                    plc_s.PLC_GOODSCODE_CODE = ini.Read(flag, "PLC_GOODSCODE_CODE");
+                    plc_s.PLC_GOODSCODE_CODENUM = ini.Read(flag, "PLC_GOODSCODE_CODENUM");
+
+                    plc_s.PLC_GOODSTYPE_CODE = ini.Read(flag, "PLC_GOODSTYPE_CODE");
+                    plc_s.PLC_GOODSTYPE_CODENUM = ini.Read(flag, "PLC_GOODSTYPE_CODENUM");
+
+                    plc_s.PLC_SEMIREWORK_CODE = ini.Read(flag, "PLC_SEMIREWORK_CODE");
+                    plc_s.PLC_SEMIREWORK_CODENUM = ini.Read(flag, "PLC_SEMIREWORK_CODENUM");
+
+                    plc_s.PLC_GOODSLEVEL_CODE = ini.Read(flag, "PLC_GOODSLEVEL_CODE");
+                    plc_s.PLC_GOODSLEVEL_CODENUM = ini.Read(flag, "PLC_GOODSLEVEL_CODENUM");
+
+                    plc_s.PROCEDURE_ID = ini.Read(flag, "PROCEDURE_ID");
+                    plc_s.PROCEDURE_USERCODE = ini.Read(flag, "PROCEDURE_USERCODE");
+
+                    plc_s.WORKSTATION_ID = ini.Read(flag, "WORKSTATION_ID");
+                    plc_s.WORKSTATION_NAME = ini.Read(flag, "WORKSTATION_NAME");
+
+                    PLC_FLAGS.Add(flag, plc_s);
+                    return plc_s;
+                }
+            }
+            catch (Exception ex)
+            {
+                Logger.Error(ex, $"[{e.Content}]ERROR-GetPLC_S_GA", loggerName, logger_e);
+                FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetPLC_S_GA={ex.Message}");
+                return null;
+            }
+        }
+    }
+}

+ 1 - 1
PLC/PLC_S/ServerModel/GoodsCode.cs

@@ -323,7 +323,7 @@ namespace PLC_S.ServerModel
                 else
                 {
                     PLC_S_GC plc_s = new PLC_S_GC();
-                    INIHelper ini = INIHelper.IniFile($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
+                    INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
 
                     plc_s.IP = ini.Read(flag, "IP");
                     plc_s.Port = ini.Read(flag, "Port").ToInt32();

+ 0 - 334
PLC/PLC_S/ServerModel/GoodsLevel.cs

@@ -1,334 +0,0 @@
-
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-
-using Curtain.Core;
-using Curtain.DataAccess;
-using Curtain.Framework.Json;
-using Curtain.Helpers;
-using Curtain.Log;
-using Curtain.Net.Sockets.PLC;
-using Curtain.Net.Sockets.PLC.Model;
-using Curtain.Net.Sockets.PLC.Model.Melsec;
-
-namespace PLC_S.ServerModel
-{
-    /// <summary>
-    /// 返回产品型号等信息
-    /// </summary>
-    public class GoodsLevel : SocketServer<SimpleSocketServerModel>, IShowFormLog, IWindowsServer
-    {
-        public static Dictionary<string, PLC_S_GC> PLC_FLAGS = new Dictionary<string, PLC_S_GC>();
-        public const string M_NAME = "GL";
-
-        private readonly Logger logger = Logger.CreateLogger(M_NAME);
-        private readonly LogInfo logger_t = new LogInfo();
-        private readonly LogInfo logger_e = new LogInfo();
-
-        public GoodsLevel()
-        {
-            logger.FileExistDays = 30;
-            logger.FilePrefix = "";
-            logger.FileSuffix = M_NAME;
-            logger.LevelOneFile = true;
-            logger.FileNameWithoutDate = true;
-
-            logger_t.SubFolderFormat = "<name>";
-            logger_t.FileExistDays = 30;
-            logger_t.LevelOneFile = true;
-
-            logger_e.FileExistDays = 0;
-
-            this.Model.FormatType = CommandFormatType.StartStopChar;
-
-            this.ServerStarting += ServerSocket_ServerStarting;
-            this.ServerStarted += ServerSocket_ServerStarted;
-            this.ServerStoping += ServerSocket_ServerStoping;
-            this.ServerStoped += ServerSocket_ServerStoped;
-
-            this.ServerMessage += ServerSocket_ServerMessage;
-            this.Received += ServerSocket_Received;
-        }
-
-        #region Server
-        public IFormLogShow FormLogShow
-        {
-            get;
-            set;
-        }
-
-        private void ServerSocket_ServerStarting(object sender, CancelEventArgs e)
-        {
-            try
-            {
-                logger.OutputTrace($"{M_NAME}_ServerStarting");
-            }
-            catch { }
-        }
-        private void ServerSocket_ServerStarted(object sender, EventArgs e)
-        {
-            try
-            {
-                logger.OutputTrace($"{M_NAME}_ServerStarted");
-            }
-            catch { }
-        }
-        private void ServerSocket_ServerStoping(object sender, CancelEventArgs e)
-        {
-            try
-            {
-                logger.OutputTrace($"{M_NAME}_ServerStoping");
-            }
-            catch { }
-        }
-        private void ServerSocket_ServerStoped(object sender, EventArgs e)
-        {
-            try
-            {
-                logger.OutputTrace($"{M_NAME}_ServerStoped");
-            }
-            catch { }
-        }
-        #endregion
-
-        private void ServerSocket_ServerMessage(object sender, ServerMessageEventArgs e)
-        {
-            try
-            {
-                string message = e.ToString();
-                string cip = e?.Client?.IP;
-                if (e.Type == ServerMessageType.Debug)
-                {
-                    Logger.Debug(message, $"{M_NAME}-T[{cip}]", logger_t);
-                }
-                if (e.Type == ServerMessageType.Error)
-                {
-                    Logger.Error(e.Exception, message, $"{M_NAME}-E[{cip}]", logger_e);
-                }
-                if (e.Type == ServerMessageType.Trace)
-                {
-                    Logger.Trace(message, $"{M_NAME}-T[{cip}]", logger_t);
-                }
-                if (e.Type == ServerMessageType.Warning)
-                {
-                    Logger.Warn(message, $"{M_NAME}-E[{cip}]", logger_e);
-                }
-                FormLogShow?.ShowLog("ServerMessage=" + message);
-            }
-            catch { }
-        }
-
-        /// <summary>
-        /// 返回产品型号
-        /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="e"></param>
-        private void ServerSocket_Received(object sender, ReceiveSession e)
-        {
-            PLC_S_GC plc_s = null;
-            string cIP = e?.Client?.IP;
-            string logKeyT = $"{M_NAME}-T[{cIP}]";
-            string logKeyE = $"{M_NAME}-E[{cIP}]";
-            try
-            {
-                string outputMessage = e.ToString();
-                Logger.Trace(outputMessage, logKeyT, logger_t);
-                FormLogShow?.ShowLog(outputMessage);
-
-                if (string.IsNullOrWhiteSpace(e.Content))
-                {
-                    outputMessage = "接收数据为空";
-                    Logger.Warn(outputMessage, logKeyT, logger_t);
-                    Logger.Warn(outputMessage, logKeyE, logger_e);
-                    FormLogShow?.ShowLog(outputMessage);
-                    return;
-                }
-
-                outputMessage = e.Content;
-                Logger.Trace(outputMessage, logKeyT, logger_t);
-                FormLogShow?.ShowLog(outputMessage);
-
-                string[] c = e.Content.Split('#');
-                string flag = null;
-                if (c.Length > 0)
-                {
-                    flag = c[0];
-                }
-                string barcode = null;
-                if (c.Length > 1)
-                {
-                    barcode = c[1];
-                }
-
-                if (string.IsNullOrWhiteSpace(flag))
-                {
-                    outputMessage = $"[{e.Content}]接收设备代码为空";
-                    Logger.Warn(outputMessage, logKeyT, logger_t);
-                    Logger.Warn(outputMessage, logKeyE, logger_e);
-                    FormLogShow?.ShowLog(outputMessage);
-                    return;
-                }
-
-                plc_s = GetPLC_S_GL(flag, e, logKeyE);
-                if (plc_s == null)
-                {
-                    outputMessage = $"[{e.Content}]设备代码[{flag}]未找到ini配置或有错误";
-                    Logger.Error(null, outputMessage, logKeyT, logger_t);
-                    Logger.Error(null, outputMessage, logKeyE, logger_e);
-                    FormLogShow?.ShowLog(outputMessage);
-                    return;
-                }
-                outputMessage = $"[{e.Content}]{JsonHelper.FromObject(plc_s)}";
-                Logger.Trace(outputMessage, logKeyT, logger_t);
-                FormLogShow?.ShowLog(outputMessage);
-
-                if (string.IsNullOrWhiteSpace(barcode) || barcode == "0")
-                {
-                    outputMessage = $"[{e.Content}]接收条码为空";
-                    Logger.Warn(outputMessage, logKeyT, logger_t);
-                    Logger.Warn(outputMessage, logKeyE, logger_e);
-                    FormLogShow?.ShowLog(outputMessage);
-                    return;
-                }
-
-                DataRow codeRow = GetGoodsCodeLevel(barcode, e, logKeyE);
-                if (codeRow == null)
-                {
-                    outputMessage = $"[{e.Content}]此条码[{barcode}]不存在";
-                    Logger.Warn(outputMessage, logKeyT, logger_t);
-                    Logger.Warn(outputMessage, logKeyE, logger_e);
-                    FormLogShow?.ShowLog(outputMessage);
-                    SendError(plc_s, e, logKeyE);
-                    return;
-                }
-
-                string code = codeRow["goodscode"].ToString();
-                string intcode = codeRow["seatcovercode"].ToString();
-                string level = codeRow["goodslevel"].ToString();
-                string levelName = codeRow["goodslevelname"].ToString();
-
-                outputMessage = $"[{e.Content}]产品型号={code}[{intcode}] 等级={levelName}[{level}]";
-                Logger.Trace(outputMessage, logKeyT, logger_t);
-                FormLogShow?.ShowLog(outputMessage);
-
-                //if (string.IsNullOrWhiteSpace(intcode))
-                //{
-                //    outputMessage = $"[{e.Content}]此条码[{barcode}]未设置型号代码";
-                //    Logger.Error(null, outputMessage, logKeyT, logger_t);
-                //    Logger.Error(null, outputMessage, logKeyE, logger_e);
-                //    FormLogShow?.ShowLog(outputMessage);
-                //    SendError(plc_s, e, logKeyE);
-                //    return;
-                //}
-
-                using (SocketClient<MelsecA1EAsciiModel> plc = new SocketClient<MelsecA1EAsciiModel>())
-                {
-                    plc.Connect(plc_s.IP, plc_s.Port);
-                    plc.Write(plc_s.Add_Code, plc_s.Add_CodeNum, intcode.ToInt32());
-                }
-            }
-            catch (Exception ex)
-            {
-                FormLogShow?.ShowLog($"[{e.Content}]ERROR={ex.Message}");
-                if (plc_s != null)
-                {
-                    Logger.Error(ex, $"ERROR[{e.Content}]", logKeyE, logger_e);
-                    SendError(plc_s, e, logKeyE);
-                }
-                else
-                {
-                    Logger.Error(ex, $"ERROR-NOFLAG[{e.Content}]", logKeyE, logger_e);
-                }
-            }
-            finally
-            {
-                e.ReturnMessage("0000");
-            }
-        }
-
-        private void SendError(PLC_S_GC plc_s, ReceiveSession e, string loggerName)
-        {
-            try
-            {
-                using (SocketClient<MelsecA1EAsciiModel> plc = new SocketClient<MelsecA1EAsciiModel>())
-                {
-                    plc.Connect(plc_s.IP, plc_s.Port);
-                    plc.Write(plc_s.Add_Error[0], plc_s.Add_ErrorNum, 1);
-                }
-            }
-            catch (Exception ex)
-            {
-                //Logger.Error(ex, $"ERROR[{e.Content}]", $"{M_NAME}-E[{e?.Client?.IP}]", logger_e);
-                Logger.Error(ex, $"ERROR[{e.Content}]", loggerName, logger_e);
-                FormLogShow?.ShowLog("SendError=" + ex.Message);
-            }
-        }
-
-        private DataRow GetGoodsCodeLevel(string barcode, ReceiveSession e, string loggerName)
-        {
-            IDataAccess dataAccess = null;
-            try
-            {
-                dataAccess = PLC_S_DataAccess.GetDataAccess(e);
-
-                // TODO
-                string sqlString = "select g.goodscode, g.seatcovercode\n" +
-                "  from tp_pm_groutingdailydetail gdd\n" +
-                " inner join tp_mst_goods g\n" +
-                "    on g.goodsid = gdd.goodsid\n" +
-                " where gdd.barcode = :barcode";
-                DataTable dataTable = dataAccess.ExecuteDatatable(sqlString, new CDAParameter(":barcode", barcode));
-                if (dataTable.HasData())
-                {
-                    return dataTable.Rows[0];
-                }
-                return null;
-            }
-            catch (Exception ex)
-            {
-                //Logger.Error(ex, $"ERROR[{e.Content}]", $"{M_NAME}-E[{e?.Client?.IP}]", logger_e);
-                Logger.Error(ex, $"ERROR[{e.Content}]", loggerName, logger_e);
-                FormLogShow?.ShowLog("GetGoodsCode=" + ex.Message);
-                return null;
-            }
-            finally
-            {
-                dataAccess?.Close();
-            }
-        }
-
-        private PLC_S_GC GetPLC_S_GL(string flag, ReceiveSession e, string loggerName)
-        {
-            try
-            {
-                if (PLC_FLAGS.ContainsKey(flag))
-                {
-                    return PLC_FLAGS[flag];
-                }
-                else
-                {
-                    PLC_S_GC plc_s = new PLC_S_GC();
-                    INIHelper ini = INIHelper.IniFile($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
-
-                    plc_s.IP = ini.Read(flag, "IP");
-                    plc_s.Port = ini.Read(flag, "Port").ToInt32();
-                    plc_s.Add_Code = ini.Read(flag, "Add_Code");
-                    plc_s.Add_CodeNum = ini.Read(flag, "Add_CodeNum").ToInt32();
-                    plc_s.Add_Error = ini.Read(flag, "Add_Error");
-                    plc_s.Add_ErrorNum = ini.Read(flag, "Add_ErrorNum").ToInt32();
-                    //PLC_FLAGS.Add(flag, plc_s);
-                    return plc_s;
-                }
-            }
-            catch (Exception ex)
-            {
-                //Logger.Error(ex, $"ERROR[{e.Content}]", $"{M_NAME}-E[{e?.Client?.IP}]", logger_e);
-                Logger.Error(ex, $"ERROR[{e.Content}]", loggerName, logger_e);
-                FormLogShow?.ShowLog("GetPLC_S_GL=" + ex.Message);
-                return null;
-            }
-        }
-    }
-}

+ 3 - 3
PLC/PLC_S/ServerModel/PieceWork.cs

@@ -144,7 +144,7 @@ namespace PLC_S.ServerModel
                 {
                     string flag = "PW1201";
                     PLC_S_PW plc_s = new PLC_S_PW();
-                    INIHelper ini = INIHelper.IniFile($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
+                    INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
                     plc_s.IP = ini.Read(flag, "IP");
                     plc_s.Port = ini.Read(flag, "Port").ToInt32();
                     plc_s.Add_FlagCode = ini.Read(flag, "Add_FlagCode");
@@ -540,7 +540,7 @@ namespace PLC_S.ServerModel
                 else
                 {
                     PLC_S_GC plc_s = new PLC_S_GC();
-                    INIHelper ini = INIHelper.IniFile($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
+                    INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
 
                     plc_s.IP = ini.Read(flag, "IP");
                     plc_s.Port = ini.Read(flag, "Port").ToInt32();
@@ -575,7 +575,7 @@ namespace PLC_S.ServerModel
                 else
                 {
                     PLC_S_PW plc_s = new PLC_S_PW();
-                    INIHelper ini = INIHelper.IniFile($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
+                    INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
 
                     plc_s.P_ID = ini.Read(flag, "P_ID").ToInt32();
                     plc_s.USER_CDOE = ini.Read(flag, "USER_CDOE");

+ 3 - 1
PLC/PLC_WF/F_Main.cs

@@ -39,8 +39,10 @@ namespace PLC_WF
             dataTable.Columns.Add("name");
             dataTable.Columns.Add("description");
 
-            dataTable.Rows.Add("EPTS_GP", "打磨【房号+计件】", "");
+            //xuwei add 2022-03-12
+            dataTable.Rows.Add("GA", "[GA]自动", "自动识别模块");
 
+            dataTable.Rows.Add("EPTS_GP", "打磨【房号+计件】", "");
             dataTable.Rows.Add("PW", "工序计件", "工序自动计件的服务【】");
 
             cboPLCST.DisplayMember = "name";

+ 1 - 1
PLC/PLC_WF/PLC_WF.csproj

@@ -7,7 +7,7 @@
     <ProjectGuid>{81A93A07-94E1-4251-91D9-AB127E6E9226}</ProjectGuid>
     <OutputType>WinExe</OutputType>
     <RootNamespace>PLC_WF</RootNamespace>
-    <AssemblyName>DK.PLC.HGCZ1</AssemblyName>
+    <AssemblyName>DK.PLC.HGCZ3</AssemblyName>
     <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <Deterministic>true</Deterministic>