Form_MESTest.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  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.typ4 = 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. Form_Home home = new Form_Home();
  491. request.beat_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  492. request.action_subject = partSn; // 该动作操作的⽬标对象(SN)
  493. request.action_subject_parent = vSn; // ⼤板SN/载具SN
  494. request.action_location = Form_Home.xiaomiParm.stationCode + "01-SLOT-01"; // 该动作的位置信息(⼯位、槽位),如:F06-GSTPLA11_01-SLOT-01
  495. request.action_material = vIndexSn; // 该动作的物料信息
  496. request.extra = extra; // 额外信息
  497. request.class_level_1 = class_level_1; // 分类层级1
  498. request.class_level_2 = class_level_2; // 分类层级2
  499. request.class_level_3 = class_level_3; // 分类层级3
  500. // 上传
  501. (int, string) iotResult = XiaomiMqttClient_Extend.Write_StationInputBegin(request);
  502. return iotResult;
  503. }
  504. /// <summary>
  505. /// 上传操作记录⽇志_Iot
  506. /// </summary>
  507. /// <param name="mesStation">mes工站名称</param>
  508. /// <returns></returns>
  509. private (int, string) SendIotOperateLogFun(string mesStation)
  510. {
  511. string operateAction = cmbOperateAction.Text.Trim(); // 操作动作
  512. string actionParam = txtActionParam.Text.Trim(); // 动作参数
  513. string operateDesc = txtOperateDesc.Text.Trim(); // 操作描述
  514. string operateResult = cmbOperateResult.Text.Trim(); // 操作结果
  515. if (string.IsNullOrEmpty(operateAction))
  516. return (999, "‘操作动作’不可为空!");
  517. else if (string.IsNullOrEmpty(operateDesc))
  518. return (999, "‘操作描述’不可为空!");
  519. else if (string.IsNullOrEmpty(operateResult))
  520. return (999, "‘操作结果’不可为空!");
  521. OperateLogRequest request = new OperateLogRequest();
  522. request.software_version = "V" + Application.ProductVersion; // 软件版本号;如:V1.2.4
  523. request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 操作时间(2022-06-01 14:27:57.283)
  524. request.operate_action = operateAction; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
  525. request.action_param = actionParam; // 动作参数;选填,附带额外的信息
  526. request.operate_module = "MES调试模块"; // 操作模块;选填
  527. request.operate_page = "手动调试页面"; // 操作⻚⾯;选填
  528. request.current_process = Process.GetCurrentProcess()?.Id.ToString(); // 当前进程;进程ID
  529. request.operate_desc = operateDesc; // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
  530. request.operate_result = operateResult; // 操作结果
  531. //request.operator_name = GlobalContext.currentRole; // 操作账号名;填当前操作⽤⼾,如⽆则填default
  532. // 上传
  533. (int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
  534. //(int, string) iotResult=(0,"");
  535. return iotResult;
  536. }
  537. /// <summary>
  538. /// 上传过站数据_Iot
  539. /// </summary>
  540. /// <param name="mesStation">mes工站名称</param>
  541. /// <returns></returns>
  542. private (int, string) SendIotPassStationFun(string mesStation)
  543. {
  544. string stationStr = cmbStationName_Iot.Text.Trim(); // 工站名
  545. string slot = txtSlot.Text.Trim(); // 槽位编码
  546. string sn = txtSn_PassStation.Text.Trim(); // 产品SN
  547. string enter_status = cmbEnterStatus.Text.Trim(); // 进站状态
  548. string result = cmbResult.Text.Trim(); // 过站结果
  549. string work_type = cmbWorkType.Text.Trim(); // 作业类型
  550. if (string.IsNullOrEmpty(slot))
  551. return (999, "‘槽位编码’不可为空!");
  552. else if (string.IsNullOrEmpty(sn))
  553. return (999, "‘产品SN’不可为空!");
  554. else if (string.IsNullOrEmpty(enter_status))
  555. return (999, "‘进站状态’不可为空!");
  556. else if (string.IsNullOrEmpty(result))
  557. return (999, "‘过站结果’不可为空!");
  558. else if (string.IsNullOrEmpty(work_type))
  559. return (999, "‘作业类型’不可为空!");
  560. PassStationResultRequest request = new PassStationResultRequest();
  561. request.project_code = GlobalContext.Project_Code; // 项⽬编码
  562. request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
  563. request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
  564. request.line_code = GlobalContext.LineCode; // 线体编码
  565. switch (stationStr)
  566. {
  567. case "[OP10]壳体清洁上料":
  568. request.work_station = GlobalContext.S1_work_station; // ⼯站
  569. request.device_code = GlobalContext.S1_device_code; // 装备编码
  570. break;
  571. case "[OP20]上盖板上料装备":
  572. request.work_station = GlobalContext.S2_work_station; // ⼯站
  573. request.device_code = GlobalContext.S2_device_code; // 装备编码
  574. break;
  575. case "[OP30]点散热胶装备_Left":
  576. request.work_station = GlobalContext.s3_1_work_station; // ⼯站
  577. request.device_code = GlobalContext.s3_1_device_code; // 装备编码
  578. break;
  579. case "[OP30]点散热胶装备_Right":
  580. request.work_station = GlobalContext.s3_2_work_station; // ⼯站
  581. request.device_code = GlobalContext.s3_2_device_code; // 装备编码
  582. break;
  583. case "[OP40]胶线检测":
  584. request.work_station = GlobalContext.s4_work_station; // ⼯站
  585. request.device_code = GlobalContext.s4_device_code; // 装备编码
  586. break;
  587. case "[OP50]ADD板上料组装装备":
  588. request.work_station = GlobalContext.s5_work_station; // ⼯站
  589. request.device_code = GlobalContext.s5_device_code; // 装备编码
  590. break;
  591. case "[OP60]组上盖板":
  592. request.work_station = GlobalContext.s6_work_station; // ⼯站
  593. request.device_code = GlobalContext.s6_device_code; // 装备编码
  594. break;
  595. case "[OP70]上盖板锁螺丝_Left":
  596. request.work_station = GlobalContext.s7_1_work_station; // ⼯站
  597. request.device_code = GlobalContext.s7_1_device_code; // 装备编码
  598. break;
  599. case "[OP70]上盖板锁螺丝_Right":
  600. request.work_station = GlobalContext.s7_2_work_station; // ⼯站
  601. request.device_code = GlobalContext.s7_2_device_code; // 装备编码
  602. break;
  603. case "[OP80]NG下料":
  604. request.work_station = GlobalContext.s8_work_station; // ⼯站
  605. request.device_code = GlobalContext.s8_device_code; // 装备编码
  606. break;
  607. case "[OP90]半成品下料":
  608. request.work_station = GlobalContext.s9_work_station; // ⼯站
  609. request.device_code = GlobalContext.s9_device_code; // 装备编码
  610. break;
  611. }
  612. request.station = mesStation;
  613. request.process_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
  614. request.slot = "01-SLOT-01"; // 槽位编码
  615. request.sn = sn; // 产品SN
  616. request.enter_status = enter_status; // 进站状态
  617. request.result = result; // 过站结果
  618. request.work_type = work_type; // 作业类型
  619. // 上传过站结果
  620. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
  621. //(int, string) iotResult = (0, "");
  622. return iotResult;
  623. }
  624. private int test_item_num = 0;
  625. /// <summary>
  626. /// 上传过站数据_Iot
  627. /// </summary>
  628. /// <param name="mesStation">mes工站名称</param>
  629. /// <returns></returns>
  630. private (int, string) SendIotPassStationDetailFun(string mesStation)
  631. {
  632. test_item_num += 1;//⽰例:1,2,递增
  633. string _stationStr = cmbStationName_Iot.Text.Trim(); // 工站名
  634. string _slot = PassStationDetail_slot.Text.Trim(); // 槽位编码
  635. string _sn = PassStationDetail_SN.Text.Trim(); // 产品SN
  636. string _function_name= pnlPassStationDetail_functionNname.Text.Trim();
  637. string _test_item= pnlPassStationDetail_testItem.Text.Trim();
  638. string _result_val= pnlPassStationDetail_resultVal.Text.Trim();
  639. string _status = pnlPassStationDetail_status.Text.Trim();
  640. if (string.IsNullOrEmpty(_slot))
  641. return (999, "‘槽位编码’不可为空!");
  642. else if (string.IsNullOrEmpty(_sn))
  643. return (999, "‘产品SN’不可为空!");
  644. else if (string.IsNullOrEmpty(_function_name))
  645. return (999, "‘功能名称’不可为空!");
  646. else if (string.IsNullOrEmpty(_test_item))
  647. return (999, "‘测试项’不可为空!");
  648. else if (string.IsNullOrEmpty(_result_val))
  649. return (999, "‘测试值’不可为空!");
  650. PassStationDetailRequest request = new PassStationDetailRequest();
  651. request.sn = _sn; // 产品SN
  652. request.slot = "01-SLOT-01"; // 槽位编码
  653. request.test_item_num = test_item_num.ToString();
  654. request.function_name = _function_name;
  655. request.test_item = _test_item;
  656. request.result_val = _result_val;
  657. request.status=_status;
  658. request.description = _test_item;
  659. // 上传过站结果
  660. (int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
  661. //(int, string) iotResult = (0, "");
  662. return iotResult;
  663. }
  664. /// <summary>
  665. /// 显示信息
  666. /// </summary>
  667. /// <param name="msg">信息</param>
  668. public void ShowLog_Iot(string msg)
  669. {
  670. txtInfo.Invoke(new Action(() =>
  671. {
  672. txtInfo_Iot.Text = string.Concat("\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "=> ", msg);
  673. }));
  674. }
  675. // 更改上传类型
  676. private void cmbSendType_Iot_SelectedIndexChanged(object sender, EventArgs e)
  677. {
  678. string iotSendType = cmbSendType_Iot.Text.Trim();
  679. switch (iotSendType)
  680. {
  681. //设备状态
  682. //故障日志
  683. //节拍日志
  684. //操作记录
  685. case "设备状态":
  686. pnlDeviceState.Enabled = true;
  687. pnlFaultLog.Enabled = false;
  688. pnlStationInputBegin.Enabled = false;
  689. pnlOperateLog.Enabled = false;
  690. pnlPassStation.Enabled = false;
  691. pnlPassStationDetail.Enabled = false;
  692. pnlFileUp.Enabled = false;
  693. pnlDeviceState7.Enabled = false;
  694. pnlDeviceState8.Enabled = false;
  695. pnlDeviceState.BackColor = Color.Yellow;
  696. pnlFaultLog.BackColor = Color.Gray;
  697. pnlStationInputBegin.BackColor = Color.Gray;
  698. pnlOperateLog.BackColor = Color.Gray;
  699. pnlPassStation.BackColor = Color.Gray;
  700. pnlPassStationDetail.BackColor = Color.Gray;
  701. pnlFileUp.BackColor = Color.Gray;
  702. pnlDeviceState7.BackColor = Color.Gray;
  703. pnlDeviceState8.BackColor = Color.Gray;
  704. break;
  705. case "故障日志":
  706. pnlDeviceState.Enabled = false;
  707. pnlFaultLog.Enabled = true;
  708. pnlStationInputBegin.Enabled = false;
  709. pnlOperateLog.Enabled = false;
  710. pnlPassStation.Enabled = false;
  711. pnlPassStationDetail.Enabled = false;
  712. pnlFileUp.Enabled = false;
  713. pnlDeviceState7.Enabled = false;
  714. pnlDeviceState8.Enabled = false;
  715. pnlDeviceState.BackColor = Color.Gray;
  716. pnlFaultLog.BackColor = Color.Yellow;
  717. pnlStationInputBegin.BackColor = Color.Gray;
  718. pnlOperateLog.BackColor = Color.Gray;
  719. pnlPassStation.BackColor = Color.Gray;
  720. pnlPassStationDetail.BackColor = Color.Gray;
  721. pnlFileUp.BackColor = Color.Gray;
  722. pnlDeviceState7.BackColor = Color.Gray;
  723. pnlDeviceState8.BackColor = Color.Gray;
  724. break;
  725. case "节拍日志":
  726. pnlDeviceState.Enabled = false;
  727. pnlFaultLog.Enabled = false;
  728. pnlStationInputBegin.Enabled = true;
  729. pnlOperateLog.Enabled = false;
  730. pnlPassStation.Enabled = false;
  731. pnlPassStationDetail.Enabled = false;
  732. pnlFileUp.Enabled = false;
  733. pnlDeviceState7.Enabled = false;
  734. pnlDeviceState8.Enabled = false;
  735. pnlDeviceState.BackColor = Color.Gray;
  736. pnlFaultLog.BackColor = Color.Gray;
  737. pnlStationInputBegin.BackColor = Color.Yellow;
  738. pnlOperateLog.BackColor = Color.Gray;
  739. pnlPassStation.BackColor = Color.Gray;
  740. pnlPassStationDetail.BackColor = Color.Gray;
  741. pnlFileUp.BackColor = Color.Gray;
  742. pnlDeviceState7.BackColor = Color.Gray;
  743. pnlDeviceState8.BackColor = Color.Gray;
  744. break;
  745. case "操作记录":
  746. pnlDeviceState.Enabled = false;
  747. pnlFaultLog.Enabled = false;
  748. pnlStationInputBegin.Enabled = false;
  749. pnlOperateLog.Enabled = true;
  750. pnlPassStation.Enabled = false;
  751. pnlPassStationDetail.Enabled = false;
  752. pnlFileUp.Enabled = false;
  753. pnlDeviceState7.Enabled = false;
  754. pnlDeviceState8.Enabled = false;
  755. pnlDeviceState.BackColor = Color.Gray;
  756. pnlFaultLog.BackColor = Color.Gray;
  757. pnlStationInputBegin.BackColor = Color.Gray;
  758. pnlOperateLog.BackColor = Color.Yellow;
  759. pnlPassStation.BackColor = Color.Gray;
  760. pnlPassStationDetail.BackColor = Color.Gray;
  761. pnlFileUp.BackColor = Color.Gray;
  762. pnlDeviceState7.BackColor = Color.Gray;
  763. pnlDeviceState8.BackColor = Color.Gray;
  764. break;
  765. case "过站结果":
  766. pnlDeviceState.Enabled = false;
  767. pnlFaultLog.Enabled = false;
  768. pnlStationInputBegin.Enabled = false;
  769. pnlOperateLog.Enabled = false;
  770. pnlPassStation.Enabled = true;
  771. pnlPassStationDetail.Enabled = false;
  772. pnlFileUp.Enabled = false;
  773. pnlDeviceState7.Enabled = false;
  774. pnlDeviceState8.Enabled = false;
  775. pnlDeviceState.BackColor = Color.Gray;
  776. pnlFaultLog.BackColor = Color.Gray;
  777. pnlStationInputBegin.BackColor = Color.Gray;
  778. pnlOperateLog.BackColor = Color.Gray;
  779. pnlPassStation.BackColor = Color.Yellow;
  780. pnlPassStationDetail.BackColor = Color.Gray;
  781. pnlFileUp.BackColor = Color.Gray;
  782. pnlDeviceState7.BackColor = Color.Gray;
  783. pnlDeviceState8.BackColor = Color.Gray;
  784. break;
  785. case "过站明细":
  786. pnlDeviceState.Enabled = false;
  787. pnlFaultLog.Enabled = false;
  788. pnlStationInputBegin.Enabled = false;
  789. pnlOperateLog.Enabled = false;
  790. pnlPassStation.Enabled = false;
  791. pnlPassStationDetail.Enabled = true;
  792. pnlFileUp.Enabled = false;
  793. pnlDeviceState7.Enabled = false;
  794. pnlDeviceState8.Enabled = false;
  795. pnlDeviceState.BackColor = Color.Gray;
  796. pnlFaultLog.BackColor = Color.Gray;
  797. pnlStationInputBegin.BackColor = Color.Gray;
  798. pnlOperateLog.BackColor = Color.Gray;
  799. pnlPassStation.BackColor = Color.Gray;
  800. pnlPassStationDetail.BackColor = Color.Yellow;
  801. pnlFileUp.BackColor = Color.Gray;
  802. pnlDeviceState7.BackColor = Color.Gray;
  803. pnlDeviceState8.BackColor = Color.Gray;
  804. break;
  805. case "非结构化":
  806. pnlDeviceState.Enabled = false;
  807. pnlFaultLog.Enabled = false;
  808. pnlStationInputBegin.Enabled = false;
  809. pnlOperateLog.Enabled = false;
  810. pnlPassStation.Enabled = false;
  811. pnlPassStationDetail.Enabled = false;
  812. pnlFileUp.Enabled = true;
  813. pnlDeviceState7.Enabled = false;
  814. pnlDeviceState8.Enabled = false;
  815. pnlDeviceState.BackColor = Color.Gray;
  816. pnlFaultLog.BackColor = Color.Gray;
  817. pnlStationInputBegin.BackColor = Color.Gray;
  818. pnlOperateLog.BackColor = Color.Gray;
  819. pnlPassStation.BackColor = Color.Gray;
  820. pnlPassStationDetail.BackColor = Color.Gray;
  821. pnlFileUp.BackColor = Color.Yellow;
  822. pnlDeviceState7.BackColor = Color.Gray;
  823. pnlDeviceState8.BackColor = Color.Gray;
  824. break;
  825. default:
  826. break;
  827. }
  828. }
  829. // 更改状态类型
  830. private void cmbXiaomiDeviceState_SelectedIndexChanged(object sender, EventArgs e)
  831. {
  832. string xmDeviceState = cmbXiaomiDeviceState.Text.Trim();
  833. if (xmDeviceState == "Fault" || xmDeviceState == "Alarm")
  834. {
  835. label23.Enabled = true;
  836. label24.Enabled = true;
  837. txtFaultCode.Enabled = true;
  838. }
  839. else
  840. {
  841. label23.Enabled = false;
  842. label24.Enabled = false;
  843. txtFaultCode.Enabled = false;
  844. }
  845. }
  846. /// <summary>
  847. /// 上传过站数据_Iot
  848. /// </summary>
  849. /// <param name="mesStation">mes工站名称</param>
  850. /// <returns></returns>
  851. private async Task<(int, string)> SendIotFileUpFun(string mesStation)
  852. {
  853. (int, string) iotResult;
  854. BarcodeSet_t BarcodeSet=new BarcodeSet_t();
  855. BarcodeSet.strProductBarcode= pnlFileUp_sn.Text.Trim() ;
  856. BarcodeSet.strCarrierBarcode = pnlFileUp_slot.Text.Trim();
  857. string StationName = cmbStationName_Iot.Text.Trim();
  858. string code = StationName.Substring(0, 6);
  859. string name = StationName.Substring(6);
  860. string path= pnlFileUp_path.Text.Trim();
  861. Form_Home home= new Form_Home();
  862. // 创建并显示加载提示框
  863. using (var loadingForm = new LoadingForm())
  864. {
  865. loadingForm.Show();
  866. iotResult = await home.SaveDBbyFileInfo(BarcodeSet, code, name,1, path);
  867. // 关闭加载提示框
  868. loadingForm.Close();
  869. }
  870. // 上传过站结果
  871. //(int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
  872. //(int, string) iotResult = (0, "");
  873. return iotResult;
  874. }
  875. #endregion Iot手动上传 Tap
  876. #region 其他方法
  877. /// <summary>
  878. /// 显示信息
  879. /// </summary>
  880. /// <param name="msg">信息</param>
  881. public void ShowLog(string msg)
  882. {
  883. txtInfo.Invoke(new Action(() =>
  884. {
  885. txtInfo.Text = string.Concat("\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "=> ", msg);
  886. }));
  887. }
  888. /// <summary>
  889. /// 添加记录
  890. /// </summary>
  891. /// <param name="logType">日志类型</param>
  892. /// <param name="msg">日志信息</param>
  893. private void AddMessage(LogType logType, string msg)
  894. {
  895. MessageEvent?.Invoke(logType, msg);
  896. }
  897. #endregion 其他方法
  898. }
  899. public class LoadingForm : Form
  900. {
  901. private Label label;
  902. public LoadingForm()
  903. {
  904. Text = "请稍候";
  905. Size = new Size(200, 100);
  906. StartPosition = FormStartPosition.CenterScreen;
  907. FormBorderStyle = FormBorderStyle.FixedDialog;
  908. ControlBox = false;
  909. TopMost = true;
  910. label = new Label
  911. {
  912. Text = "正在处理,请稍等...",
  913. Dock = DockStyle.Fill,
  914. TextAlign = System.Drawing.ContentAlignment.MiddleCenter
  915. };
  916. this.Controls.Add(label);
  917. }
  918. }
  919. }