Form_MESTest.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. using EIP_Protocol;
  2. using MainForm.ClassFile.XiaomiAPI;
  3. using Sunny.UI.Win32;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Diagnostics;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
  14. namespace MainForm.FaForm
  15. {
  16. public partial class Form_MESTest : Form
  17. {
  18. #region 变量
  19. public event AlarmMessageHandler MessageEvent;
  20. #endregion 变量
  21. #region 窗体事件
  22. public Form_MESTest()
  23. {
  24. InitializeComponent();
  25. }
  26. private void Form_MESTest_Load(object sender, EventArgs e)
  27. {
  28. cmbSNType.SelectedIndex = 0;
  29. cmbProResult.SelectedIndex = 0;
  30. }
  31. #endregion 窗体事件
  32. #region 进站相关
  33. /// <summary>
  34. /// 进站
  35. /// </summary>
  36. private async void btnStationIn_Click(object sender, EventArgs e)
  37. {
  38. try
  39. {
  40. string sn = txtSN.Text.Trim();
  41. if (string.IsNullOrEmpty(sn))
  42. {
  43. MessageBox.Show("SN号不可为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  44. return;
  45. }
  46. string snType = cmbSNType.Text.Trim();
  47. switch (snType)
  48. {
  49. case "产品SN":
  50. (int, string) result = StationInFunc_ProductSN(sn);
  51. ShowLog(result.Item2);
  52. break;
  53. case "载具SN":
  54. case "弹夹SN":
  55. MessageBox.Show("暂不支持的进站方式");
  56. break;
  57. default:
  58. break;
  59. }
  60. }
  61. catch (Exception ex)
  62. {
  63. string str = ex.StackTrace;
  64. MessageBox.Show("进站异常!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  65. }
  66. }
  67. /// <summary>
  68. /// 进站 - 产品SN
  69. /// </summary>
  70. /// <param name="sn">产品SN</param>
  71. /// <returns></returns>
  72. private (int, string) StationInFunc_ProductSN(string sn)
  73. {
  74. string stationStr = cmbStationName.Text.Trim();
  75. #region 校验
  76. string vehicleCode = txtVehicleCode.Text.Trim(); // 载具码
  77. string vehicleCodeNum = txtVehicleCodeNum.Text.Trim(); // 载具穴号
  78. string bulletclipCode = txtBulletclipCode.Text.Trim(); // 弹夹码
  79. string bulletclipCodeNum = txtBulletclipCodeNum.Text.Trim(); // 弹夹穴号
  80. List<TestItem> item = new List<TestItem>();
  81. item.Add(new TestItem()
  82. {
  83. Parameter_name = "产品结果",
  84. Parameter_value = cmbProResult.Text.Trim(),
  85. });
  86. if (string.IsNullOrEmpty(vehicleCode))
  87. item.Add(new TestItem()
  88. {
  89. Parameter_name = "载具码",
  90. Parameter_value = vehicleCode,
  91. });
  92. if (string.IsNullOrEmpty(vehicleCodeNum))
  93. item.Add(new TestItem()
  94. {
  95. Parameter_name = "载具穴号",
  96. Parameter_value = vehicleCodeNum,
  97. });
  98. if (string.IsNullOrEmpty(bulletclipCode))
  99. item.Add(new TestItem()
  100. {
  101. Parameter_name = "弹夹码",
  102. Parameter_value = bulletclipCode,
  103. });
  104. if (string.IsNullOrEmpty(bulletclipCodeNum))
  105. item.Add(new TestItem()
  106. {
  107. Parameter_name = "弹夹穴号",
  108. Parameter_value = bulletclipCodeNum,
  109. });
  110. #endregion 校验
  111. int mesResult = Form_Main.formHome.SaveStationInData(stationStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  112. switch (mesResult)
  113. {
  114. case 1:
  115. return (1, "[1]成功;" + errorMsg);
  116. case 5:
  117. return (5, "[5]MES报警;" + errorMsg);
  118. case 6:
  119. return (6, "[6]上位机报警;" + errorMsg);
  120. default:
  121. return (999, "[999]未知结果;" + errorMsg);
  122. }
  123. }
  124. #endregion 进站相关
  125. #region 出站相关
  126. /// <summary>
  127. /// 出站
  128. /// </summary>
  129. private async void btnStationOut_Click(object sender, EventArgs e)
  130. {
  131. try
  132. {
  133. string sn = txtSN.Text.Trim();
  134. if (string.IsNullOrEmpty(sn))
  135. {
  136. MessageBox.Show("SN号不可为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  137. return;
  138. }
  139. string snType = cmbSNType.Text.Trim();
  140. switch (snType)
  141. {
  142. case "产品SN":
  143. (int, string) result = StationOutFunc_ProductSN(sn);
  144. ShowLog(result.Item2);
  145. break;
  146. case "载具SN":
  147. case "弹夹SN":
  148. MessageBox.Show("暂不支持的出站方式");
  149. break;
  150. default:
  151. break;
  152. }
  153. }
  154. catch (Exception ex)
  155. {
  156. string str = ex.StackTrace;
  157. MessageBox.Show("进站异常!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  158. }
  159. }
  160. /// <summary>
  161. /// 出站 - 产品SN
  162. /// </summary>
  163. /// <param name="sn">产品SN</param>
  164. /// <returns></returns>
  165. private (int, string) StationOutFunc_ProductSN(string sn)
  166. {
  167. string stationStr = cmbStationName.Text.Trim();
  168. #region 校验
  169. string vehicleCode = txtVehicleCode.Text.Trim(); // 载具码
  170. string vehicleCodeNum = txtVehicleCodeNum.Text.Trim(); // 载具穴号
  171. string bulletclipCode = txtBulletclipCode.Text.Trim(); // 弹夹码
  172. string bulletclipCodeNum = txtBulletclipCodeNum.Text.Trim(); // 弹夹穴号
  173. List<TestItem> item = new List<TestItem>();
  174. item.Add(new TestItem()
  175. {
  176. Parameter_name = "产品结果",
  177. Parameter_value = cmbProResult.Text.Trim(),
  178. });
  179. if (string.IsNullOrEmpty(vehicleCode))
  180. item.Add(new TestItem()
  181. {
  182. Parameter_name = "载具码",
  183. Parameter_value = vehicleCode,
  184. });
  185. if (string.IsNullOrEmpty(vehicleCodeNum))
  186. item.Add(new TestItem()
  187. {
  188. Parameter_name = "载具穴号",
  189. Parameter_value = vehicleCodeNum,
  190. });
  191. if (string.IsNullOrEmpty(bulletclipCode))
  192. item.Add(new TestItem()
  193. {
  194. Parameter_name = "弹夹码",
  195. Parameter_value = bulletclipCode,
  196. });
  197. if (string.IsNullOrEmpty(bulletclipCodeNum))
  198. item.Add(new TestItem()
  199. {
  200. Parameter_name = "弹夹穴号",
  201. Parameter_value = bulletclipCodeNum,
  202. });
  203. #endregion 校验
  204. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  205. string mtltmrk = GlobalContext.Mtltmrk; // 型号
  206. bool pass = cmbProResult.Text == "OK";
  207. string zj = vehicleCode;
  208. string zjxh = vehicleCodeNum;
  209. if (!string.IsNullOrEmpty(bulletclipCode) && !string.IsNullOrEmpty(bulletclipCodeNum))
  210. {
  211. zj = bulletclipCode;
  212. zjxh = bulletclipCodeNum;
  213. }
  214. string equipmentCode = "";
  215. string processItem = "";
  216. //[S1]Tray盘上料装备
  217. //[S2]FCT
  218. //[S3]值板机
  219. //[S4_1]载具下线装备
  220. //[S4_3]提升机1
  221. //[S4_4]提升机2
  222. //[S4_5]载具上线装备
  223. //[S5]Tray盘下料装备
  224. switch (stationStr)
  225. {
  226. case "[S1]Tray盘上料装备":
  227. equipmentCode = GlobalContext.LineCode + "-[S1]";
  228. processItem = "Tray盘上料装备";
  229. break;
  230. case "[S2]FCT":
  231. equipmentCode = GlobalContext.LineCode + "-[S2]";
  232. processItem = "FCT";
  233. break;
  234. case "[S3]值板机":
  235. equipmentCode = GlobalContext.LineCode + "-[S3]";
  236. processItem = "值板机";
  237. break;
  238. case "[S4_1]载具下线装备":
  239. equipmentCode = GlobalContext.LineCode + "-[S4_1]";
  240. processItem = "载具下线装备";
  241. break;
  242. case "[S4_3]提升机1":
  243. equipmentCode = GlobalContext.LineCode + "-[S4_3]";
  244. processItem = "提升机1";
  245. break;
  246. case "[S4_4]提升机2":
  247. equipmentCode = GlobalContext.LineCode + "-[S4_4]";
  248. processItem = "提升机2";
  249. break;
  250. case "[S4_5]载具上线装备":
  251. equipmentCode = GlobalContext.LineCode + "-[S4_5]";
  252. processItem = "载具上线装备";
  253. break;
  254. case "[S5]Tray盘下料装备":
  255. equipmentCode = GlobalContext.LineCode + "-[S5]";
  256. processItem = "Tray盘下料装备";
  257. break;
  258. }
  259. //int mesResult = 0;
  260. int mesResult = Form_Main.formHome.SaveProcessDataByDB(stationStr, item, equipmentCode, processItem
  261. , workorder_code, mtltmrk, sn, pass, zj, zjxh);
  262. switch (mesResult)
  263. {
  264. case 1:
  265. return (1, "[1]成功");
  266. case 5:
  267. return (5, "[5]MES报警");
  268. case 6:
  269. return (6, "[6]上位机报警");
  270. default:
  271. return (999, "[999]未知结果");
  272. }
  273. }
  274. #endregion 出站相关
  275. #region Iot手动上传 Tap
  276. /// <summary>
  277. /// 上传按钮_Iot
  278. /// </summary>
  279. private async void btnSend_Iot_Click(object sender, EventArgs e)
  280. {
  281. try
  282. {
  283. await Task.Run(async () =>
  284. {
  285. string stationStr = cmbStationName_Iot.Text.Trim(); // 工站名称
  286. string mesStation = "";
  287. switch (stationStr)
  288. {
  289. //[S1]Tray盘上料装备
  290. //[S2]FCT
  291. //[S3]值板机
  292. //[S4_1]载具下线装备
  293. //[S4_5]载具上线装备
  294. //[S5]Tray盘下料装备
  295. case "[OP10]壳体清洁上料":
  296. mesStation = GlobalContext.S1_station;
  297. break;
  298. case "[OP20]上盖板上料装备":
  299. mesStation = GlobalContext.S2_station;
  300. break;
  301. case "[OP30]点散热胶装备_Left":
  302. mesStation = GlobalContext.s3_1_station;
  303. break;
  304. case "[OP30]点散热胶装备_Right":
  305. mesStation = GlobalContext.s3_2_station;
  306. break;
  307. case "[OP40]胶线检测":
  308. mesStation = GlobalContext.s4_station;
  309. break;
  310. case "[OP50]ADD板上料组装装备":
  311. mesStation = GlobalContext.s5_station;
  312. break;
  313. case "[OP60]组上盖板":
  314. mesStation = GlobalContext.s6_station;
  315. break;
  316. case "[OP70]上盖板锁螺丝_Left":
  317. mesStation = GlobalContext.s7_1_station;
  318. break;
  319. case "[OP70]上盖板锁螺丝_Right":
  320. mesStation = GlobalContext.s7_2_station;
  321. break;
  322. case "[OP80]NG下料":
  323. mesStation = GlobalContext.s8_station;
  324. break;
  325. case "[OP90]半成品下料":
  326. mesStation = GlobalContext.s8_station;
  327. break;
  328. }
  329. string iotSendType = cmbSendType_Iot.Text.Trim();
  330. switch (iotSendType)
  331. {
  332. //设备状态
  333. //故障日志
  334. //节拍日志
  335. //操作记录
  336. case "设备状态":
  337. (int, string) resultDeviceState = SendIotDeviceStateFun(mesStation);
  338. ShowLog_Iot($"[{resultDeviceState.Item1}]" + resultDeviceState.Item2);
  339. break;
  340. case "故障日志":
  341. (int, string) resultFaultLog = SendIotFaultLogFun(mesStation);
  342. ShowLog_Iot($"[{resultFaultLog.Item1}]" + resultFaultLog.Item2);
  343. break;
  344. case "节拍日志":
  345. (int, string) resultInputBegin = SendIotInputBeginFun(mesStation);
  346. ShowLog_Iot($"[{resultInputBegin.Item1}]" + resultInputBegin.Item2);
  347. break;
  348. case "操作记录":
  349. (int, string) resultOperateLog = SendIotOperateLogFun(mesStation);
  350. ShowLog_Iot($"[{resultOperateLog.Item1}]" + resultOperateLog.Item2);
  351. break;
  352. case "过站结果":
  353. (int, string) resultPassStation = SendIotPassStationFun(mesStation);
  354. ShowLog_Iot($"[{resultPassStation.Item1}]" + resultPassStation.Item2);
  355. break;
  356. case "过站明细":
  357. (int, string) resultPassStationDetail = SendIotPassStationDetailFun(mesStation);
  358. ShowLog_Iot($"[{resultPassStationDetail.Item1}]" + resultPassStationDetail.Item2);
  359. break;
  360. case "非结构化":
  361. Task<(int, string)> resultFileUp = SendIotFileUpFun(mesStation);
  362. var result = await resultFileUp;
  363. ShowLog_Iot($"[{result.Item1}]" + result.Item2);
  364. break;
  365. default:
  366. break;
  367. }
  368. });
  369. }
  370. catch (Exception ex)
  371. {
  372. string str = ex.StackTrace;
  373. MessageBox.Show("进站异常!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  374. }
  375. }
  376. /// <summary>
  377. /// 上传设备状态_Iot
  378. /// </summary>
  379. /// <param name="mesStation">mes工站名称</param>
  380. /// <returns></returns>
  381. private (int, string) SendIotDeviceStateFun(string mesStation)
  382. {
  383. string xmDeviceState = cmbXiaomiDeviceState.Text.Trim(); // 设备状态
  384. if (string.IsNullOrEmpty(xmDeviceState))
  385. return (999, "‘状态类型’不可为空!");
  386. DeviceStateDataRequest request = new DeviceStateDataRequest();
  387. request.station = mesStation; // ⼯位
  388. request.state = xmDeviceState; // 设备状态
  389. request.time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 状态切换时的时间 2022-06-01 14:27:57.283
  390. if (xmDeviceState == "Fault" || xmDeviceState == "Alarm")
  391. {
  392. string faultCode = txtFaultCode.Text.Trim();
  393. if (string.IsNullOrEmpty(faultCode))
  394. return (999, "‘故障编码’不可为空!");
  395. request.fault_code = faultCode; // 对应的故障编码
  396. request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发⽣时间
  397. }
  398. // 上传
  399. (int, string) iotResult = XiaomiMqttClient_Extend.Write_DeviceStateData(request);
  400. return iotResult;
  401. }
  402. /// <summary>
  403. /// 上传故障日志_Iot
  404. /// </summary>
  405. /// <param name="mesStation">mes工站名称</param>
  406. /// <returns></returns>
  407. private (int, string) SendIotFaultLogFun(string mesStation)
  408. {
  409. string xmFaultName = txtFaultName.Text.Trim(); // 故障名称
  410. string xmFaultCode2 = txtFaultCode2.Text.Trim(); // 故障编码
  411. string xmFaultCmpnt = txtFaultCmpnt.Text.Trim(); // 故障部件
  412. string xmFaultDesc = txtFaultDesc.Text.Trim(); // 故障描述
  413. if (string.IsNullOrEmpty(xmFaultName))
  414. return (999, "‘故障名称’不可为空!");
  415. else if (string.IsNullOrEmpty(xmFaultCode2))
  416. return (999, "‘故障编码’不可为空!");
  417. else if (string.IsNullOrEmpty(xmFaultCmpnt))
  418. return (999, "‘故障部件’不可为空!");
  419. else if (string.IsNullOrEmpty(xmFaultDesc))
  420. return (999, "‘故障描述’不可为空!");
  421. FaultLogRequest request = new FaultLogRequest();
  422. request.station = mesStation; // ⼯位
  423. request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
  424. request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
  425. request.fault_cmpnt = xmFaultCmpnt; // 故障部件
  426. request.fault_desc = xmFaultDesc; // 故障描述
  427. request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发⽣时间 2022-06-01 14:27:57.283
  428. // 上传
  429. (int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request);
  430. //(int, string) iotResult = (0, "");
  431. return iotResult;
  432. }
  433. /// <summary>
  434. /// 上传节拍日志_Iot
  435. /// </summary>
  436. /// <param name="mesStation">mes工站名称</param>
  437. /// <returns></returns>
  438. private (int, string) SendIotInputBeginFun(string mesStation)
  439. {
  440. string action = cmbAction.Text.Trim(); // 节拍动作
  441. string partSn = txtPartSn.Text.Trim(); // 物料SN
  442. string vSn = txtVSn.Text.Trim(); // 载具SN
  443. string vIndexSn = txtVIndexSn.Text.Trim(); // 载具穴位编号
  444. string extra = txtExtra.Text.Trim(); // 额外信息
  445. string class_level_1 = txtClassLevel1.Text.Trim(); // 分类层级1
  446. string class_level_2 = txtClassLevel2.Text.Trim(); // 分类层级2
  447. string class_level_3 = txtClassLevel3.Text.Trim(); // 分类层级3
  448. if (string.IsNullOrEmpty(action))
  449. return (999, "‘节拍动作’不可为空!");
  450. else if (string.IsNullOrEmpty(partSn))
  451. return (999, "‘物料SN’不可为空!");
  452. else if (string.IsNullOrEmpty(vSn))
  453. return (999, "‘载具SN’不可为空!");
  454. //else if (string.IsNullOrEmpty(vIndexSn))
  455. // return (999, "‘载具穴位编号’不可为空!");
  456. else if (string.IsNullOrEmpty(class_level_1))
  457. return (999, "‘分类层级1’不可为空!");
  458. else if (string.IsNullOrEmpty(class_level_2))
  459. return (999, "‘分类层级2’不可为空!");
  460. else if (string.IsNullOrEmpty(class_level_3))
  461. return (999, "‘分类层级3’不可为空!");
  462. StationInputBeginRequest request = new StationInputBeginRequest();
  463. switch (action)
  464. {
  465. /// 上料开始:beat_log/business/OEE/station_input_begin
  466. /// 上料结束:beat_log/business/OEE/station_input_end
  467. /// 作业开始:beat_log/business/OEE/station_work_begin
  468. /// 作业结束:beat_log/business/OEE/station_work_end
  469. /// 下料开始:beat_log/business/OEE/station_output_begin
  470. /// 下料结束:beat_log/business/OEE/station_output_end
  471. case "上料开始":
  472. request.action = "beat_log/business/OEE/station_input_begin"; // 节拍动作(XiaomiDeviceOEE)
  473. break;
  474. case "上料结束":
  475. request.action = "beat_log/business/OEE/station_input_end"; // 节拍动作(XiaomiDeviceOEE)
  476. break;
  477. case "作业开始":
  478. request.action = "beat_log/business/OEE/station_work_begin"; // 节拍动作(XiaomiDeviceOEE)
  479. break;
  480. case "作业结束":
  481. request.action = "beat_log/business/OEE/station_work_end"; // 节拍动作(XiaomiDeviceOEE)
  482. break;
  483. case "下料开始":
  484. request.action = "beat_log/business/OEE/station_output_begin"; // 节拍动作(XiaomiDeviceOEE)
  485. break;
  486. case "下料结束":
  487. request.action = "beat_log/business/OEE/station_output_end"; // 节拍动作(XiaomiDeviceOEE)
  488. break;
  489. }
  490. request.beat_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  491. request.action_subject = partSn; // 该动作操作的⽬标对象(SN)
  492. request.action_subject_parent = vSn; // ⼤板SN/载具SN
  493. request.action_location = mesStation; // 该动作的位置信息(⼯位、槽位),如:F06-GSTPLA11_01-SLOT-01
  494. request.action_material = vIndexSn; // 该动作的物料信息
  495. request.extra = extra; // 额外信息
  496. request.class_level_1 = class_level_1; // 分类层级1
  497. request.class_level_2 = class_level_2; // 分类层级2
  498. request.class_level_3 = class_level_3; // 分类层级3
  499. // 上传
  500. (int, string) iotResult = XiaomiMqttClient_Extend.Write_StationInputBegin(request);
  501. return iotResult;
  502. }
  503. /// <summary>
  504. /// 上传操作记录⽇志_Iot
  505. /// </summary>
  506. /// <param name="mesStation">mes工站名称</param>
  507. /// <returns></returns>
  508. private (int, string) SendIotOperateLogFun(string mesStation)
  509. {
  510. string operateAction = cmbOperateAction.Text.Trim(); // 操作动作
  511. string actionParam = txtActionParam.Text.Trim(); // 动作参数
  512. string operateDesc = txtOperateDesc.Text.Trim(); // 操作描述
  513. string operateResult = cmbOperateResult.Text.Trim(); // 操作结果
  514. if (string.IsNullOrEmpty(operateAction))
  515. return (999, "‘操作动作’不可为空!");
  516. else if (string.IsNullOrEmpty(operateDesc))
  517. return (999, "‘操作描述’不可为空!");
  518. else if (string.IsNullOrEmpty(operateResult))
  519. return (999, "‘操作结果’不可为空!");
  520. OperateLogRequest request = new OperateLogRequest();
  521. request.software_version = "V" + Application.ProductVersion; // 软件版本号;如:V1.2.4
  522. request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 操作时间(2022-06-01 14:27:57.283)
  523. request.operate_action = operateAction; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
  524. request.action_param = actionParam; // 动作参数;选填,附带额外的信息
  525. request.operate_module = "MES调试模块"; // 操作模块;选填
  526. request.operate_page = "手动调试页面"; // 操作⻚⾯;选填
  527. request.current_process = Process.GetCurrentProcess()?.Id.ToString(); // 当前进程;进程ID
  528. request.operate_desc = operateDesc; // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
  529. request.operate_result = operateResult; // 操作结果
  530. //request.operator_name = GlobalContext.currentRole; // 操作账号名;填当前操作⽤⼾,如⽆则填default
  531. // 上传
  532. (int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
  533. //(int, string) iotResult=(0,"");
  534. return iotResult;
  535. }
  536. /// <summary>
  537. /// 上传过站数据_Iot
  538. /// </summary>
  539. /// <param name="mesStation">mes工站名称</param>
  540. /// <returns></returns>
  541. private (int, string) SendIotPassStationFun(string mesStation)
  542. {
  543. string stationStr = cmbStationName_Iot.Text.Trim(); // 工站名
  544. string slot = txtSlot.Text.Trim(); // 槽位编码
  545. string sn = txtSn_PassStation.Text.Trim(); // 产品SN
  546. string enter_status = cmbEnterStatus.Text.Trim(); // 进站状态
  547. string result = cmbResult.Text.Trim(); // 过站结果
  548. string work_type = cmbWorkType.Text.Trim(); // 作业类型
  549. if (string.IsNullOrEmpty(slot))
  550. return (999, "‘槽位编码’不可为空!");
  551. else if (string.IsNullOrEmpty(sn))
  552. return (999, "‘产品SN’不可为空!");
  553. else if (string.IsNullOrEmpty(enter_status))
  554. return (999, "‘进站状态’不可为空!");
  555. else if (string.IsNullOrEmpty(result))
  556. return (999, "‘过站结果’不可为空!");
  557. else if (string.IsNullOrEmpty(work_type))
  558. return (999, "‘作业类型’不可为空!");
  559. PassStationResultRequest request = new PassStationResultRequest();
  560. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  561. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  562. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  563. request.line_code = GlobalContext.LineCode; // 线体编码
  564. switch (stationStr)
  565. {
  566. case "[OP10]壳体清洁上料":
  567. request.work_station = GlobalContext.S1_work_station; // ⼯站
  568. request.device_code = GlobalContext.S1_device_code; // 装备编码
  569. break;
  570. case "[OP20]上盖板上料装备":
  571. request.work_station = GlobalContext.S2_work_station; // ⼯站
  572. request.device_code = GlobalContext.S2_device_code; // 装备编码
  573. break;
  574. case "[OP30]点散热胶装备_Left":
  575. request.work_station = GlobalContext.s3_1_work_station; // ⼯站
  576. request.device_code = GlobalContext.s3_1_device_code; // 装备编码
  577. break;
  578. case "[OP30]点散热胶装备_Right":
  579. request.work_station = GlobalContext.s3_2_work_station; // ⼯站
  580. request.device_code = GlobalContext.s3_2_device_code; // 装备编码
  581. break;
  582. case "[OP40]胶线检测":
  583. request.work_station = GlobalContext.s4_work_station; // ⼯站
  584. request.device_code = GlobalContext.s4_device_code; // 装备编码
  585. break;
  586. case "[OP50]ADD板上料组装装备":
  587. request.work_station = GlobalContext.s5_work_station; // ⼯站
  588. request.device_code = GlobalContext.s5_device_code; // 装备编码
  589. break;
  590. case "[OP60]组上盖板":
  591. request.work_station = GlobalContext.s6_work_station; // ⼯站
  592. request.device_code = GlobalContext.s6_device_code; // 装备编码
  593. break;
  594. case "[OP70]上盖板锁螺丝_Left":
  595. request.work_station = GlobalContext.s7_1_work_station; // ⼯站
  596. request.device_code = GlobalContext.s7_1_device_code; // 装备编码
  597. break;
  598. case "[OP70]上盖板锁螺丝_Right":
  599. request.work_station = GlobalContext.s7_2_work_station; // ⼯站
  600. request.device_code = GlobalContext.s7_2_device_code; // 装备编码
  601. break;
  602. case "[OP80]NG下料":
  603. request.work_station = GlobalContext.s8_work_station; // ⼯站
  604. request.device_code = GlobalContext.s8_device_code; // 装备编码
  605. break;
  606. case "[OP90]半成品下料":
  607. request.work_station = GlobalContext.s9_work_station; // ⼯站
  608. request.device_code = GlobalContext.s9_device_code; // 装备编码
  609. break;
  610. }
  611. request.station = mesStation;
  612. request.process_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  613. request.slot = slot; // 槽位编码
  614. request.sn = sn; // 产品SN
  615. request.enter_status = enter_status; // 进站状态
  616. request.result = result; // 过站结果
  617. request.work_type = work_type; // 作业类型
  618. // 上传过站结果
  619. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  620. //(int, string) iotResult = (0, "");
  621. return iotResult;
  622. }
  623. private int test_item_num = 0;
  624. /// <summary>
  625. /// 上传过站数据_Iot
  626. /// </summary>
  627. /// <param name="mesStation">mes工站名称</param>
  628. /// <returns></returns>
  629. private (int, string) SendIotPassStationDetailFun(string mesStation)
  630. {
  631. test_item_num += 1;//⽰例:1,2,递增
  632. string _stationStr = cmbStationName_Iot.Text.Trim(); // 工站名
  633. string _slot = PassStationDetail_slot.Text.Trim(); // 槽位编码
  634. string _sn = PassStationDetail_SN.Text.Trim(); // 产品SN
  635. string _function_name= pnlPassStationDetail_functionNname.Text.Trim();
  636. string _test_item= pnlPassStationDetail_testItem.Text.Trim();
  637. string _result_val= pnlPassStationDetail_resultVal.Text.Trim();
  638. string _status = pnlPassStationDetail_status.Text.Trim();
  639. if (string.IsNullOrEmpty(_slot))
  640. return (999, "‘槽位编码’不可为空!");
  641. else if (string.IsNullOrEmpty(_sn))
  642. return (999, "‘产品SN’不可为空!");
  643. else if (string.IsNullOrEmpty(_function_name))
  644. return (999, "‘功能名称’不可为空!");
  645. else if (string.IsNullOrEmpty(_test_item))
  646. return (999, "‘测试项’不可为空!");
  647. else if (string.IsNullOrEmpty(_result_val))
  648. return (999, "‘测试值’不可为空!");
  649. PassStationDetailRequest request = new PassStationDetailRequest();
  650. request.sn = _sn; // 产品SN
  651. request.slot = _slot; // 槽位编码
  652. request.test_item_num = test_item_num.ToString();
  653. request.function_name = _function_name;
  654. request.test_item = _test_item;
  655. request.result_val = _result_val;
  656. request.status=_status;
  657. request.description = _test_item;
  658. // 上传过站结果
  659. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
  660. //(int, string) iotResult = (0, "");
  661. return iotResult;
  662. }
  663. /// <summary>
  664. /// 显示信息
  665. /// </summary>
  666. /// <param name="msg">信息</param>
  667. public void ShowLog_Iot(string msg)
  668. {
  669. txtInfo.Invoke(new Action(() =>
  670. {
  671. txtInfo_Iot.Text = string.Concat("\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "=> ", msg);
  672. }));
  673. }
  674. // 更改上传类型
  675. private void cmbSendType_Iot_SelectedIndexChanged(object sender, EventArgs e)
  676. {
  677. string iotSendType = cmbSendType_Iot.Text.Trim();
  678. switch (iotSendType)
  679. {
  680. //设备状态
  681. //故障日志
  682. //节拍日志
  683. //操作记录
  684. case "设备状态":
  685. pnlDeviceState.Enabled = true;
  686. pnlFaultLog.Enabled = false;
  687. pnlStationInputBegin.Enabled = false;
  688. pnlOperateLog.Enabled = false;
  689. pnlPassStation.Enabled = false;
  690. pnlPassStationDetail.Enabled = false;
  691. pnlFileUp.Enabled = false;
  692. pnlDeviceState7.Enabled = false;
  693. pnlDeviceState8.Enabled = false;
  694. pnlDeviceState.BackColor = Color.Yellow;
  695. pnlFaultLog.BackColor = Color.Gray;
  696. pnlStationInputBegin.BackColor = Color.Gray;
  697. pnlOperateLog.BackColor = Color.Gray;
  698. pnlPassStation.BackColor = Color.Gray;
  699. pnlPassStationDetail.BackColor = Color.Gray;
  700. pnlFileUp.BackColor = Color.Gray;
  701. pnlDeviceState7.BackColor = Color.Gray;
  702. pnlDeviceState8.BackColor = Color.Gray;
  703. break;
  704. case "故障日志":
  705. pnlDeviceState.Enabled = false;
  706. pnlFaultLog.Enabled = true;
  707. pnlStationInputBegin.Enabled = false;
  708. pnlOperateLog.Enabled = false;
  709. pnlPassStation.Enabled = false;
  710. pnlPassStationDetail.Enabled = false;
  711. pnlFileUp.Enabled = false;
  712. pnlDeviceState7.Enabled = false;
  713. pnlDeviceState8.Enabled = false;
  714. pnlDeviceState.BackColor = Color.Gray;
  715. pnlFaultLog.BackColor = Color.Yellow;
  716. pnlStationInputBegin.BackColor = Color.Gray;
  717. pnlOperateLog.BackColor = Color.Gray;
  718. pnlPassStation.BackColor = Color.Gray;
  719. pnlPassStationDetail.BackColor = Color.Gray;
  720. pnlFileUp.BackColor = Color.Gray;
  721. pnlDeviceState7.BackColor = Color.Gray;
  722. pnlDeviceState8.BackColor = Color.Gray;
  723. break;
  724. case "节拍日志":
  725. pnlDeviceState.Enabled = false;
  726. pnlFaultLog.Enabled = false;
  727. pnlStationInputBegin.Enabled = true;
  728. pnlOperateLog.Enabled = false;
  729. pnlPassStation.Enabled = false;
  730. pnlPassStationDetail.Enabled = false;
  731. pnlFileUp.Enabled = false;
  732. pnlDeviceState7.Enabled = false;
  733. pnlDeviceState8.Enabled = false;
  734. pnlDeviceState.BackColor = Color.Gray;
  735. pnlFaultLog.BackColor = Color.Gray;
  736. pnlStationInputBegin.BackColor = Color.Yellow;
  737. pnlOperateLog.BackColor = Color.Gray;
  738. pnlPassStation.BackColor = Color.Gray;
  739. pnlPassStationDetail.BackColor = Color.Gray;
  740. pnlFileUp.BackColor = Color.Gray;
  741. pnlDeviceState7.BackColor = Color.Gray;
  742. pnlDeviceState8.BackColor = Color.Gray;
  743. break;
  744. case "操作记录":
  745. pnlDeviceState.Enabled = false;
  746. pnlFaultLog.Enabled = false;
  747. pnlStationInputBegin.Enabled = false;
  748. pnlOperateLog.Enabled = true;
  749. pnlPassStation.Enabled = false;
  750. pnlPassStationDetail.Enabled = false;
  751. pnlFileUp.Enabled = false;
  752. pnlDeviceState7.Enabled = false;
  753. pnlDeviceState8.Enabled = false;
  754. pnlDeviceState.BackColor = Color.Gray;
  755. pnlFaultLog.BackColor = Color.Gray;
  756. pnlStationInputBegin.BackColor = Color.Gray;
  757. pnlOperateLog.BackColor = Color.Yellow;
  758. pnlPassStation.BackColor = Color.Gray;
  759. pnlPassStationDetail.BackColor = Color.Gray;
  760. pnlFileUp.BackColor = Color.Gray;
  761. pnlDeviceState7.BackColor = Color.Gray;
  762. pnlDeviceState8.BackColor = Color.Gray;
  763. break;
  764. case "过站结果":
  765. pnlDeviceState.Enabled = false;
  766. pnlFaultLog.Enabled = false;
  767. pnlStationInputBegin.Enabled = false;
  768. pnlOperateLog.Enabled = false;
  769. pnlPassStation.Enabled = true;
  770. pnlPassStationDetail.Enabled = false;
  771. pnlFileUp.Enabled = false;
  772. pnlDeviceState7.Enabled = false;
  773. pnlDeviceState8.Enabled = false;
  774. pnlDeviceState.BackColor = Color.Gray;
  775. pnlFaultLog.BackColor = Color.Gray;
  776. pnlStationInputBegin.BackColor = Color.Gray;
  777. pnlOperateLog.BackColor = Color.Gray;
  778. pnlPassStation.BackColor = Color.Yellow;
  779. pnlPassStationDetail.BackColor = Color.Gray;
  780. pnlFileUp.BackColor = Color.Gray;
  781. pnlDeviceState7.BackColor = Color.Gray;
  782. pnlDeviceState8.BackColor = Color.Gray;
  783. break;
  784. case "过站明细":
  785. pnlDeviceState.Enabled = false;
  786. pnlFaultLog.Enabled = false;
  787. pnlStationInputBegin.Enabled = false;
  788. pnlOperateLog.Enabled = false;
  789. pnlPassStation.Enabled = false;
  790. pnlPassStationDetail.Enabled = true;
  791. pnlFileUp.Enabled = false;
  792. pnlDeviceState7.Enabled = false;
  793. pnlDeviceState8.Enabled = false;
  794. pnlDeviceState.BackColor = Color.Gray;
  795. pnlFaultLog.BackColor = Color.Gray;
  796. pnlStationInputBegin.BackColor = Color.Gray;
  797. pnlOperateLog.BackColor = Color.Gray;
  798. pnlPassStation.BackColor = Color.Gray;
  799. pnlPassStationDetail.BackColor = Color.Yellow;
  800. pnlFileUp.BackColor = Color.Gray;
  801. pnlDeviceState7.BackColor = Color.Gray;
  802. pnlDeviceState8.BackColor = Color.Gray;
  803. break;
  804. case "非结构化":
  805. pnlDeviceState.Enabled = false;
  806. pnlFaultLog.Enabled = false;
  807. pnlStationInputBegin.Enabled = false;
  808. pnlOperateLog.Enabled = false;
  809. pnlPassStation.Enabled = false;
  810. pnlPassStationDetail.Enabled = false;
  811. pnlFileUp.Enabled = true;
  812. pnlDeviceState7.Enabled = false;
  813. pnlDeviceState8.Enabled = false;
  814. pnlDeviceState.BackColor = Color.Gray;
  815. pnlFaultLog.BackColor = Color.Gray;
  816. pnlStationInputBegin.BackColor = Color.Gray;
  817. pnlOperateLog.BackColor = Color.Gray;
  818. pnlPassStation.BackColor = Color.Gray;
  819. pnlPassStationDetail.BackColor = Color.Gray;
  820. pnlFileUp.BackColor = Color.Yellow;
  821. pnlDeviceState7.BackColor = Color.Gray;
  822. pnlDeviceState8.BackColor = Color.Gray;
  823. break;
  824. default:
  825. break;
  826. }
  827. }
  828. // 更改状态类型
  829. private void cmbXiaomiDeviceState_SelectedIndexChanged(object sender, EventArgs e)
  830. {
  831. string xmDeviceState = cmbXiaomiDeviceState.Text.Trim();
  832. if (xmDeviceState == "Fault" || xmDeviceState == "Alarm")
  833. {
  834. label23.Enabled = true;
  835. label24.Enabled = true;
  836. txtFaultCode.Enabled = true;
  837. }
  838. else
  839. {
  840. label23.Enabled = false;
  841. label24.Enabled = false;
  842. txtFaultCode.Enabled = false;
  843. }
  844. }
  845. /// <summary>
  846. /// 上传过站数据_Iot
  847. /// </summary>
  848. /// <param name="mesStation">mes工站名称</param>
  849. /// <returns></returns>
  850. private async Task<(int, string)> SendIotFileUpFun(string mesStation)
  851. {
  852. (int, string) iotResult;
  853. BarcodeSet_t BarcodeSet=new BarcodeSet_t();
  854. BarcodeSet.strProductBarcode= pnlFileUp_sn.Text.Trim() ;
  855. BarcodeSet.strCarrierBarcode = pnlFileUp_slot.Text.Trim();
  856. string StationName = cmbStationName_Iot.Text.Trim();
  857. string code = StationName.Substring(0, 6);
  858. string name = StationName.Substring(6);
  859. string path= pnlFileUp_path.Text.Trim();
  860. Form_Home home= new Form_Home();
  861. // 创建并显示加载提示框
  862. using (var loadingForm = new LoadingForm())
  863. {
  864. loadingForm.Show();
  865. iotResult = await home.SaveDBbyFileInfo(BarcodeSet, code, name, path);
  866. // 关闭加载提示框
  867. loadingForm.Close();
  868. }
  869. // 上传过站结果
  870. //(int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
  871. //(int, string) iotResult = (0, "");
  872. return iotResult;
  873. }
  874. #endregion Iot手动上传 Tap
  875. #region 其他方法
  876. /// <summary>
  877. /// 显示信息
  878. /// </summary>
  879. /// <param name="msg">信息</param>
  880. public void ShowLog(string msg)
  881. {
  882. txtInfo.Invoke(new Action(() =>
  883. {
  884. txtInfo.Text = string.Concat("\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "=> ", msg);
  885. }));
  886. }
  887. /// <summary>
  888. /// 添加记录
  889. /// </summary>
  890. /// <param name="logType">日志类型</param>
  891. /// <param name="msg">日志信息</param>
  892. private void AddMessage(LogType logType, string msg)
  893. {
  894. MessageEvent?.Invoke(logType, msg);
  895. }
  896. #endregion 其他方法
  897. }
  898. public class LoadingForm : Form
  899. {
  900. private Label label;
  901. public LoadingForm()
  902. {
  903. this.Text = "请稍等";
  904. this.Width = 200;
  905. this.Height = 100;
  906. this.StartPosition = FormStartPosition.CenterScreen;
  907. label = new Label
  908. {
  909. Text = "正在处理,请稍等...",
  910. Dock = DockStyle.Fill,
  911. TextAlign = System.Drawing.ContentAlignment.MiddleCenter
  912. };
  913. this.Controls.Add(label);
  914. }
  915. }
  916. }