Explorar o código

修正自动对接点模型支持不操作PLC

xuwei %!s(int64=4) %!d(string=hai) anos
pai
achega
2cbf3be7e0
Modificáronse 1 ficheiros con 26 adicións e 8 borrados
  1. 26 8
      PLC/PLC_S/ServerModel/GoodsAuto.cs

+ 26 - 8
PLC/PLC_S/ServerModel/GoodsAuto.cs

@@ -219,13 +219,21 @@ namespace PLC_S.ServerModel
                     #endregion
 
                     #region 【必须】建立PLC连接
-                    outputMessage = $"[{e.Content}]PLC_Connect={JsonHelper.FromObject(plc_s)}";
-                    Logger.Trace(outputMessage, logKeyT, logger_t);
-                    FormLogShow?.ShowLog(outputMessage);
+                    if (!string.IsNullOrEmpty(plc_s.PLC_IP))
+                    {
+                        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);
+                        plc = new SocketClient<SiemensS7_1200Model>();
+                        plc.Connect(plc_s.PLC_IP, plc_s.PLC_PORT);
+                    }
+                    else
+                    {
+                        Logger.Trace("无PLC连接!", logKeyT, logger_t);
+                    }
                     PLCResult p_r;
+
                     #endregion
 
                     #region 【必须】判断接收条码格式是否正确
@@ -402,15 +410,25 @@ namespace PLC_S.ServerModel
                                 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);
+                                if (!string.IsNullOrEmpty(plc_s.PLC_FLAG_CODE) && !string.IsNullOrEmpty(plc_s.PLC_FLAG_CODENUM))
+                                {
+                                    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);
+                    #region 【可选】写入PLC扫码结果 【1:通过,2:扫码异常,3:工序异常,0:复位】
+                    if (!string.IsNullOrEmpty(plc_s.PLC_FLAG_CODE) && !string.IsNullOrEmpty(plc_s.PLC_FLAG_CODENUM))
+                    {
+                        SendCode(plc_s, e, logKeyT, logKeyE, plc, 1);
+                    }
+                    else
+                    {
+                        Logger.Trace("无PLC标识位执行成功!", logKeyT, logger_t);
+                    }
                     #endregion
 
                 }