GoodsAuto.cs 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using Curtain.DataAccess;
  7. using Curtain.Extension.ExObjectConvert;
  8. using Curtain.Extension.ExSystemData;
  9. using Curtain.Framework.Json;
  10. using Curtain.Helpers;
  11. using Curtain.Log;
  12. using Curtain.Net.Sockets.PLC;
  13. using Curtain.Net.Sockets.PLC.Model;
  14. using Curtain.Net.Sockets.PLC.Model.Siemens;
  15. using PLC_S.Proxy;
  16. namespace PLC_S.ServerModel
  17. {
  18. /// <summary>
  19. /// 自动返回产品型号等信息 xuwei add 2022-01-10
  20. /// </summary>
  21. public class GoodsAuto : SocketServer<SimpleSocketServerModel>, IShowFormLog, IWindowsServer
  22. {
  23. public Dictionary<string, PLC_S_GA> PLC_FLAGS = new Dictionary<string, PLC_S_GA>();
  24. public const string M_NAME = "GA";
  25. private MES_S _mes_s = null;
  26. private readonly Logger logger = Logger.CreateLogger(M_NAME);
  27. private readonly LogInfo logger_t = new LogInfo();
  28. private readonly LogInfo logger_e = new LogInfo();
  29. private bool _S_STOP = false;
  30. public int Interval
  31. {
  32. get;
  33. set;
  34. }
  35. public string EPTS_CODE
  36. {
  37. get;
  38. set;
  39. }
  40. public GoodsAuto()
  41. {
  42. logger.FileExistDays = 30;
  43. logger.FilePrefix = "";
  44. logger.FileSuffix = M_NAME;
  45. logger.LevelOneFile = true;
  46. logger.FileNameWithoutDate = true;
  47. logger_t.SubFolderFormat = "<name>";
  48. logger_t.FileExistDays = 30;
  49. logger_t.LevelOneFile = true;
  50. logger_e.FileExistDays = 10;
  51. this.Model.FormatType = CommandFormatType.StartStopChar;
  52. this.ServerStarting += ServerSocket_ServerStarting;
  53. this.ServerStarted += ServerSocket_ServerStarted;
  54. this.ServerStoping += ServerSocket_ServerStoping;
  55. this.ServerStoped += ServerSocket_ServerStoped;
  56. this.ServerMessage += ServerSocket_ServerMessage;
  57. this.Received += ServerSocket_Received;
  58. _mes_s = MES_S.Get();
  59. }
  60. #region Server
  61. public IFormLogShow FormLogShow
  62. {
  63. get;
  64. set;
  65. }
  66. private void ServerSocket_ServerStarting(object sender, CancelEventArgs e)
  67. {
  68. try
  69. {
  70. _S_STOP = false;
  71. logger.OutputTrace($"{M_NAME}_ServerStarting");
  72. }
  73. catch { }
  74. }
  75. private void ServerSocket_ServerStarted(object sender, EventArgs e)
  76. {
  77. try
  78. {
  79. _S_STOP = false;
  80. logger.OutputTrace($"{M_NAME}_ServerStarted");
  81. }
  82. catch { }
  83. }
  84. private void ServerSocket_ServerStoping(object sender, CancelEventArgs e)
  85. {
  86. try
  87. {
  88. _S_STOP = false;
  89. logger.OutputTrace($"{M_NAME}_ServerStoping");
  90. }
  91. catch { }
  92. }
  93. private void ServerSocket_ServerStoped(object sender, EventArgs e)
  94. {
  95. try
  96. {
  97. _S_STOP = false;
  98. logger.OutputTrace($"{M_NAME}_ServerStoped");
  99. }
  100. catch { }
  101. }
  102. private void ServerSocket_ServerMessage(object sender, ServerMessageEventArgs e)
  103. {
  104. try
  105. {
  106. _S_STOP = false;
  107. string message = e.ToString();
  108. string cip = e?.Client?.IP;
  109. if (e.Type == ServerMessageType.Debug)
  110. {
  111. Logger.Debug(message, $"{M_NAME}-T[{cip}]", logger_t);
  112. }
  113. if (e.Type == ServerMessageType.Error)
  114. {
  115. Logger.Error(e.Exception, message, $"{M_NAME}-E[{cip}]", logger_e);
  116. }
  117. if (e.Type == ServerMessageType.Trace)
  118. {
  119. Logger.Trace(message, $"{M_NAME}-T[{cip}]", logger_t);
  120. }
  121. if (e.Type == ServerMessageType.Warning)
  122. {
  123. Logger.Warn(message, $"{M_NAME}-E[{cip}]", logger_e);
  124. }
  125. FormLogShow?.ShowLog("ServerMessage=" + message);
  126. }
  127. catch { }
  128. }
  129. #endregion
  130. /// <summary>
  131. /// 返回产品型号
  132. /// </summary>
  133. /// <param name="sender"></param>
  134. /// <param name="e"></param>
  135. private void ServerSocket_Received(object sender, ReceiveSession e)
  136. {
  137. PLC_S_GA plc_s = null;
  138. string cIP = e?.Client?.IP;
  139. string logKeyT = $"{M_NAME}-T[{cIP}]";
  140. string logKeyE = $"{M_NAME}-E[{cIP}]";
  141. _S_STOP = false;
  142. SocketClient<SiemensS7_1200Model> plc = null;
  143. Logger LoggerT = null;
  144. try
  145. {
  146. LoggerT = Logger.CreateLogger(logKeyT, logger_t);
  147. lock (LoggerT)
  148. {
  149. LoggerT.BeginTracking();
  150. string outputMessage = e.ToString();
  151. Logger.Trace(outputMessage, logKeyT, logger_t);
  152. FormLogShow?.ShowLog(outputMessage);
  153. #region 【必须】判断接收数据是否为空
  154. if (string.IsNullOrWhiteSpace(e.Content))
  155. {
  156. outputMessage = "接收数据为空";
  157. Logger.Warn(outputMessage, logKeyT, logger_t);
  158. Logger.Warn(outputMessage, logKeyE, logger_e);
  159. FormLogShow?.ShowLog(outputMessage);
  160. return;
  161. }
  162. #endregion
  163. #region 【必须】判断接收设备代码是否为空
  164. outputMessage = e.Content;
  165. Logger.Trace(outputMessage, logKeyT, logger_t);
  166. FormLogShow?.ShowLog(outputMessage);
  167. string[] c = e.Content.Split('#');
  168. string flag = null;
  169. if (c.Length > 0)
  170. {
  171. flag = c[0];
  172. }
  173. string barCode = null;
  174. if (c.Length > 1)
  175. {
  176. barCode = c[1];
  177. }
  178. if (string.IsNullOrWhiteSpace(flag))
  179. {
  180. outputMessage = $"[{e.Content}]接收设备代码为空";
  181. Logger.Warn(outputMessage, logKeyT, logger_t);
  182. Logger.Warn(outputMessage, logKeyE, logger_e);
  183. FormLogShow?.ShowLog(outputMessage);
  184. return;
  185. }
  186. #endregion
  187. #region 【必须】读取INI配置文件
  188. plc_s = GetPLC_S_GA(flag, e, logKeyE);
  189. if (plc_s == null)
  190. {
  191. outputMessage = $"[{e.Content}]设备代码[{flag}]未找到ini配置或有错误";
  192. Logger.Error(null, outputMessage, logKeyT, logger_t);
  193. Logger.Error(null, outputMessage, logKeyE, logger_e);
  194. FormLogShow?.ShowLog(outputMessage);
  195. return;
  196. }
  197. #endregion
  198. #region 【必须】建立PLC连接
  199. outputMessage = $"[{e.Content}]PLC_Connect={JsonHelper.FromObject(plc_s)}";
  200. Logger.Trace(outputMessage, logKeyT, logger_t);
  201. FormLogShow?.ShowLog(outputMessage);
  202. plc = new SocketClient<SiemensS7_1200Model>();
  203. plc.Connect(plc_s.PLC_IP, plc_s.PLC_PORT);
  204. PLCResult p_r;
  205. #endregion
  206. #region 【必须】判断接收条码格式是否正确
  207. if (string.IsNullOrWhiteSpace(barCode) ||
  208. barCode == "0" ||
  209. barCode.Length != 11 ||
  210. barCode.StartsWith("0") ||
  211. barCode.StartsWith("ERROR")
  212. )
  213. {
  214. outputMessage = $"[{e.Content}]接收条码格式错误";
  215. Logger.Warn(outputMessage, logKeyT, logger_t);
  216. Logger.Warn(outputMessage, logKeyE, logger_e);
  217. FormLogShow?.ShowLog(outputMessage);
  218. SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
  219. return;
  220. }
  221. #endregion
  222. #region 【可选】产品型号写入
  223. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSCODE_CODENUM))
  224. {
  225. string intCode = GetSeatCoverCode(barCode, e, logKeyE);
  226. if (intCode == null)
  227. {
  228. outputMessage = $"[{e.Content}]此条码[{barCode}]不存在";
  229. Logger.Warn(outputMessage, logKeyT, logger_t);
  230. Logger.Warn(outputMessage, logKeyE, logger_e);
  231. FormLogShow?.ShowLog(outputMessage);
  232. SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
  233. return;
  234. }
  235. outputMessage = $"[{e.Content}]产品条码={barCode}[{intCode}]";
  236. Logger.Trace(outputMessage, logKeyT, logger_t);
  237. FormLogShow?.ShowLog(outputMessage);
  238. if (string.IsNullOrWhiteSpace(intCode))
  239. {
  240. outputMessage = $"[{e.Content}]此条码[{barCode}]未设置型号代码";
  241. Logger.Error(null, outputMessage, logKeyT, logger_t);
  242. Logger.Error(null, outputMessage, logKeyE, logger_e);
  243. FormLogShow?.ShowLog(outputMessage);
  244. SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
  245. return;
  246. }
  247. outputMessage = $"[{e.Content}]SET_GOODSCODE=[{intCode}]{plc_s.PLC_GOODSCODE_CODE + plc_s.PLC_GOODSCODE_CODENUM}";
  248. Logger.Trace(outputMessage, logKeyT, logger_t);
  249. FormLogShow?.ShowLog(outputMessage);
  250. p_r = plc.Write<short>(plc_s.PLC_GOODSCODE_CODE, plc_s.PLC_GOODSCODE_CODENUM, (short)(intCode.ToInt32()));
  251. outputMessage = $"[{e.Content}]END_GOODSCODE=[{p_r}]{plc_s.PLC_GOODSCODE_CODE + plc_s.PLC_GOODSCODE_CODENUM}";
  252. Logger.Trace(outputMessage, logKeyT, logger_t);
  253. FormLogShow?.ShowLog(outputMessage);
  254. }
  255. #endregion
  256. #region 【可选】产品类型写入
  257. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSTYPE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSTYPE_CODENUM))
  258. {
  259. Int16 goodsType = Convert.ToInt16(GetGoodsType(barCode, e, logKeyT));
  260. outputMessage = $"[{e.Content}]SET_GoodsType=[{goodsType}]{plc_s.PLC_GOODSTYPE_CODE + plc_s.PLC_GOODSTYPE_CODENUM}";
  261. Logger.Trace(outputMessage, logKeyT, logger_t);
  262. FormLogShow?.ShowLog(outputMessage);
  263. p_r = plc?.Write<short>(plc_s.PLC_GOODSTYPE_CODE, plc_s.PLC_GOODSTYPE_CODENUM, goodsType);
  264. outputMessage = $"[{e.Content}]END_GoodsType=[{p_r.ToString()}]{plc_s.PLC_GOODSTYPE_CODE + plc_s.PLC_GOODSTYPE_CODENUM}";
  265. Logger.Trace(outputMessage, logKeyT, logger_t);
  266. FormLogShow?.ShowLog(outputMessage);
  267. }
  268. #endregion
  269. #region 【可选】产品下线写入 2023-05-19
  270. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSDISABLED_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSDISABLED_CODENUM))
  271. {
  272. Int16 goodsDisabled = Convert.ToInt16(GetGoodsDisabled(barCode, e, logKeyT));
  273. outputMessage = $"[{e.Content}]SET_GoodsDisabled=[{goodsDisabled}]{plc_s.PLC_GOODSDISABLED_CODE + plc_s.PLC_GOODSDISABLED_CODENUM}";
  274. Logger.Trace(outputMessage, logKeyT, logger_t);
  275. FormLogShow?.ShowLog(outputMessage);
  276. p_r = plc?.Write<short>(plc_s.PLC_GOODSDISABLED_CODE, plc_s.PLC_GOODSDISABLED_CODENUM, goodsDisabled);
  277. outputMessage = $"[{e.Content}]END_GoodsDisabled=[{p_r.ToString()}]{plc_s.PLC_GOODSDISABLED_CODE + plc_s.PLC_GOODSDISABLED_CODENUM}";
  278. Logger.Trace(outputMessage, logKeyT, logger_t);
  279. FormLogShow?.ShowLog(outputMessage);
  280. }
  281. #endregion
  282. #region 【可选】养水标识(用于三水厂) 2024-01-29
  283. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSWATER_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSWATER_CODENUM))
  284. {
  285. Int16 goodsWater = Convert.ToInt16(GetGoodsWater(barCode, e, logKeyT));
  286. outputMessage = $"[{e.Content}]SET_GoodsWater=[{goodsWater}]{plc_s.PLC_GOODSWATER_CODE + plc_s.PLC_GOODSWATER_CODENUM}";
  287. Logger.Trace(outputMessage, logKeyT, logger_t);
  288. FormLogShow?.ShowLog(outputMessage);
  289. p_r = plc?.Write<short>(plc_s.PLC_GOODSWATER_CODE, plc_s.PLC_GOODSWATER_CODENUM, goodsWater);
  290. outputMessage = $"[{e.Content}]END_GoodsWater=[{p_r.ToString()}]{plc_s.PLC_GOODSWATER_CODE + plc_s.PLC_GOODSWATER_CODENUM}";
  291. Logger.Trace(outputMessage, logKeyT, logger_t);
  292. FormLogShow?.ShowLog(outputMessage);
  293. }
  294. #endregion
  295. #region 【可选】产品型号#物料号写入(用于三水厂) 2023-05-19
  296. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSCODESKU_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSCODESKU_CODENUM))
  297. {
  298. Int16 goodsCodeSku = Convert.ToInt16(GetGoodsCodeSku(barCode, e, logKeyT));
  299. outputMessage = $"[{e.Content}]SET_GoodsCodeSku=[{goodsCodeSku}]{plc_s.PLC_GOODSCODESKU_CODE + plc_s.PLC_GOODSCODESKU_CODENUM}";
  300. Logger.Trace(outputMessage, logKeyT, logger_t);
  301. FormLogShow?.ShowLog(outputMessage);
  302. p_r = plc?.Write<short>(plc_s.PLC_GOODSCODESKU_CODE, plc_s.PLC_GOODSCODESKU_CODENUM, goodsCodeSku);
  303. outputMessage = $"[{e.Content}]END_GoodsDisabled=[{p_r.ToString()}]{plc_s.PLC_GOODSCODESKU_CODE + plc_s.PLC_GOODSCODESKU_CODENUM}";
  304. Logger.Trace(outputMessage, logKeyT, logger_t);
  305. FormLogShow?.ShowLog(outputMessage);
  306. }
  307. #endregion
  308. #region 【可选】产品补裂写入(用于三水厂) 2023-05-19
  309. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSBREAK_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSBREAK_CODENUM))
  310. {
  311. Int16 goodsBreak = Convert.ToInt16(GetGoodsBreak(barCode, e, logKeyT));
  312. outputMessage = $"[{e.Content}]SET_GoodsBreak=[{goodsBreak}]{plc_s.PLC_GOODSBREAK_CODE + plc_s.PLC_GOODSBREAK_CODENUM}";
  313. Logger.Trace(outputMessage, logKeyT, logger_t);
  314. FormLogShow?.ShowLog(outputMessage);
  315. p_r = plc?.Write<short>(plc_s.PLC_GOODSBREAK_CODE, plc_s.PLC_GOODSBREAK_CODENUM, goodsBreak);
  316. outputMessage = $"[{e.Content}]END_GoodsBreak=[{p_r.ToString()}]{plc_s.PLC_GOODSBREAK_CODE + plc_s.PLC_GOODSBREAK_CODENUM}";
  317. Logger.Trace(outputMessage, logKeyT, logger_t);
  318. FormLogShow?.ShowLog(outputMessage);
  319. }
  320. #endregion
  321. #region 【可选】成型线号写入(只写第3位,用于三水厂)
  322. if (!string.IsNullOrEmpty(plc_s.PLC_GROUTINGLINE3_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GROUTINGLINE3_CODENUM))
  323. {
  324. Int16 goodsType = Convert.ToInt16(GetGroutingLine3(barCode, e, logKeyT));
  325. outputMessage = $"[{e.Content}]SET_GROUTINGLINE3=[{goodsType}]{plc_s.PLC_GROUTINGLINE3_CODE + plc_s.PLC_GROUTINGLINE3_CODENUM}";
  326. Logger.Trace(outputMessage, logKeyT, logger_t);
  327. FormLogShow?.ShowLog(outputMessage);
  328. p_r = plc?.Write<short>(plc_s.PLC_GROUTINGLINE3_CODE, plc_s.PLC_GROUTINGLINE3_CODENUM, goodsType);
  329. outputMessage = $"[{e.Content}]END_GROUTINGLINE3=[{p_r.ToString()}]{plc_s.PLC_GROUTINGLINE3_CODE + plc_s.PLC_GROUTINGLINE3_CODENUM}";
  330. Logger.Trace(outputMessage, logKeyT, logger_t);
  331. FormLogShow?.ShowLog(outputMessage);
  332. }
  333. #endregion
  334. #region 【可选】产品条码写入
  335. if (!string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODE) && !string.IsNullOrEmpty(plc_s.PLC_BARCODE_CODENUM))
  336. {
  337. outputMessage = $"[{e.Content}]SET_BarCode=[{barCode}]{plc_s.PLC_BARCODE_CODE + plc_s.PLC_BARCODE_CODENUM}";
  338. Logger.Trace(outputMessage, logKeyT, logger_t);
  339. FormLogShow?.ShowLog(outputMessage);
  340. p_r = plc.Write<string>(plc_s.PLC_BARCODE_CODE, plc_s.PLC_BARCODE_CODENUM, barCode);
  341. outputMessage = $"[{e.Content}]END_BarCode=[{p_r}]{plc_s.PLC_BARCODE_CODE + plc_s.PLC_BARCODE_CODENUM}";
  342. Logger.Trace(outputMessage, logKeyT, logger_t);
  343. FormLogShow?.ShowLog(outputMessage);
  344. }
  345. #endregion
  346. #region 【可选】半检返工标识写入
  347. if (!string.IsNullOrEmpty(plc_s.PLC_SEMIREWORK_CODE) && !string.IsNullOrEmpty(plc_s.PLC_SEMIREWORK_CODENUM))
  348. {
  349. Int16 goodsType = Convert.ToInt16(GetSemiReWork(barCode, e, logKeyT));
  350. outputMessage = $"[{e.Content}]SET_SemiRework=[{goodsType}]{plc_s.PLC_SEMIREWORK_CODE + plc_s.PLC_SEMIREWORK_CODENUM}";
  351. Logger.Trace(outputMessage, logKeyT, logger_t);
  352. FormLogShow?.ShowLog(outputMessage);
  353. p_r = plc?.Write<short>(plc_s.PLC_SEMIREWORK_CODE, plc_s.PLC_SEMIREWORK_CODENUM, goodsType);
  354. outputMessage = $"[{e.Content}]END_SemiRework=[{p_r.ToString()}]{plc_s.PLC_SEMIREWORK_CODE + plc_s.PLC_SEMIREWORK_CODENUM}";
  355. Logger.Trace(outputMessage, logKeyT, logger_t);
  356. FormLogShow?.ShowLog(outputMessage);
  357. }
  358. #endregion
  359. #region 【可选】产品等级写入
  360. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSLEVEL_CODENUM))
  361. {
  362. Int16 goodsLevel = Convert.ToInt16(GetGoodsLevel(barCode, e, logKeyT));
  363. outputMessage = $"[{e.Content}]SET_GoodsLevel=[{goodsLevel}]{plc_s.PLC_GOODSLEVEL_CODE + plc_s.PLC_GOODSLEVEL_CODENUM}";
  364. Logger.Trace(outputMessage, logKeyT, logger_t);
  365. FormLogShow?.ShowLog(outputMessage);
  366. p_r = plc?.Write<short>(plc_s.PLC_GOODSLEVEL_CODE, plc_s.PLC_GOODSLEVEL_CODENUM, goodsLevel);
  367. outputMessage = $"[{e.Content}]END_GoodsLevel=[{p_r.ToString()}]{plc_s.PLC_GOODSLEVEL_CODE + plc_s.PLC_GOODSLEVEL_CODENUM}";
  368. Logger.Trace(outputMessage, logKeyT, logger_t);
  369. FormLogShow?.ShowLog(outputMessage);
  370. }
  371. #endregion
  372. #region 【可选】产品漏气合格写入
  373. if (!string.IsNullOrEmpty(plc_s.PLC_GOODSLEAKFLAG1_CODE) && !string.IsNullOrEmpty(plc_s.PLC_GOODSLEAKFLAG1_CODENUM))
  374. {
  375. Int16 goodsLeakFlag1 = Convert.ToInt16(GetGoodsLeakFlag1(barCode, e, logKeyT));
  376. outputMessage = $"[{e.Content}]SET_GoodsLeakFlag1=[{goodsLeakFlag1}]{plc_s.PLC_GOODSLEAKFLAG1_CODE + plc_s.PLC_GOODSLEAKFLAG1_CODENUM}";
  377. Logger.Trace(outputMessage, logKeyT, logger_t);
  378. FormLogShow?.ShowLog(outputMessage);
  379. p_r = plc?.Write<short>(plc_s.PLC_GOODSLEAKFLAG1_CODE, plc_s.PLC_GOODSLEAKFLAG1_CODENUM, goodsLeakFlag1);
  380. outputMessage = $"[{e.Content}]END_GoodsLeakFlag1=[{p_r.ToString()}]{plc_s.PLC_GOODSLEAKFLAG1_CODE + plc_s.PLC_GOODSLEAKFLAG1_CODENUM}";
  381. Logger.Trace(outputMessage, logKeyT, logger_t);
  382. FormLogShow?.ShowLog(outputMessage);
  383. }
  384. #endregion
  385. #region 【可选】工序验证
  386. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_CHECKID))
  387. {
  388. Int16 plc_flag = Convert.ToInt16(GetProcedureCheck(barCode, plc_s.PROCEDURE_CHECKID, e, logKeyT, logKeyE));
  389. SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
  390. return;
  391. }
  392. #endregion
  393. #region 【可选】工序计件
  394. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_ID) && (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE) || !string.IsNullOrEmpty(plc_s.WORKSTATION_ID)) )
  395. {
  396. string p_id = GetFlowId(barCode, e, logKeyE);
  397. Int16 plc_flag = 0;
  398. if (p_id != plc_s.PROCEDURE_ID.ToString())
  399. {
  400. string userCode = "";
  401. //默认读取userCode
  402. if(!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE))
  403. {
  404. userCode = plc_s.PROCEDURE_USERCODE;
  405. }
  406. //优先从工位取userCode
  407. if (!string.IsNullOrEmpty(plc_s.WORKSTATION_ID))
  408. {
  409. userCode = GetUserCodeFromWorkStation(plc_s.WORKSTATION_ID, e, logKeyE);
  410. outputMessage = $"[{e.Content}]DB_UserCode=[{userCode}]";
  411. Logger.Trace(outputMessage, logKeyT, logger_t);
  412. FormLogShow?.ShowLog(outputMessage);
  413. }
  414. //工序计件
  415. string result = SmartDeviceProxy.Instance.Invoke<string>(
  416. p => p.AddWorkPieceByStatus3(
  417. _mes_s.AccountCode,
  418. userCode,
  419. null,
  420. Convert.ToInt32(plc_s.PROCEDURE_ID),
  421. barCode,
  422. null));
  423. outputMessage = $"[{e.Content}]MES_Result=[{result}]";
  424. Logger.Trace(outputMessage, logKeyT, logger_t);
  425. FormLogShow?.ShowLog(outputMessage);
  426. // 返回状态(成功、失败)
  427. if (result != "OK")
  428. {
  429. plc_flag = 3;
  430. if (result == "EE")
  431. {
  432. plc_flag = 4;
  433. outputMessage = $"MES服务端异常(详情参见MES端日志)";
  434. }
  435. else if (result == "EU-01")
  436. {
  437. outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
  438. }
  439. else
  440. {
  441. outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
  442. }
  443. Logger.Error(null, outputMessage, logKeyT, logger_t);
  444. Logger.Error(null, outputMessage, logKeyE, logger_e);
  445. FormLogShow?.ShowLog(outputMessage);
  446. SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
  447. return;
  448. }
  449. }
  450. }
  451. #endregion
  452. #region 【可选】工序计件(计件第2工序,用于扫描1个点连续计件2道工序)
  453. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_ID2) && (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE2) || !string.IsNullOrEmpty(plc_s.WORKSTATION_ID2)))
  454. {
  455. string p_id = GetFlowId(barCode, e, logKeyE);
  456. Int16 plc_flag = 0;
  457. if (p_id != plc_s.PROCEDURE_ID2.ToString())
  458. {
  459. string userCode = "";
  460. //默认读取userCode
  461. if (!string.IsNullOrEmpty(plc_s.PROCEDURE_USERCODE2))
  462. {
  463. userCode = plc_s.PROCEDURE_USERCODE2;
  464. }
  465. //优先从工位取userCode
  466. if (!string.IsNullOrEmpty(plc_s.WORKSTATION_ID2))
  467. {
  468. userCode = GetUserCodeFromWorkStation(plc_s.WORKSTATION_ID2, e, logKeyE);
  469. outputMessage = $"[{e.Content}]DB_UserCode=[{userCode}]";
  470. Logger.Trace(outputMessage, logKeyT, logger_t);
  471. FormLogShow?.ShowLog(outputMessage);
  472. }
  473. //工序计件
  474. string result = SmartDeviceProxy.Instance.Invoke<string>(
  475. p => p.AddWorkPieceByStatus3(
  476. _mes_s.AccountCode,
  477. userCode,
  478. null,
  479. Convert.ToInt32(plc_s.PROCEDURE_ID2),
  480. barCode,
  481. null));
  482. outputMessage = $"[{e.Content}]MES_Result=[{result}]";
  483. Logger.Trace(outputMessage, logKeyT, logger_t);
  484. FormLogShow?.ShowLog(outputMessage);
  485. // 返回状态(成功、失败)
  486. if (result != "OK")
  487. {
  488. plc_flag = 3;
  489. if (result == "EE")
  490. {
  491. plc_flag = 4;
  492. outputMessage = $"MES服务端异常(详情参见MES端日志)";
  493. }
  494. else if (result == "EU-01")
  495. {
  496. outputMessage = $"无效的帐套或工号(详情参见MES端日志)";
  497. }
  498. else
  499. {
  500. outputMessage = $"其他错误(详情参见MES端日志)[{result}]";
  501. }
  502. Logger.Error(null, outputMessage, logKeyT, logger_t);
  503. Logger.Error(null, outputMessage, logKeyE, logger_e);
  504. FormLogShow?.ShowLog(outputMessage);
  505. SendCode(plc_s, e, logKeyT, logKeyE, plc, plc_flag);
  506. return;
  507. }
  508. }
  509. }
  510. #endregion
  511. #region 【必须】写入PLC扫码结果 【1:通过,2:扫码异常,3:工序异常,0:复位】
  512. SendCode(plc_s, e, logKeyT, logKeyE, plc, 1);
  513. #endregion
  514. }
  515. }
  516. catch (Exception ex)
  517. {
  518. FormLogShow?.ShowLog($"[{e.Content}]ERROR={ex.Message}");
  519. if (plc_s != null)
  520. {
  521. Logger.Error(ex, $"[{e.Content}]ERROR", logKeyT, logger_t);
  522. Logger.Error(ex, $"[{e.Content}]ERROR", logKeyE, logger_e);
  523. SendCode(plc_s, e, logKeyT, logKeyE, plc, 2);
  524. }
  525. else
  526. {
  527. Logger.Error(ex, $"[{e.Content}]ERROR-NOFLAG", logKeyT, logger_t);
  528. Logger.Error(ex, $"[{e.Content}]ERROR-NOFLAG", logKeyE, logger_e);
  529. }
  530. }
  531. finally
  532. {
  533. LoggerT?.EndTracking();
  534. plc?.Disconnect();
  535. plc?.Close();
  536. }
  537. }
  538. private void SendCode(PLC_S_GA plc_s, ReceiveSession e, string loggerNameT, string loggerNameE, SocketClient<SiemensS7_1200Model> plc, short code)
  539. {
  540. try
  541. {
  542. string outputMessage = $"[{e.Content}]SET_FLAG_CODE=[{code}]{plc_s.PLC_FLAG_CODE + plc_s.PLC_FLAG_CODENUM}";
  543. Logger.Trace(outputMessage, loggerNameT, logger_t);
  544. FormLogShow?.ShowLog(outputMessage);
  545. PLCResult p_r = plc?.Write<short>(plc_s.PLC_FLAG_CODE, plc_s.PLC_FLAG_CODENUM, (short)code);
  546. outputMessage = $"[{e.Content}]SET_FLAG_CODE=[{p_r}]{plc_s.PLC_FLAG_CODE + plc_s.PLC_FLAG_CODENUM}";
  547. Logger.Trace(outputMessage, loggerNameT, logger_t);
  548. FormLogShow?.ShowLog(outputMessage);
  549. }
  550. catch (Exception ex)
  551. {
  552. Logger.Error(ex, $"[{e.Content}]ERROR-SendCode", loggerNameT, logger_t);
  553. Logger.Error(ex, $"[{e.Content}]ERROR-SendCode", loggerNameE, logger_e);
  554. FormLogShow?.ShowLog($"[{e.Content}]ERROR-SendCode={ex.Message}");
  555. }
  556. }
  557. private string GetGoodsCode(string barCode, ReceiveSession e, string loggerName)
  558. {
  559. try
  560. {
  561. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  562. {
  563. string sqlStr = @"
  564. SELECT
  565. G.GOODSCODE
  566. FROM
  567. TP_PM_GROUTINGDAILYDETAIL GDD
  568. WHERE
  569. GDD.BARCODE = :BARCODE
  570. ";
  571. object result = conn.ExecuteDatatable(sqlStr, new CDAParameter(":BARCODE", barCode));
  572. return result == null ? "" : result.ToString();
  573. }
  574. }
  575. catch (Exception ex)
  576. {
  577. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsCode", loggerName, logger_e);
  578. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsCode={ex.Message}");
  579. return null;
  580. }
  581. }
  582. private string GetGroutingLine3(string barCode, ReceiveSession e, string loggerName)
  583. {
  584. try
  585. {
  586. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  587. {
  588. string sqlStr = @"
  589. SELECT
  590. SUBSTR(GDD.GROUTINGLINECODE,3,1) AS GROUTINGLINECODE
  591. FROM
  592. TP_PM_GROUTINGDAILYDETAIL GDD
  593. WHERE
  594. GDD.BARCODE = :BARCODE
  595. ";
  596. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  597. return result == null ? "" : result.ToString();
  598. }
  599. }
  600. catch (Exception ex)
  601. {
  602. Logger.Error(ex, $"[{e.Content}]ERROR-GetGroutingLine3", loggerName, logger_e);
  603. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGroutingLine3={ex.Message}");
  604. return null;
  605. }
  606. }
  607. private string GetSeatCoverCode(string barCode, ReceiveSession e, string loggerName)
  608. {
  609. try
  610. {
  611. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  612. {
  613. string sqlStr = @"
  614. SELECT
  615. G.SEATCOVERCODE
  616. FROM
  617. TP_PM_GROUTINGDAILYDETAIL GDD
  618. INNER JOIN TP_MST_GOODS G ON G.GOODSID = GDD.GOODSID
  619. WHERE
  620. GDD.BARCODE = :BARCODE
  621. ";
  622. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  623. return result == null ? "" : result.ToString();
  624. }
  625. }
  626. catch (Exception ex)
  627. {
  628. Logger.Error(ex, $"[{e.Content}]ERROR-GetSeatCoverCode", loggerName, logger_e);
  629. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSeatCoverCode={ex.Message}");
  630. return null;
  631. }
  632. }
  633. private string GetGoodsType(string barCode, ReceiveSession e, string loggerName)
  634. {
  635. try
  636. {
  637. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  638. {
  639. string sqlStr = @"
  640. SELECT
  641. -- G.GOODSCODE,
  642. -- G.SEATCOVERCODE,
  643. CASE
  644. WHEN T.GOODSTYPECODE = '001001001' THEN 2 --连体
  645. WHEN T.GOODSTYPECODE = '001001002' THEN 3 --分体
  646. WHEN T.GOODSTYPECODE = '001001003' THEN 1 --智能
  647. WHEN T.GOODSTYPECODE = '001001004' THEN 1 --智能高压
  648. ELSE 0 --其他
  649. END AS GOODSTYPE
  650. FROM
  651. TP_PM_GROUTINGDAILYDETAIL GDD
  652. INNER JOIN TP_MST_GOODS G ON G.GOODSID = GDD.GOODSID
  653. INNER JOIN TP_MST_GOODSTYPE T ON G.GOODSTYPEID = T.GOODSTYPEID
  654. WHERE
  655. GDD.BARCODE = :BARCODE --'10006800247'
  656. ";
  657. string goodsType = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  658. return goodsType;
  659. }
  660. }
  661. catch (Exception ex)
  662. {
  663. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsType", loggerName, logger_e);
  664. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsType={ex.Message}");
  665. return "0";
  666. }
  667. }
  668. private string GetGoodsDisabled(string barCode, ReceiveSession e, string loggerName)
  669. {
  670. try
  671. {
  672. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  673. {
  674. //判断单品下线
  675. string sqlStr = @"
  676. SELECT
  677. CASE WHEN GDD.OFFLINEFLAG = 0 AND OL.GOODSID IS NULL THEN 1 ELSE 2 END AS OFFLINEFLAG
  678. FROM
  679. TP_PM_GROUTINGDAILYDETAIL GDD
  680. LEFT JOIN TP_PM_OFFLINE OL ON GDD.GOODSID = OL.GOODSID
  681. WHERE
  682. GDD.BARCODE = :BARCODE --'10017193389'
  683. ";
  684. string goodsDisabled = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  685. return goodsDisabled;
  686. }
  687. }
  688. catch (Exception ex)
  689. {
  690. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsDisabled", loggerName, logger_e);
  691. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsDisabled={ex.Message}");
  692. return "0";
  693. }
  694. }
  695. private string GetGoodsWater(string barCode, ReceiveSession e, string loggerName)
  696. {
  697. try
  698. {
  699. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  700. {
  701. //取养水标识
  702. string sqlStr = @"
  703. SELECT
  704. NVL( GDD.LEAKFLAG4, 0 ) AS WATER
  705. FROM
  706. TP_PM_GROUTINGDAILYDETAIL GDD
  707. WHERE
  708. GDD.BARCODE = :BARCODE --'10016123244'
  709. ";
  710. string goodsWater = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  711. return goodsWater;
  712. }
  713. }
  714. catch (Exception ex)
  715. {
  716. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsWater", loggerName, logger_e);
  717. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsWater={ex.Message}");
  718. return "0";
  719. }
  720. }
  721. private string GetGoodsCodeSku(string barCode, ReceiveSession e, string loggerName)
  722. {
  723. try
  724. {
  725. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  726. {
  727. string sqlStr = @"
  728. SELECT
  729. GDD.GOODSCODE || '#' || GDD.MATERIALCODE
  730. FROM
  731. TP_PM_GROUTINGDAILYDETAIL GDD
  732. WHERE
  733. GDD.BARCODE = :BARCODE
  734. ";
  735. string goodsCodeSku = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  736. return goodsCodeSku;
  737. }
  738. }
  739. catch (Exception ex)
  740. {
  741. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsCodeSku", loggerName, logger_e);
  742. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsCodeSku={ex.Message}");
  743. return "0";
  744. }
  745. }
  746. private string GetGoodsBreak(string barCode, ReceiveSession e, string loggerName)
  747. {
  748. try
  749. {
  750. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess(e))
  751. {
  752. string sqlStr = @"
  753. SELECT
  754. LEAKFLAG6
  755. FROM
  756. TP_PM_GROUTINGDAILYDETAIL GDD
  757. WHERE
  758. GDD.BARCODE = :BARCODE
  759. ";
  760. string goodsBreak = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode)).ToString();
  761. if (goodsBreak == "0") goodsBreak = "2"; //补裂
  762. return goodsBreak;
  763. }
  764. }
  765. catch (Exception ex)
  766. {
  767. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsBreak", loggerName, logger_e);
  768. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsBreak={ex.Message}");
  769. return "0";
  770. }
  771. }
  772. private string GetFlowId(string barCode, ReceiveSession e, string loggerName)
  773. {
  774. try
  775. {
  776. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  777. {
  778. string sqlStr = @"
  779. SELECT
  780. GDD.FLOWPROCEDUREID
  781. FROM
  782. TP_PM_INPRODUCTION GDD
  783. WHERE
  784. GDD.BARCODE = :BARCODE
  785. ";
  786. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  787. return result == null ? "0" : result.ToString();
  788. }
  789. }
  790. catch (Exception ex)
  791. {
  792. Logger.Error(ex, $"[{e.Content}]ERROR-GetFlowId", loggerName, logger_e);
  793. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetFlowId={ex.Message}");
  794. return "0";
  795. }
  796. }
  797. private string GetUserCodeFromWorkStation(string workStationId, ReceiveSession e, string loggerName)
  798. {
  799. try
  800. {
  801. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  802. {
  803. string sqlStr = @"
  804. SELECT
  805. T.USERCODE
  806. FROM
  807. TP_MST_WORKSTATION T
  808. INNER JOIN TP_MST_USER U ON U.USERCODE = T.USERCODE
  809. WHERE
  810. T.WORKSTATIONID = :WORKSTATIONID
  811. ";
  812. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":WORKSTATIONID", workStationId));
  813. return result == null ? "0" : result.ToString();
  814. }
  815. }
  816. catch (Exception ex)
  817. {
  818. Logger.Error(ex, $"[{e.Content}]ERROR-GetUserCodeFromWorkStation", loggerName, logger_e);
  819. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetUserCodeFromWorkStation={ex.Message}");
  820. return "0";
  821. }
  822. }
  823. private string GetSemiReWork(string barCode, ReceiveSession e, string loggerName)
  824. {
  825. try
  826. {
  827. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  828. {
  829. string sqlStr = @"
  830. SELECT
  831. P.ISREWORKFLAG
  832. FROM
  833. TP_PM_INPRODUCTION P
  834. WHERE
  835. P.BARCODE = :BARCODE
  836. ";
  837. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  838. //返工标识(0:正常,1:半检返工中, 2:半检返修)
  839. //没找到记录表明产品报废写 3
  840. string resultFlag = "0";
  841. if(result !=null)
  842. {
  843. if (result.ToString() == "0") resultFlag = "1"; //正常
  844. if (result.ToString() == "1" || result.ToString() == "2") resultFlag = "2";//返工
  845. }
  846. else
  847. {
  848. resultFlag = "3";//报废
  849. }
  850. return resultFlag;
  851. }
  852. }
  853. catch (Exception ex)
  854. {
  855. Logger.Error(ex, $"[{e.Content}]ERROR-GetSemiReWork", loggerName, logger_e);
  856. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetSemiReWork={ex.Message}");
  857. return "0";
  858. }
  859. }
  860. private string GetGoodsLevel(string barCode, ReceiveSession e, string loggerName)
  861. {
  862. try
  863. {
  864. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  865. {
  866. string sqlStr = @"
  867. SELECT
  868. GDD.GOODSLEVELTYPEID
  869. FROM
  870. TP_PM_GROUTINGDAILYDETAIL GDD
  871. WHERE
  872. GDD.BARCODE = :BARCODE
  873. ";
  874. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  875. return result == null ? "0" : result.ToString();
  876. }
  877. }
  878. catch (Exception ex)
  879. {
  880. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsLevel", loggerName, logger_e);
  881. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsLevel={ex.Message}");
  882. return "0";
  883. }
  884. }
  885. private string GetGoodsLeakFlag1(string barCode, ReceiveSession e, string loggerName)
  886. {
  887. try
  888. {
  889. using (IDataAccess conn = PLC_S_DataAccess.GetDataAccess())
  890. {
  891. string sqlStr = @"
  892. SELECT
  893. DECODE(GDD.LEAKFLAG1,NULL,2,0,2,GDD.LEAKFLAG1)
  894. FROM
  895. TP_PM_GROUTINGDAILYDETAIL GDD
  896. WHERE
  897. GDD.BARCODE = :BARCODE
  898. ";
  899. object result = conn.ExecuteScalar(sqlStr, new CDAParameter(":BARCODE", barCode));
  900. return result == null ? "0" : result.ToString();
  901. }
  902. }
  903. catch (Exception ex)
  904. {
  905. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsLeakFlag1", loggerName, logger_e);
  906. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsLeakFlag1={ex.Message}");
  907. return "0";
  908. }
  909. }
  910. private string GetProcedureCheck(string barCode,string procedureId, ReceiveSession e, string loggerNameT, string loggerNameE)
  911. {
  912. try
  913. {
  914. using (IDataAccess dataAccess = PLC_S_DataAccess.GetDataAccess())
  915. {
  916. CDAParameter[] parameters = new CDAParameter[]
  917. {
  918. new CDAParameter("in_procedureid", procedureId),
  919. new CDAParameter("in_barcode", barCode),
  920. new CDAParameter("out_errType",DataType.Int32, ParameterDirection.Output),
  921. new CDAParameter("out_errMsg",DataType.VarChar, 4000, ParameterDirection.Output),
  922. new CDAParameter("out_goodsID",DataType.Int32, ParameterDirection.Output),
  923. new CDAParameter("out_goodsCode",DataType.VarChar, 400, ParameterDirection.Output),
  924. new CDAParameter("out_goodsType",DataType.Int32, ParameterDirection.Output),
  925. };
  926. int ii = dataAccess.ExecuteSPNonQuery("PRO_PM_CheckBarcode_PLC", parameters);
  927. Int16 plc_flag = 0;
  928. if (!int.TryParse(parameters[2].Value + "", out int errtype))
  929. {
  930. errtype = 4;
  931. }
  932. // 其他情况显示MES异常
  933. if (errtype == 4)
  934. {
  935. plc_flag = 4;
  936. }
  937. else if (errtype == 0)
  938. {
  939. plc_flag = 1;
  940. }
  941. else // errtype == 1 || errtype == 2 || errtype == 3
  942. {
  943. // 无效条码,显示不可到达
  944. plc_flag = 3;
  945. }
  946. string outputMessage = $"[{e.Content}]MESSAGE=[{errtype}][{parameters[3].Value}]";
  947. Logger.Trace(outputMessage, loggerNameT, logger_t);
  948. FormLogShow?.ShowLog(outputMessage);
  949. return plc_flag.ToString();
  950. }
  951. }
  952. catch (Exception ex)
  953. {
  954. Logger.Error(ex, $"[{e.Content}]ERROR-GetProcedureCheck", loggerNameE, logger_e);
  955. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetProcedureCheck={ex.Message}");
  956. return "0";
  957. }
  958. }
  959. private PLC_S_GA GetPLC_S_GA(string flag, ReceiveSession e, string loggerName)
  960. {
  961. try
  962. {
  963. flag = M_NAME + flag;
  964. if (PLC_FLAGS.ContainsKey(flag))
  965. {
  966. return PLC_FLAGS[flag];
  967. }
  968. else
  969. {
  970. PLC_S_GA plc_s = new PLC_S_GA();
  971. INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
  972. plc_s.PLC_IP = ini.Read(flag, "PLC_IP");
  973. plc_s.PLC_PORT = ini.Read(flag, "PLC_PORT").ToInt32();
  974. plc_s.PLC_FLAG_CODE = ini.Read(flag, "PLC_FLAG_CODE");
  975. plc_s.PLC_FLAG_CODENUM = ini.Read(flag, "PLC_FLAG_CODENUM");
  976. plc_s.PLC_GOODSCODE_CODE = ini.Read(flag, "PLC_GOODSCODE_CODE");
  977. plc_s.PLC_GOODSCODE_CODENUM = ini.Read(flag, "PLC_GOODSCODE_CODENUM");
  978. plc_s.PLC_GROUTINGLINE3_CODE = ini.Read(flag, "PLC_GROUTINGLINE3_CODE");
  979. plc_s.PLC_GROUTINGLINE3_CODENUM = ini.Read(flag, "PLC_GROUTINGLINE3_CODENUM");
  980. plc_s.PLC_GOODSTYPE_CODE = ini.Read(flag, "PLC_GOODSTYPE_CODE");
  981. plc_s.PLC_GOODSTYPE_CODENUM = ini.Read(flag, "PLC_GOODSTYPE_CODENUM");
  982. plc_s.PLC_GOODSDISABLED_CODE = ini.Read(flag, "PLC_GOODSDISABLED_CODE");
  983. plc_s.PLC_GOODSDISABLED_CODENUM = ini.Read(flag, "PLC_GOODSDISABLED_CODENUM");
  984. plc_s.PLC_SEMIREWORK_CODE = ini.Read(flag, "PLC_SEMIREWORK_CODE");
  985. plc_s.PLC_SEMIREWORK_CODENUM = ini.Read(flag, "PLC_SEMIREWORK_CODENUM");
  986. plc_s.PLC_GOODSLEVEL_CODE = ini.Read(flag, "PLC_GOODSLEVEL_CODE");
  987. plc_s.PLC_GOODSLEVEL_CODENUM = ini.Read(flag, "PLC_GOODSLEVEL_CODENUM");
  988. plc_s.PLC_GOODSLEAKFLAG1_CODE = ini.Read(flag, "PLC_GOODSLEAKFLAG1_CODE");
  989. plc_s.PLC_GOODSLEAKFLAG1_CODENUM = ini.Read(flag, "PLC_GOODSLEAKFLAG1_CODENUM");
  990. plc_s.PLC_GOODSWATER_CODE = ini.Read(flag, "PLC_GOODSWATER_CODE");
  991. plc_s.PLC_GOODSWATER_CODENUM = ini.Read(flag, "PLC_GOODSWATER_CODENUM");
  992. plc_s.PROCEDURE_ID = ini.Read(flag, "PROCEDURE_ID");
  993. plc_s.PROCEDURE_USERCODE = ini.Read(flag, "PROCEDURE_USERCODE");
  994. plc_s.WORKSTATION_ID = ini.Read(flag, "WORKSTATION_ID");
  995. plc_s.WORKSTATION_NAME = ini.Read(flag, "WORKSTATION_NAME");
  996. plc_s.PROCEDURE_ID2 = ini.Read(flag, "PROCEDURE_ID2");
  997. plc_s.PROCEDURE_USERCODE2 = ini.Read(flag, "PROCEDURE_USERCODE2");
  998. plc_s.WORKSTATION_ID2 = ini.Read(flag, "WORKSTATION_ID2");
  999. plc_s.WORKSTATION_NAME2 = ini.Read(flag, "WORKSTATION_NAME2");
  1000. PLC_FLAGS.Add(flag, plc_s);
  1001. return plc_s;
  1002. }
  1003. }
  1004. catch (Exception ex)
  1005. {
  1006. Logger.Error(ex, $"[{e.Content}]ERROR-GetPLC_S_GA", loggerName, logger_e);
  1007. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetPLC_S_GA={ex.Message}");
  1008. return null;
  1009. }
  1010. }
  1011. }
  1012. }