PieceWork.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Threading;
  7. using Curtain.Core;
  8. using Curtain.DataAccess;
  9. using Curtain.Extension.ExObjectConvert;
  10. using Curtain.Extension.ExSystemData;
  11. using Curtain.Framework.Json;
  12. using Curtain.Helpers;
  13. using Curtain.Log;
  14. using Curtain.Net.Sockets.PLC;
  15. using Curtain.Net.Sockets.PLC.Model;
  16. using Curtain.Net.Sockets.PLC.Model.Melsec;
  17. using PLC_S.Proxy;
  18. namespace PLC_S.ServerModel
  19. {
  20. /// <summary>
  21. /// 计件(2-20机械修坯助修)
  22. /// </summary>
  23. public class PieceWork : SocketServer<SimpleSocketServerModel>, IShowFormLog, IWindowsServer
  24. {
  25. public Dictionary<string, PLC_S_PW> PLC_FLAGS = new Dictionary<string, PLC_S_PW>();
  26. public Dictionary<string, PLC_S_GC> PLC_FLAGS_GC = new Dictionary<string, PLC_S_GC>();
  27. public const string M_NAME = "PW";
  28. private readonly MES_S _mes_s = null;
  29. private readonly Logger logger = Logger.CreateLogger(M_NAME);
  30. private readonly LogInfo logger_t = new LogInfo();
  31. private readonly LogInfo logger_e = new LogInfo();
  32. private bool _S_STOP = false;
  33. public int Interval
  34. {
  35. get;
  36. set;
  37. }
  38. public string EPTS_CODE
  39. {
  40. get;
  41. set;
  42. }
  43. public PieceWork()
  44. {
  45. logger.FileExistDays = 30;
  46. logger.FilePrefix = "";
  47. logger.FileSuffix = M_NAME;
  48. logger_t.LevelOneFile = true;
  49. logger.FileNameWithoutDate = true;
  50. logger_t.SubFolderFormat = "<name>";
  51. logger_t.FileExistDays = 30;
  52. logger_t.LevelOneFile = true;
  53. logger_e.FileExistDays = 0;
  54. this.Model.FormatType = CommandFormatType.StartStopChar;
  55. this.ServerStarting += ServerSocket_ServerStarting;
  56. this.ServerStarted += ServerSocket_ServerStarted;
  57. this.ServerStoping += ServerSocket_ServerStoping;
  58. this.ServerStoped += ServerSocket_ServerStoped;
  59. this.ServerMessage += ServerSocket_ServerMessage;
  60. this.Received += ServerSocket_Received;
  61. _mes_s = MES_S.Get();
  62. }
  63. #region Server
  64. public IFormLogShow FormLogShow
  65. {
  66. get;
  67. set;
  68. }
  69. private void ServerSocket_ServerStarting(object sender, CancelEventArgs e)
  70. {
  71. try
  72. {
  73. _S_STOP = false;
  74. logger.OutputTrace($"{M_NAME}_ServerStarting");
  75. }
  76. catch { }
  77. }
  78. private void ServerSocket_ServerStarted(object sender, EventArgs e)
  79. {
  80. try
  81. {
  82. _S_STOP = false;
  83. logger.OutputTrace($"{M_NAME}_ServerStarted");
  84. }
  85. catch { }
  86. }
  87. private void ServerSocket_ServerStoping(object sender, CancelEventArgs e)
  88. {
  89. try
  90. {
  91. _S_STOP = true;
  92. logger.OutputTrace($"{M_NAME}_ServerStoping");
  93. }
  94. catch { }
  95. }
  96. private void ServerSocket_ServerStoped(object sender, EventArgs e)
  97. {
  98. try
  99. {
  100. _S_STOP = true;
  101. logger.OutputTrace($"{M_NAME}_ServerStoped");
  102. }
  103. catch { }
  104. }
  105. private void ServerSocket_ServerMessage(object sender, ServerMessageEventArgs e)
  106. {
  107. try
  108. {
  109. _S_STOP = true;
  110. string message = e.ToString();
  111. string cip = e?.Client?.IP;
  112. if (e.Type == ServerMessageType.Debug)
  113. {
  114. Logger.Debug(message, $"{M_NAME}-T[{cip}]", logger_t);
  115. }
  116. if (e.Type == ServerMessageType.Error)
  117. {
  118. Logger.Error(e.Exception, message, $"{M_NAME}-E[{cip}]", logger_e);
  119. }
  120. if (e.Type == ServerMessageType.Trace)
  121. {
  122. Logger.Trace(message, $"{M_NAME}-T[{cip}]", logger_t);
  123. }
  124. if (e.Type == ServerMessageType.Warning)
  125. {
  126. Logger.Warn(message, $"{M_NAME}-E[{cip}]", logger_e);
  127. }
  128. FormLogShow?.ShowLog("ServerMessage=" + message);
  129. }
  130. catch { }
  131. try
  132. {
  133. if (e.Code == "CNS-T-001")
  134. {
  135. string flag = "PW1201";
  136. PLC_S_PW plc_s = new PLC_S_PW();
  137. INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
  138. plc_s.IP = ini.Read(flag, "IP");
  139. plc_s.Port = ini.Read(flag, "Port").ToInt32();
  140. plc_s.Add_FlagCode = ini.Read(flag, "Add_FlagCode");
  141. plc_s.Add_FlagCodeNum = ini.Read(flag, "Add_FlagCodeNum");
  142. SocketClient<MelsecA1EAsciiModel> plc = new SocketClient<MelsecA1EAsciiModel>();
  143. plc.Connect(plc_s.IP, plc_s.Port);
  144. try
  145. {
  146. string outputMessage = $"[]SET_FlagCode=[0]{plc_s.Add_FlagCode + plc_s.Add_FlagCodeNum}";
  147. Logger.Trace(outputMessage, null, logger_t);
  148. FormLogShow?.ShowLog(outputMessage);
  149. plc?.Write<int>(plc_s.Add_FlagCode, plc_s.Add_FlagCodeNum, 0);
  150. outputMessage = $"[]END_FlagCode=[0]{plc_s.Add_FlagCode + plc_s.Add_FlagCodeNum}";
  151. Logger.Trace(outputMessage, null, logger_t);
  152. FormLogShow?.ShowLog(outputMessage);
  153. }
  154. catch
  155. {
  156. }
  157. plc?.Disconnect();
  158. plc?.Close();
  159. }
  160. }
  161. catch
  162. {
  163. }
  164. }
  165. #endregion
  166. private string _RECEIVED_CODE = null;
  167. /// <summary>
  168. /// 2-20机械修坯助修
  169. /// </summary>
  170. /// <param name="sender"></param>
  171. /// <param name="e"></param>
  172. private void ServerSocket_Received(object sender, ReceiveSession e)
  173. {
  174. string cIP = e?.Client?.IP;
  175. string logKeyT = $"{M_NAME}-T[{cIP}]";
  176. string logKeyE = $"{M_NAME}-E[{cIP}]";
  177. string outputMessage = e.ToString();
  178. Logger.Trace(outputMessage, logKeyT, logger_t);
  179. FormLogShow?.ShowLog(outputMessage);
  180. string receivedCode = Guid.NewGuid().ToString();
  181. _RECEIVED_CODE = receivedCode;
  182. _S_STOP = true;
  183. lock (this)
  184. {
  185. if (_RECEIVED_CODE != receivedCode)
  186. {
  187. outputMessage = $"[{e.Content}]不是当前请求,退出排队";
  188. Logger.Warn(outputMessage, logKeyT, logger_t);
  189. Logger.Warn(outputMessage, logKeyE, logger_e);
  190. FormLogShow?.ShowLog(outputMessage);
  191. return;
  192. }
  193. _S_STOP = false;
  194. PLC_S_PW plc_s = null;
  195. SocketClient<MelsecA1EAsciiModel> plc = null;
  196. try
  197. {
  198. if (string.IsNullOrWhiteSpace(e.Content))
  199. {
  200. outputMessage = "接收数据为空";
  201. Logger.Warn(outputMessage, logKeyT, logger_t);
  202. Logger.Warn(outputMessage, logKeyE, logger_e);
  203. FormLogShow?.ShowLog(outputMessage);
  204. return;
  205. }
  206. outputMessage = e.Content;
  207. Logger.Trace(outputMessage, logKeyT, logger_t);
  208. FormLogShow?.ShowLog(outputMessage);
  209. string flag = null;
  210. string[] c = e.Content.Split('#');
  211. if (c.Length > 0)
  212. {
  213. flag = c[0];
  214. }
  215. string barcode = null;
  216. if (c.Length > 1)
  217. {
  218. barcode = c[1];
  219. }
  220. plc_s = GetPLC_S_PW(flag, e, logKeyE);
  221. if (plc_s == null || plc_s.USER_CDOES == null)
  222. {
  223. outputMessage = $"[{e.Content}]设备代码[{flag}]未找到ini配置或有错误";
  224. Logger.Error(null, outputMessage, logKeyT, logger_t);
  225. Logger.Error(null, outputMessage, logKeyE, logger_e);
  226. FormLogShow?.ShowLog(outputMessage);
  227. return;
  228. }
  229. plc = new SocketClient<MelsecA1EAsciiModel>();
  230. plc.Connect(plc_s.IP, plc_s.Port);
  231. outputMessage = $"[{e.Content}]PLC_Connect=[{plc_s.IP}:{plc_s.Port}]";
  232. Logger.Trace(outputMessage, logKeyT, logger_t);
  233. FormLogShow?.ShowLog(outputMessage);
  234. if (string.IsNullOrWhiteSpace(flag))
  235. {
  236. outputMessage = $"[{e.Content}]接收设备代码为空";
  237. Logger.Warn(outputMessage, logKeyT, logger_t);
  238. Logger.Warn(outputMessage, logKeyE, logger_e);
  239. FormLogShow?.ShowLog(outputMessage);
  240. SendError(plc_s, e, logKeyT, logKeyE, plc);
  241. return;
  242. }
  243. if (string.IsNullOrWhiteSpace(barcode) || barcode == "0" || barcode.StartsWith("0"))
  244. {
  245. outputMessage = $"[{e.Content}]接收条码为空";
  246. Logger.Warn(outputMessage, logKeyT, logger_t);
  247. Logger.Warn(outputMessage, logKeyE, logger_e);
  248. FormLogShow?.ShowLog(outputMessage);
  249. SendError(plc_s, e, logKeyT, logKeyE, plc);
  250. return;
  251. }
  252. outputMessage = $"[{e.Content}]SET_FlagCode=[1]{plc_s.Add_FlagCode + plc_s.Add_FlagCodeNum}";
  253. Logger.Trace(outputMessage, logKeyT, logger_t);
  254. FormLogShow?.ShowLog(outputMessage);
  255. //plc.Write<string>(plc_s.Add_FlagCode, plc_s.Add_FlagCodeNum, "1");
  256. plc.Write<int>(plc_s.Add_FlagCode, plc_s.Add_FlagCodeNum, 1);
  257. outputMessage = $"[{e.Content}]END_FlagCode=[1]{plc_s.Add_FlagCode + plc_s.Add_FlagCodeNum}";
  258. Logger.Trace(outputMessage, logKeyT, logger_t);
  259. FormLogShow?.ShowLog(outputMessage);
  260. //PLCResult<string> flag_result = null;
  261. PLCResult<int> flag_result_int = null;
  262. while (true)
  263. {
  264. Thread.Sleep(plc_s.Thread_Sleep);
  265. outputMessage = $"[{e.Content}]GET_RoomCode=[ ]{plc_s.Add_RoomCode + plc_s.Add_RoomCodeNum}";
  266. Logger.Trace(outputMessage, logKeyT, logger_t);
  267. FormLogShow?.ShowLog(outputMessage);
  268. //flag_result = plc.Read<string>(plc_s.Add_RoomCode, plc_s.Add_RoomCodeNum);
  269. flag_result_int = plc.Read<int>(plc_s.Add_RoomCode, plc_s.Add_RoomCodeNum, 1);
  270. outputMessage = $"[{e.Content}]END_RoomCode=[{flag_result_int.Data}]{plc_s.Add_RoomCode + plc_s.Add_RoomCodeNum}";
  271. Logger.Trace(outputMessage, logKeyT, logger_t);
  272. FormLogShow?.ShowLog(outputMessage);
  273. //if (!string.IsNullOrWhiteSpace(flag_result.Data) &&
  274. // flag_result.Data != "0")
  275. //{
  276. // break;
  277. //}
  278. if (flag_result_int.Data > 0)
  279. {
  280. break;
  281. }
  282. if (_S_STOP)
  283. {
  284. outputMessage = $"[{e.Content}]STOP[S]";
  285. Logger.Trace(outputMessage, logKeyT, logger_t);
  286. FormLogShow?.ShowLog(outputMessage);
  287. //SendError(plc_s, e, logKeyT, logKeyE, plc);
  288. return;
  289. }
  290. }
  291. //string roomcode = flag_result?.Data;
  292. //int room_num = 0;
  293. //if (string.IsNullOrWhiteSpace(roomcode))
  294. //{
  295. // room_num = Convert.ToInt32(roomcode);
  296. //}
  297. int room_num = flag_result_int.Data;
  298. string roomcode = room_num.ToString();
  299. outputMessage = $"[{e.Content}]SET_RoomCode=[0]{plc_s.Add_RoomCode + plc_s.Add_RoomCodeNum}";
  300. Logger.Trace(outputMessage, logKeyT, logger_t);
  301. FormLogShow?.ShowLog(outputMessage);
  302. //plc.Write<string>(plc_s.Add_RoomCode, plc_s.Add_RoomCodeNum, "0");
  303. plc.Write<int>(plc_s.Add_RoomCode, plc_s.Add_RoomCodeNum, 0);
  304. outputMessage = $"[{e.Content}]END_RoomCode=[0]{plc_s.Add_RoomCode + plc_s.Add_RoomCodeNum}";
  305. Logger.Trace(outputMessage, logKeyT, logger_t);
  306. FormLogShow?.ShowLog(outputMessage);
  307. if (room_num < 1 || room_num > 2)
  308. {
  309. outputMessage = $"[{barcode}][{roomcode}]读取房号失败";
  310. Logger.Warn(outputMessage, logKeyT, logger_t);
  311. Logger.Warn(outputMessage, logKeyE, logger_e);
  312. FormLogShow?.ShowLog(outputMessage);
  313. SendError(plc_s, e, logKeyT, logKeyE, plc);
  314. return;
  315. }
  316. //outputMessage = $"[{e.Content}]usercode_s=[{plc_s.USER_CDOE}]";
  317. //Logger.Trace(outputMessage, logKeyT, logger_t);
  318. //FormLogShow?.ShowLog(outputMessage);
  319. string usercode = plc_s.USER_CDOES[room_num];
  320. using (IDataAccess dataAccess = PLC_S_DataAccess.GetDataAccess(e))
  321. {
  322. string sqlString = $@"
  323. SELECT t.usercode
  324. FROM tp_mst_workstation t
  325. WHERE t.workstationid = {usercode}
  326. ";
  327. usercode = dataAccess.ExecuteScalar(sqlString) + "";
  328. }
  329. outputMessage = $"[{e.Content}]usercode=[{usercode}]";
  330. Logger.Trace(outputMessage, logKeyT, logger_t);
  331. FormLogShow?.ShowLog(outputMessage);
  332. string result = "OK";
  333. outputMessage = $"[{e.Content}]AddWorkPieceByStatus3=[F:{plc_s.Add_GoodsCodeNum}][P_ID:{plc_s.P_ID}][Code:{roomcode}]";
  334. Logger.Trace(outputMessage, logKeyT, logger_t);
  335. FormLogShow?.ShowLog(outputMessage);
  336. if (plc_s.Add_GoodsCodeNum == "1")
  337. {
  338. result = SmartDeviceProxy.Instance.Invoke<string>(
  339. p => p.AddWorkPieceByStatus3(
  340. _mes_s.AccountCode,
  341. usercode,
  342. null,
  343. plc_s.P_ID,
  344. barcode,
  345. roomcode));
  346. }
  347. // 返回状态(成功、失败)
  348. if (result == "OK")
  349. {
  350. outputMessage = $"[{e.Content}]result=[OK]";
  351. Logger.Trace(outputMessage, logKeyT, logger_t);
  352. FormLogShow?.ShowLog(outputMessage);
  353. return;
  354. }
  355. if (result == "EE")
  356. {
  357. outputMessage = $"[{e.Content}]result=[{result}]MES服务端异常(详情参见MES端日志)";
  358. }
  359. else if (result == "EU-01")
  360. {
  361. outputMessage = $"[{e.Content}]result=[{result}]无效的帐套或工号(详情参见MES端日志)";
  362. }
  363. else
  364. {
  365. outputMessage = $"[{e.Content}]result=[E][{result}]其他错误(详情参见MES端日志)";
  366. }
  367. Logger.Warn(outputMessage, logKeyT, logger_t);
  368. Logger.Warn(outputMessage, logKeyE, logger_e);
  369. FormLogShow?.ShowLog(outputMessage);
  370. SendError(plc_s, e, logKeyT, logKeyE, plc);
  371. }
  372. catch (Exception ex)
  373. {
  374. FormLogShow?.ShowLog($"[{e.Content}]ERROR={ex.Message}");
  375. if (plc_s != null)
  376. {
  377. Logger.Error(ex, $"[{e.Content}]ERROR", logKeyT, logger_t);
  378. Logger.Error(ex, $"[{e.Content}]ERROR", logKeyE, logger_e);
  379. SendError(plc_s, e, logKeyT, logKeyE, plc);
  380. }
  381. else
  382. {
  383. Logger.Error(ex, $"[{e.Content}]ERROR-NOFLAG", logKeyT, logger_t);
  384. Logger.Error(ex, $"[{e.Content}]ERROR-NOFLAG", logKeyE, logger_e);
  385. }
  386. }
  387. finally
  388. {
  389. try
  390. {
  391. outputMessage = $"[{e.Content}]SET_FlagCode=[0]{plc_s.Add_FlagCode + plc_s.Add_FlagCodeNum}";
  392. Logger.Trace(outputMessage, logKeyT, logger_t);
  393. FormLogShow?.ShowLog(outputMessage);
  394. plc?.Write<int>(plc_s.Add_FlagCode, plc_s.Add_FlagCodeNum, 0);
  395. outputMessage = $"[{e.Content}]END_FlagCode=[0]{plc_s.Add_FlagCode + plc_s.Add_FlagCodeNum}";
  396. Logger.Trace(outputMessage, logKeyT, logger_t);
  397. FormLogShow?.ShowLog(outputMessage);
  398. }
  399. catch (Exception ex)
  400. {
  401. Logger.Error(ex, $"[{e.Content}]ERROR-FIN", logKeyT, logger_t);
  402. Logger.Error(ex, $"[{e.Content}]ERROR-FIN", logKeyE, logger_e);
  403. FormLogShow?.ShowLog($"[{e.Content}]ERROR-FIN={ex.Message}");
  404. }
  405. plc?.Disconnect();
  406. plc?.Close();
  407. e.ReturnMessage("0000");
  408. }
  409. }
  410. }
  411. private void SendError(PLC_S_PW plc_s, ReceiveSession e, string loggerNameT,
  412. string loggerNameE, SocketClient<MelsecA1EAsciiModel> plc)
  413. {
  414. try
  415. {
  416. //using (SocketClient<SiemensS7_1200Model> plc = new SocketClient<SiemensS7_1200Model>())
  417. {
  418. string outputMessage = $"[{e.Content}]SET_ErrorNum=[1]{plc_s.Add_Error + plc_s.Add_ErrorNum}";
  419. Logger.Trace(outputMessage, loggerNameT, logger_t);
  420. FormLogShow?.ShowLog(outputMessage);
  421. plc?.Write<int>(plc_s.Add_Error, plc_s.Add_ErrorNum, 1);
  422. outputMessage = $"[{e.Content}]END_ErrorNum=[1]{plc_s.Add_Error + plc_s.Add_ErrorNum}";
  423. Logger.Trace(outputMessage, loggerNameT, logger_t);
  424. FormLogShow?.ShowLog(outputMessage);
  425. }
  426. }
  427. catch (Exception ex)
  428. {
  429. Logger.Error(ex, $"[{e.Content}]ERROR-SendError", loggerNameT, logger_t);
  430. Logger.Error(ex, $"[{e.Content}]ERROR-SendError", loggerNameE, logger_e);
  431. FormLogShow?.ShowLog($"[{e.Content}]ERROR-SendError={ex.Message}");
  432. }
  433. }
  434. private DataRow GetGoodsCode(string barcode, ReceiveSession e, string loggerName)
  435. {
  436. IDataAccess dataAccess = null;
  437. try
  438. {
  439. dataAccess = PLC_S_DataAccess.GetDataAccess(e);
  440. string sqlString = "select g.goodscode, g.seatcovercode\n" +
  441. " from tp_pm_groutingdailydetail gdd\n" +
  442. " inner join tp_mst_goods g\n" +
  443. " on g.goodsid = gdd.goodsid\n" +
  444. " where gdd.barcode = :barcode";
  445. DataTable dataTable = dataAccess.ExecuteDatatable(sqlString, new CDAParameter(":barcode", barcode));
  446. if (dataTable.HasData())
  447. {
  448. return dataTable.Rows[0];
  449. }
  450. return null;
  451. }
  452. catch (Exception ex)
  453. {
  454. //Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsCode", loggerNameT, logger_t);
  455. Logger.Error(ex, $"[{e.Content}]ERROR-GetGoodsCode", loggerName, logger_e);
  456. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetGoodsCode={ex.Message}");
  457. return null;
  458. }
  459. finally
  460. {
  461. dataAccess?.Close();
  462. }
  463. }
  464. /// <summary>
  465. /// 记录喷釉房
  466. /// </summary>
  467. /// <param name="barcode"></param>
  468. /// <returns></returns>
  469. private bool SetGlazingRoom(string barcode, string roomcode, ReceiveSession e, string loggerName)
  470. {
  471. IDataAccess dataAccess = null;
  472. try
  473. {
  474. dataAccess = PLC_S_DataAccess.GetDataAccess(e);
  475. string sqlString = "update tp_pm_groutingdailydetail g set g.glazingroom = :roomcode where g.barcode=:barcode";
  476. int i = dataAccess.ExecuteNonQuery(sqlString,
  477. new CDAParameter[] { new CDAParameter(":roomcode", roomcode), new CDAParameter(":barcode", barcode) });
  478. return true;
  479. }
  480. catch (Exception ex)
  481. {
  482. //Logger.Error(ex, $"[{e.Content}]ERROR-SetGlazingRoom", loggerNameT, logger_t);
  483. Logger.Error(ex, $"[{e.Content}]ERROR-SetGlazingRoom", loggerName, logger_e);
  484. FormLogShow?.ShowLog($"[{e.Content}]ERROR-SetGlazingRoom={ex.Message}");
  485. return false;
  486. }
  487. finally
  488. {
  489. dataAccess?.Close();
  490. }
  491. }
  492. private PLC_S_GC GetPLC_S_GC(string flag, ReceiveSession e, string loggerName)
  493. {
  494. try
  495. {
  496. flag = "GC" + flag;
  497. if (PLC_FLAGS_GC.ContainsKey(flag))
  498. {
  499. return PLC_FLAGS_GC[flag];
  500. }
  501. else
  502. {
  503. PLC_S_GC plc_s = new PLC_S_GC();
  504. INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
  505. plc_s.IP = ini.Read(flag, "IP");
  506. plc_s.Port = ini.Read(flag, "Port").ToInt32();
  507. plc_s.Add_Code = ini.Read(flag, "Add_Code");
  508. plc_s.Add_CodeNum = ini.Read(flag, "Add_CodeNum");
  509. plc_s.Add_BarCode = ini.Read(flag, "Add_BarCode");
  510. plc_s.Add_BarCodeNum = ini.Read(flag, "Add_BarCodeNum");
  511. plc_s.Add_Error = ini.Read(flag, "Add_Error");
  512. plc_s.Add_ErrorNum = ini.Read(flag, "Add_ErrorNum");
  513. PLC_FLAGS_GC.Add(flag, plc_s);
  514. return plc_s;
  515. }
  516. }
  517. catch (Exception ex)
  518. {
  519. //Logger.Error(ex, $"[{e.Content}]ERROR-GetPLC_S_GC", loggerNameT, logger_t);
  520. Logger.Error(ex, $"[{e.Content}]ERROR-GetPLC_S_GC", loggerName, logger_e);
  521. FormLogShow?.ShowLog($"[{e.Content}]ERROR-GetPLC_S_GC={ex.Message}");
  522. return null;
  523. }
  524. }
  525. private PLC_S_PW GetPLC_S_PW(string flag, ReceiveSession e, string loggerName)
  526. {
  527. try
  528. {
  529. flag = "PW" + flag;
  530. if (PLC_FLAGS.ContainsKey(flag))
  531. {
  532. return PLC_FLAGS[flag];
  533. }
  534. else
  535. {
  536. PLC_S_PW plc_s = new PLC_S_PW();
  537. INIHelper ini = INIHelper.Create($@"PLC_S_INI\PLC_S_{M_NAME}.ini");
  538. plc_s.P_ID = ini.Read(flag, "P_ID").ToInt32();
  539. plc_s.USER_CDOE = ini.Read(flag, "USER_CDOE");
  540. plc_s.USER_CDOES = plc_s.USER_CDOE?.Split(',');
  541. plc_s.USER_CDOE = JsonHelper.ToJson(plc_s.USER_CDOES);
  542. plc_s.IP = ini.Read(flag, "IP");
  543. plc_s.Port = ini.Read(flag, "Port").ToInt32();
  544. plc_s.Add_GoodsCode = ini.Read(flag, "Add_GoodsCode");
  545. plc_s.Add_GoodsCodeNum = ini.Read(flag, "Add_GoodsCodeNum");
  546. plc_s.Add_RoomCode = ini.Read(flag, "Add_RoomCode");
  547. plc_s.Add_RoomCodeNum = ini.Read(flag, "Add_RoomCodeNum");
  548. plc_s.Thread_Sleep = ini.Read(flag, "Thread_Sleep").ToInt32();
  549. if (plc_s.Thread_Sleep < 1000)
  550. {
  551. plc_s.Thread_Sleep = 1000;
  552. }
  553. plc_s.Add_FlagCode = ini.Read(flag, "Add_FlagCode");
  554. plc_s.Add_FlagCodeNum = ini.Read(flag, "Add_FlagCodeNum");
  555. plc_s.Add_Error = ini.Read(flag, "Add_Error");
  556. plc_s.Add_ErrorNum = ini.Read(flag, "Add_ErrorNum");
  557. PLC_FLAGS.Add(flag, plc_s);
  558. return plc_s;
  559. }
  560. }
  561. catch (Exception ex)
  562. {
  563. //Logger.Error(ex, $"[{e.Content}]ERROR-GetPLC_S_PW", loggerNameT, logger_t);
  564. Logger.Error(ex, $"[{e?.Content}]ERROR-GetPLC_S_PW", loggerName, logger_e);
  565. FormLogShow?.ShowLog($"[{e?.Content}]ERROR-GetPLC_S_PW={ex.Message}");
  566. return null;
  567. }
  568. }
  569. }
  570. }