Form_MESTest.cs 45 KB

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