MainPage.xaml.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. 
  2. using CCDCount.DLL;
  3. using CCDCount.DLL.SqlDataClass;
  4. using CCDCount.MODEL.AuditTrailModel;
  5. using CCDCount.MODEL.ConfigModel;
  6. using LogClass;
  7. using MvCameraControl;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Diagnostics;
  11. using System.Drawing;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.Windows.Data;
  19. using System.Windows.Documents;
  20. using System.Windows.Input;
  21. using System.Windows.Interop;
  22. using System.Windows.Media;
  23. using System.Windows.Media.Imaging;
  24. using static System.Net.Mime.MediaTypeNames;
  25. namespace CCDCountWpf.WpfPage
  26. {
  27. /// <summary>
  28. /// MainPage.xaml 的交互逻辑
  29. /// </summary>
  30. public partial class MainPage : Page
  31. {
  32. #region 变量与实例
  33. #endregion
  34. public MainPage()
  35. {
  36. InitializeComponent();
  37. DataContext = ShowMessageBus.ShowBinding;
  38. InitFormationItems();
  39. }
  40. private void DataClear_Click(object sender, RoutedEventArgs e)
  41. {
  42. if(MessageBus.MainThreadS.Count<MessageBus.NowLoadCameraIndex+1)
  43. return;
  44. MessageBus.MainThreadS[MessageBus.NowLoadCameraIndex].ClearHistoryActive();
  45. }
  46. private void Page_Loaded(object sender, RoutedEventArgs e)
  47. {
  48. this.Width = double.NaN; // 等效于 Auto
  49. this.Height = double.NaN;
  50. StopIdentifyBtn.IsEnabled = false;
  51. StopIdentifyBtn.Opacity = 0.5;
  52. if(MessageBus.NowLoadCameraIndex>=0)
  53. {
  54. if (MessageBus.MainThreadS[MessageBus.NowLoadCameraIndex].CameraRunStatic)
  55. {
  56. StartIdentifyBtn.IsEnabled = false;
  57. StartIdentifyBtn.Opacity = 0.5;
  58. StopIdentifyBtn.IsEnabled = true;
  59. StopIdentifyBtn.Opacity = 1;
  60. }
  61. else
  62. {
  63. StartIdentifyBtn.IsEnabled = true;
  64. StartIdentifyBtn.Opacity = 1;
  65. StopIdentifyBtn.IsEnabled = false;
  66. StopIdentifyBtn.Opacity = 0.5;
  67. }
  68. }
  69. }
  70. private void MiniShowImageBox2_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  71. {
  72. if(MessageBus.MainThreadS.Count < 2) return;
  73. MessageBus.NowLoadCameraIndex = 1;
  74. }
  75. private void MiniShowImageBox1_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  76. {
  77. if (MessageBus.MainThreadS.Count < 1) return;
  78. MessageBus.NowLoadCameraIndex = 0;
  79. }
  80. private void MiniShowImageBox3_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  81. {
  82. if (MessageBus.MainThreadS.Count < 3) return;
  83. MessageBus.NowLoadCameraIndex = 2;
  84. }
  85. private void MiniShowImageBox4_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  86. {
  87. if (MessageBus.MainThreadS.Count < 4) return;
  88. MessageBus.NowLoadCameraIndex = 3;
  89. }
  90. /// <summary>
  91. /// 启动相机识别
  92. /// </summary>
  93. private void RunCameraIdentify()
  94. {
  95. for (int i = 0; i < MessageBus.MainThreadS.Count; i++)
  96. {
  97. MessageBus.MainThreadS[i].BatchNumber = ShowMessageBus.ShowBinding.BatchNumber;
  98. if (MessageBus.MainThreadS[i].CameraConfigIsChange)
  99. {
  100. MessageBus.MainThreadS[i].ReLoadCameraConfig();
  101. }
  102. //启动单相机实例的全部线程
  103. if (!MessageBus.MainThreadS[i].StartMianThread())
  104. {
  105. FaultLog.RecordErrorMessage(MessageBus.MainThreadS[i].cameraConfig.DeviceName + "_" + MessageBus.MainThreadS[i].cameraConfig.CameraSNNum + "启动失败", "CCDCountWpf:MainPage-RunCameraIdentify");
  106. //LOG.error(MessageBus.MainThreadS[i].cameraConfig.DeviceName + "_" + MessageBus.MainThreadS[i].cameraConfig.CameraSNNum + "启动失败");
  107. MessageBox.Show(MessageBus.MainThreadS[i].cameraConfig.DeviceName + "_" + MessageBus.MainThreadS[i].cameraConfig.CameraSNNum + "启动失败");
  108. continue;
  109. }
  110. }
  111. MessageBus.NowLoadCammeraSN = MessageBus.MainThreadS[0].cameraConfig.CameraSNNum;
  112. MessageBus.SeetingNowLoadInMaThreadsIndex = 0;
  113. MessageBus.NowLoadCameraIndex = 0;
  114. }
  115. /// <summary>
  116. /// 停止相机识别
  117. /// </summary>
  118. private void StopCameraIdentify()
  119. {
  120. for (int i = 0; i < MessageBus.MainThreadS.Count; i++)
  121. {
  122. //启动单相机实例的全部线程
  123. if (!MessageBus.MainThreadS[i].StopMianThread())
  124. {
  125. FaultLog.RecordErrorMessage(MessageBus.MainThreadS[i].cameraConfig.DeviceName + "_" + MessageBus.MainThreadS[i].cameraConfig.CameraSNNum + "关闭失败", "CCDCountWpf:MainPage-StopCameraIdentify");
  126. MessageBox.Show(MessageBus.MainThreadS[i].cameraConfig.DeviceName + "_" + MessageBus.MainThreadS[i].cameraConfig.CameraSNNum + "关闭失败");
  127. continue;
  128. }
  129. }
  130. }
  131. private bool RunBatchIsRun =false;
  132. /// <summary>
  133. /// 运行批次记录
  134. /// </summary>
  135. /// <param name="BatchNumber"></param>
  136. private void RunBatchRecord(string BatchNumber)
  137. {
  138. if (RunBatchIsRun)
  139. {
  140. return;
  141. }
  142. List<BatchRecordModel> batchRecordModels = new List<BatchRecordModel>();
  143. Stopwatch stopwatch = new Stopwatch();
  144. BatchMessSqliteDataClass batchMessSqliteData = new BatchMessSqliteDataClass($"{AppDomain.CurrentDomain.BaseDirectory}DATA\\BatchData\\BatchData_{BatchNumber}.db");
  145. RunBatchIsRun = true;
  146. Task.Run(() =>
  147. {
  148. while (RunBatchIsRun)
  149. {
  150. stopwatch.Restart();
  151. DateTime RecordTime = DateTime.Now;
  152. var OutTimeBatch = batchRecordModels.Where(x => x.RecordTime.AddMinutes(1) < RecordTime).ToList();
  153. OutTimeBatch.ForEach(x => batchRecordModels.Remove(x));
  154. PlcSettingMessageBus.pLCManagement.ReadBottingVibrationTableHighSpeedValue(out ushort BottingVibrationTableHighSpeedValue, out ushort FilterVibrationTableHighSpeedValue, out ushort CountVibrationTableHighSpeedValue);
  155. PlcSettingMessageBus.pLCManagement.ReadBottingCount(out ushort BottingCount);
  156. ushort CountSPeed = (ushort)(batchRecordModels.Count() > 0 ? (BottingCount - batchRecordModels.Min(o => o.BottingCount)) > 0 ? BottingCount - batchRecordModels.Min(o => o.BottingCount) : 0 : 0);
  157. ShowMessageBus.ShowBinding.BottingSpeed = CountSPeed;
  158. BatchRecordModel batchRecordModel = new BatchRecordModel
  159. {
  160. BatchNunber = BatchNumber,
  161. MaterialCylinderVibrationTableSpeed = BottingVibrationTableHighSpeedValue,
  162. FilterVibrationTableSpeed = FilterVibrationTableHighSpeedValue,
  163. CountVibrationTableSpeed = CountVibrationTableHighSpeedValue,
  164. BottingCount = BottingCount,
  165. BottingSpeed = CountSPeed,
  166. RecordTime = RecordTime
  167. };
  168. batchMessSqliteData.InsertBatchMessage(batchRecordModel);
  169. batchRecordModels.Add(batchRecordModel);
  170. stopwatch.Stop();
  171. int SleepTime = 998 - (int)stopwatch.ElapsedMilliseconds;
  172. if(SleepTime > 0)
  173. {
  174. Thread.Sleep(SleepTime);
  175. }
  176. }
  177. });
  178. }
  179. private void StopBatchRecord()
  180. {
  181. RunBatchIsRun = false;
  182. }
  183. private void StartIdentifyBtn_Click(object sender, RoutedEventArgs e)
  184. {
  185. if(String.IsNullOrWhiteSpace(ShowMessageBus.ShowBinding.BatchNumber))
  186. {
  187. MessageBox.Show("请输入批次号!");
  188. return;
  189. }
  190. RunBatchRecord(ShowMessageBus.ShowBinding.BatchNumber);
  191. RunCameraIdentify();
  192. StartIdentifyBtn.IsEnabled = false;
  193. StartIdentifyBtn.Opacity = 0.5;
  194. StopIdentifyBtn.IsEnabled = true;
  195. StopIdentifyBtn.Opacity = 1;
  196. if(PlcSettingMessageBus.pLCManagement.IsConnect)
  197. {
  198. PlcSettingMessageBus.pLCManagement.InitiateToTrue();
  199. }
  200. }
  201. private void StopIdentifyBtn_Click(object sender, RoutedEventArgs e)
  202. {
  203. StopCameraIdentify();
  204. StopBatchRecord();
  205. StartIdentifyBtn.IsEnabled = true;
  206. StartIdentifyBtn.Opacity = 1;
  207. StopIdentifyBtn.IsEnabled = false;
  208. StopIdentifyBtn.Opacity = 0.5;
  209. if (PlcSettingMessageBus.pLCManagement.IsConnect)
  210. {
  211. PlcSettingMessageBus.pLCManagement.StopToTrue();
  212. }
  213. }
  214. private void BottingMaterialCylinderVibrationTableHighSpeedValueUpUpBtn_Click(object sender, RoutedEventArgs e)
  215. {
  216. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottingMaterialCylinderVibrationTableHighSpeedValue + 10) >
  217. PlcSettingMessageBus.PlcMessageShowBindage.BottingMaterialCylinderVibrationTableHighSpeedValue)
  218. {
  219. PlcSettingMessageBus.PlcMessageShowBindage.BottingMaterialCylinderVibrationTableHighSpeedValue += 10;
  220. }
  221. }
  222. private void BottingMaterialCylinderVibrationTableHighSpeedValueUpBtn_Click(object sender, RoutedEventArgs e)
  223. {
  224. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottingMaterialCylinderVibrationTableHighSpeedValue + 1) >
  225. PlcSettingMessageBus.PlcMessageShowBindage.BottingMaterialCylinderVibrationTableHighSpeedValue)
  226. {
  227. PlcSettingMessageBus.PlcMessageShowBindage.BottingMaterialCylinderVibrationTableHighSpeedValue += 1;
  228. }
  229. }
  230. private void BottingMaterialCylinderVibrationTableHighSpeedValueDownBtn_Click(object sender, RoutedEventArgs e)
  231. {
  232. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottingMaterialCylinderVibrationTableHighSpeedValue - 1) <
  233. PlcSettingMessageBus.PlcMessageShowBindage.BottingMaterialCylinderVibrationTableHighSpeedValue)
  234. {
  235. PlcSettingMessageBus.PlcMessageShowBindage.BottingMaterialCylinderVibrationTableHighSpeedValue -= 1;
  236. }
  237. }
  238. private void BottingMaterialCylinderVibrationTableHighSpeedValueDownDownBtn_Click(object sender, RoutedEventArgs e)
  239. {
  240. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottingMaterialCylinderVibrationTableHighSpeedValue - 10) <
  241. PlcSettingMessageBus.PlcMessageShowBindage.BottingMaterialCylinderVibrationTableHighSpeedValue)
  242. {
  243. PlcSettingMessageBus.PlcMessageShowBindage.BottingMaterialCylinderVibrationTableHighSpeedValue -= 10;
  244. }
  245. }
  246. private void BottingFilterVibrationTableHighSpeedValueUpUpBtn_Click(object sender, RoutedEventArgs e)
  247. {
  248. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottingFilterVibrationTableHighSpeedValue + 10) >
  249. PlcSettingMessageBus.PlcMessageShowBindage.BottingFilterVibrationTableHighSpeedValue)
  250. {
  251. PlcSettingMessageBus.PlcMessageShowBindage.BottingFilterVibrationTableHighSpeedValue += 10;
  252. }
  253. }
  254. private void BottingFilterVibrationTableHighSpeedValueUpBtn_Click(object sender, RoutedEventArgs e)
  255. {
  256. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottingFilterVibrationTableHighSpeedValue + 1) >
  257. PlcSettingMessageBus.PlcMessageShowBindage.BottingFilterVibrationTableHighSpeedValue)
  258. {
  259. PlcSettingMessageBus.PlcMessageShowBindage.BottingFilterVibrationTableHighSpeedValue += 1;
  260. }
  261. }
  262. private void BottingFilterVibrationTableHighSpeedValueDownBtn_Click(object sender, RoutedEventArgs e)
  263. {
  264. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottingFilterVibrationTableHighSpeedValue - 1) <
  265. PlcSettingMessageBus.PlcMessageShowBindage.BottingFilterVibrationTableHighSpeedValue)
  266. {
  267. PlcSettingMessageBus.PlcMessageShowBindage.BottingFilterVibrationTableHighSpeedValue -= 1;
  268. }
  269. }
  270. private void BottingFilterVibrationTableHighSpeedValueDownDownBtn_Click(object sender, RoutedEventArgs e)
  271. {
  272. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottingFilterVibrationTableHighSpeedValue - 10) <
  273. PlcSettingMessageBus.PlcMessageShowBindage.BottingFilterVibrationTableHighSpeedValue)
  274. {
  275. PlcSettingMessageBus.PlcMessageShowBindage.BottingFilterVibrationTableHighSpeedValue -= 10;
  276. }
  277. }
  278. private void BottingCountVibrationTableHighSpeedValueUpUpBtn_Click(object sender, RoutedEventArgs e)
  279. {
  280. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottingCountVibrationTableHighSpeedValue + 10) >
  281. PlcSettingMessageBus.PlcMessageShowBindage.BottingCountVibrationTableHighSpeedValue)
  282. {
  283. PlcSettingMessageBus.PlcMessageShowBindage.BottingCountVibrationTableHighSpeedValue += 10;
  284. }
  285. }
  286. private void BottingCountVibrationTableHighSpeedValueUpBtn_Click(object sender, RoutedEventArgs e)
  287. {
  288. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottingCountVibrationTableHighSpeedValue + 1) >
  289. PlcSettingMessageBus.PlcMessageShowBindage.BottingCountVibrationTableHighSpeedValue)
  290. {
  291. PlcSettingMessageBus.PlcMessageShowBindage.BottingCountVibrationTableHighSpeedValue += 1;
  292. }
  293. }
  294. private void BottingCountVibrationTableHighSpeedValueDownBtn_Click(object sender, RoutedEventArgs e)
  295. {
  296. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottingCountVibrationTableHighSpeedValue - 1) <
  297. PlcSettingMessageBus.PlcMessageShowBindage.BottingCountVibrationTableHighSpeedValue)
  298. {
  299. PlcSettingMessageBus.PlcMessageShowBindage.BottingCountVibrationTableHighSpeedValue -= 1;
  300. }
  301. }
  302. private void BottingCountVibrationTableHighSpeedValueDownDownBtn_Click(object sender, RoutedEventArgs e)
  303. {
  304. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottingCountVibrationTableHighSpeedValue - 10) <
  305. PlcSettingMessageBus.PlcMessageShowBindage.BottingCountVibrationTableHighSpeedValue)
  306. {
  307. PlcSettingMessageBus.PlcMessageShowBindage.BottingCountVibrationTableHighSpeedValue -= 10;
  308. }
  309. }
  310. private void BottValueSetUpUpBtn_Click(object sender, RoutedEventArgs e)
  311. {
  312. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet + 5) >
  313. PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet)
  314. {
  315. PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet += 5;
  316. }
  317. }
  318. private void BottValueSetUpBtn_Click(object sender, RoutedEventArgs e)
  319. {
  320. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet + 1) >
  321. PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet)
  322. {
  323. PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet += 1;
  324. }
  325. }
  326. private void BottValueSetDownBtn_Click(object sender, RoutedEventArgs e)
  327. {
  328. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet - 1) <
  329. PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet)
  330. {
  331. PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet -= 1;
  332. }
  333. }
  334. private void BottValueSetDownDownBtn_Click(object sender, RoutedEventArgs e)
  335. {
  336. if ((ushort)(PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet - 5) <
  337. PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet)
  338. {
  339. PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet -= 5;
  340. }
  341. }
  342. private void TextBox_KeyDown(object sender,KeyEventArgs e)
  343. {
  344. if (e.Key == Key.Enter)
  345. {
  346. TextBox textBox = sender as TextBox;
  347. if (textBox != null)
  348. {
  349. // 强制更新源数据
  350. BindingExpression bindingExpression = textBox.GetBindingExpression(TextBox.TextProperty);
  351. bindingExpression.UpdateSource();
  352. }
  353. }
  354. }
  355. /// <summary>
  356. /// 初始化配方列表
  357. /// </summary>
  358. private void InitFormationItems()
  359. {
  360. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Formulations";
  361. if (!Directory.Exists(folderPath))
  362. {
  363. // 创建文件夹
  364. Directory.CreateDirectory(folderPath);
  365. }
  366. try
  367. {
  368. // 获取文件列表(包含子目录)
  369. string[] files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories);
  370. ShowMessageBus.ShowBinding.FormulationItems.Clear();
  371. foreach (string file in files)
  372. {
  373. ShowMessageBus.ShowBinding.FormulationItems.Add(Path.GetFileNameWithoutExtension(file));
  374. }
  375. if (ShowMessageBus.ShowBinding.FormulationName != null && ShowMessageBus.ShowBinding.FormulationName != string.Empty)
  376. {
  377. try
  378. {
  379. FormulationCoBox.SelectedItem = ShowMessageBus.ShowBinding.FormulationName;
  380. }
  381. catch { }
  382. }
  383. }
  384. catch
  385. { }
  386. }
  387. private void SaveFormulationBtn_Click(object sender, RoutedEventArgs e)
  388. {
  389. if (string.IsNullOrEmpty(ShowMessageBus.ShowBinding.FormulationName))
  390. {
  391. MessageBox.Show("请输入配方名称!");
  392. return;
  393. }
  394. var ParaValue = PlcSettingMessageBus.pLCManagement.ReadAllPara();
  395. FormulationConfigClass formulationConfigClass = FormulationClass.InitFormulation(
  396. MessageBus.NowSettingLoadMainThread.cameraConfig, MessageBus.NowSettingLoadMainThread.shuLiConfig,ParaValue);
  397. if (formulationConfigClass == null)
  398. {
  399. MessageBox.Show("获取参数失败,请检查与PLC的连接");
  400. return;
  401. }
  402. formulationConfigClass.FormulationName = ShowMessageBus.ShowBinding.FormulationName;
  403. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Formulations";
  404. string FilePath = folderPath + "\\" + ShowMessageBus.ShowBinding.FormulationName + ".xml";
  405. if (File.Exists(FilePath))
  406. {
  407. var confirmResult = MessageBox.Show("配方已存在,是否覆盖?",
  408. "保存确认", MessageBoxButton.YesNo);
  409. if (confirmResult == MessageBoxResult.No)
  410. {
  411. return;
  412. }
  413. }
  414. if (!Directory.Exists(folderPath)) Directory.CreateDirectory(folderPath);
  415. {
  416. XmlStorage.SerializeToXml(formulationConfigClass, FilePath);
  417. InitFormationItems();
  418. MessageBus.NowSettingLoadMainThread.FormulationName = formulationConfigClass.FormulationName;
  419. MessageBus.NowSettingLoadMainThread.IsLoadFormulation = true;
  420. MessageBox.Show("保存成功");
  421. }
  422. }
  423. private void ReadFormulationBtn_Click(object sender, RoutedEventArgs e)
  424. {
  425. string folderPath = $"{AppDomain.CurrentDomain.BaseDirectory}Formulations\\{FormulationCoBox.SelectedItem}.xml";
  426. if (!File.Exists(folderPath))
  427. {
  428. MessageBox.Show("指定文件不存在,请选择一个正确的配方");
  429. return;
  430. }
  431. try
  432. {
  433. FormulationConfigClass formulationConfigClass = null;
  434. formulationConfigClass = XmlStorage.DeserializeFromXml<FormulationConfigClass>(folderPath);
  435. LoadFormulation(formulationConfigClass);
  436. MessageBus.NowSettingLoadMainThread.FormulationName = formulationConfigClass.FormulationName;
  437. MessageBus.NowSettingLoadMainThread.IsLoadFormulation = true;
  438. MessageBox.Show("加载成功");
  439. }
  440. catch (Exception ex)
  441. {
  442. MessageBox.Show($"读取文件时出错:{ex.Message}");
  443. }
  444. }
  445. /// <summary>
  446. /// 加载配方
  447. /// </summary>
  448. /// <param name="FormulationConfig"></param>
  449. private void LoadFormulation(FormulationConfigClass FormulationConfig)
  450. {
  451. ShowMessageBus.ShowBinding.AcquistionLineRate = FormulationConfig.AcquistionLineRateValue.ToString();
  452. ShowMessageBus.ShowBinding.ExposureTimeValue = FormulationConfig.ExposureTimeValue.ToString();
  453. ShowMessageBus.ShowBinding.Channel = FormulationConfig.Channel.ToString();
  454. ShowMessageBus.ShowBinding.FormulationName = FormulationConfig.FormulationName;
  455. ShowMessageBus.ShowBinding.MAX_OBJECT_LENGTH = FormulationConfig.MAX_Object_LENGTH.ToString();
  456. ShowMessageBus.ShowBinding.MIN_OBJECT_LENGTH = FormulationConfig.MIN_Object_LENGTH.ToString();
  457. ShowMessageBus.ShowBinding.PandingCode = FormulationConfig.PandingCode.ToString();
  458. ShowMessageBus.ShowBinding.RegionThreshold = FormulationConfig.RegionThreshold.ToString();
  459. PlcSettingMessageBus.PlcMessageShowBindage.SpeedModeRunningSpeed =
  460. FormulationConfig.SpeedModeRunningSpeed.ToString();
  461. PlcSettingMessageBus.PlcMessageShowBindage.JogSpeed =
  462. FormulationConfig.JogSpeed.ToString();
  463. PlcSettingMessageBus.PlcMessageShowBindage.BottValueSet =
  464. FormulationConfig.BottValueSet;
  465. PlcSettingMessageBus.PlcMessageShowBindage.TransferValveOpeningSpeed =
  466. FormulationConfig.TransferValveOpeningSpeed.ToString();
  467. PlcSettingMessageBus.PlcMessageShowBindage.TransferValveOpeningTime =
  468. FormulationConfig.TransferValveOpeningTime;
  469. PlcSettingMessageBus.PlcMessageShowBindage.BottingDecelerationValue =
  470. FormulationConfig.BottingDecelerationValue;
  471. PlcSettingMessageBus.PlcMessageShowBindage.CacheDecelerationValue =
  472. FormulationConfig.CacheDecelerationValue;
  473. PlcSettingMessageBus.PlcMessageShowBindage.CacheCountDelayTiming =
  474. FormulationConfig.CacheCountDelayTiming;
  475. PlcSettingMessageBus.PlcMessageShowBindage.CacheShutdownValue =
  476. FormulationConfig.CacheShutdownValue;
  477. PlcSettingMessageBus.PlcMessageShowBindage.BottingMaterialCylinderVibrationTableHighSpeedValue =
  478. FormulationConfig.BottingMaterialCylinderVibrationTableHighSpeedValue;
  479. PlcSettingMessageBus.PlcMessageShowBindage.BottingFilterVibrationTableHighSpeedValue =
  480. FormulationConfig.BottingFilterVibrationTableHighSpeedValue;
  481. PlcSettingMessageBus.PlcMessageShowBindage.BottingCountVibrationTableHighSpeedValue =
  482. FormulationConfig.BottingCountVibrationTableHighSpeedValue;
  483. PlcSettingMessageBus.PlcMessageShowBindage.BottingMaterialCylinderVibrationTableDecelerationSpeedValue =
  484. FormulationConfig.BottingMaterialCylinderVibrationTableDecelerationSpeedValue;
  485. PlcSettingMessageBus.PlcMessageShowBindage.BottingFilterVibrationTableDecelerationSpeedValue =
  486. FormulationConfig.BottingFilterVibrationTableDecelerationSpeedValue;
  487. PlcSettingMessageBus.PlcMessageShowBindage.BottingCountVibrationTableDecelerationSpeedValue =
  488. FormulationConfig.BottingCountVibrationTableDecelerationSpeedValue;
  489. PlcSettingMessageBus.PlcMessageShowBindage.CacheMaterialCylinderVibrationTableHighSpeedValue =
  490. FormulationConfig.CacheMaterialCylinderVibrationTableHighSpeedValue;
  491. PlcSettingMessageBus.PlcMessageShowBindage.CacheFilterVibrationTableHighSpeedValue =
  492. FormulationConfig.CacheFilterVibrationTableHighSpeedValue;
  493. PlcSettingMessageBus.PlcMessageShowBindage.CacheCountVibrationTableHighSpeedValue =
  494. FormulationConfig.CacheCountVibrationTableHighSpeedValue;
  495. PlcSettingMessageBus.PlcMessageShowBindage.CacheMaterialCylinderVibrationTableDecelerationSpeedValue =
  496. FormulationConfig.CacheMaterialCylinderVibrationTableDecelerationSpeedValue;
  497. PlcSettingMessageBus.PlcMessageShowBindage.CacheMaterialCylinderVibrationTableHighSpeedValue =
  498. FormulationConfig.CacheMaterialCylinderVibrationTableHighSpeedValue;
  499. PlcSettingMessageBus.PlcMessageShowBindage.CacheCountVibrationTableDecelerationSpeedValue =
  500. FormulationConfig.CacheCountVibrationTableDecelerationSpeedValue;
  501. PlcSettingMessageBus.PlcMessageShowBindage.GateOpeningDelay =
  502. FormulationConfig.GateOpeningDelay;
  503. PlcSettingMessageBus.PlcMessageShowBindage.ReturnToZeroOffsetValue =
  504. FormulationConfig.ReturnToZeroOffsetValue.ToString();
  505. PlcSettingMessageBus.PlcMessageShowBindage.ReturnToZeroOffsetSpeed =
  506. FormulationConfig.ReturnToZeroOffsetSpeed.ToString();
  507. PlcSettingMessageBus.PlcMessageShowBindage.TransferValveClosingSpeed =
  508. FormulationConfig.TransferValveClosingSpeed.ToString();
  509. PlcSettingMessageBus.PlcMessageShowBindage.TransferValveOpenPosition =
  510. FormulationConfig.TransferValveOpenPosition.ToString();
  511. PlcSettingMessageBus.PlcMessageShowBindage.TransferValveClosePosition =
  512. FormulationConfig.TransferValveClosePosition.ToString();
  513. PlcSettingMessageBus.PlcMessageShowBindage.AirValveOpeningDelay =
  514. FormulationConfig.AirValveOpeningDelay;
  515. PlcSettingMessageBus.PlcMessageShowBindage.BottlingShutdownValue =
  516. FormulationConfig.BottlingShutdownValue;
  517. PlcSettingMessageBus.PlcMessageShowBindage.BottlingShutdownTime =
  518. FormulationConfig.BottlingShutdownTime;
  519. PlcSettingMessageBus.PlcMessageShowBindage.BottleFeedingWheelRunningSpeed =
  520. FormulationConfig.BottleFeedingWheelRunningSpeed.ToString();
  521. PlcSettingMessageBus.PlcMessageShowBindage.BottleFeedingWheelJogRunningSpeed =
  522. FormulationConfig.BottleFeedingWheelJogRunningSpeed.ToString();
  523. PlcSettingMessageBus.PlcMessageShowBindage.BottleFeedingWheelReturnToZeroOffsetValue =
  524. FormulationConfig.BottleFeedingWheelReturnToZeroOffsetValue.ToString();
  525. PlcSettingMessageBus.PlcMessageShowBindage.BottleFeedingWheelReturnToZeroSpeed =
  526. FormulationConfig.BottleFeedingWheelReturnToZeroSpeed.ToString();
  527. PlcSettingMessageBus.PlcMessageShowBindage.BottleFeedingWheelPositionLength =
  528. FormulationConfig.BottleFeedingWheelPositionLength.ToString();
  529. PlcSettingMessageBus.PlcMessageShowBindage.BottleFeedingWheelPauseTime =
  530. FormulationConfig.BottleFeedingWheelPauseTime;
  531. PlcSettingMessageBus.PlcMessageShowBindage.DelayBlanking =
  532. FormulationConfig.DelayBlanking;
  533. }
  534. }
  535. }