ULpControl.xaml.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using SecsGem.Core;
  2. using SecsGem.Core.ItemModel;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace EapClientSimulator
  18. {
  19. /// <summary>
  20. /// ULpControl.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class ULpControl : UserControl
  23. {
  24. private string sequence= System.Configuration.ConfigurationManager.AppSettings.Get("defaultSequence");
  25. public event EventHandler<string> OnSendMessage;
  26. public ULpControl()
  27. {
  28. InitializeComponent();
  29. }
  30. string portId = "";
  31. string jobId = "";
  32. string lotId = "";
  33. private void btnLoadId_Click(object sender, RoutedEventArgs e)
  34. {
  35. PortCommand("Load");
  36. }
  37. private void btnReadId_Click(object sender, RoutedEventArgs e)
  38. {
  39. PortCommand("ReadID");
  40. }
  41. FrmSequence frmSequence = null;
  42. private void btnPPSelect_Click(object sender, RoutedEventArgs e)
  43. {
  44. frmSequence = new FrmSequence(portId, jobId, lotId,sequence);
  45. frmSequence.OnUpdateSequence += FrmSequence_OnUpdateSequence;
  46. frmSequence.OnSendMessage += FrmSequence_OnSendMessage;
  47. frmSequence.ShowDialog();
  48. }
  49. private void FrmSequence_OnUpdateSequence(object sender, string e)
  50. {
  51. sequence = e;
  52. }
  53. private void FrmSequence_OnSendMessage(object sender, string e)
  54. {
  55. if(OnSendMessage!=null)
  56. {
  57. OnSendMessage(sender, e);
  58. }
  59. }
  60. private void btnStart_Click(object sender, RoutedEventArgs e)
  61. {
  62. JobCommand("StartJob");
  63. }
  64. private void btnStop_Click(object sender, RoutedEventArgs e)
  65. {
  66. JobCommand("StopJob");
  67. }
  68. private void btnAbort_Click(object sender, RoutedEventArgs e)
  69. {
  70. JobCommand("AbortJob");
  71. }
  72. private void btnResume_Click(object sender, RoutedEventArgs e)
  73. {
  74. JobCommand("ResumeJob");
  75. }
  76. private void btnPause_Click(object sender, RoutedEventArgs e)
  77. {
  78. JobCommand("PauseJob");
  79. }
  80. private void JobCommand(string command)
  81. {
  82. RemoteCommand remoteCommand = new RemoteCommand();
  83. remoteCommand.Command = command;
  84. RemoteParameter remoteParameter = new RemoteParameter();
  85. remoteParameter.Name = "JobID";
  86. remoteParameter.Value = new StringItem(SecsGem.Core.DataFormat.Ascii, jobId);
  87. remoteCommand.RemoteParameters.Add(remoteParameter);
  88. SecsGem.Core.SecsMessage secsMessage = SecsMessageSendUtil.CreateS2F49Message(remoteCommand);
  89. if (GlobalData.Client != null)
  90. {
  91. GlobalData.Client.SendMessage(secsMessage);
  92. }
  93. if (OnSendMessage != null)
  94. {
  95. OnSendMessage(this, SmlSerializationUtil.SerializeItemToString(secsMessage));
  96. }
  97. }
  98. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  99. {
  100. portId = this.Name.Substring(this.Name.Length - 1);
  101. jobId = "Job_" + portId;
  102. lotId = "C00" + portId;
  103. }
  104. private void btnUnload_Click(object sender, RoutedEventArgs e)
  105. {
  106. PortCommand("UnLoad");
  107. }
  108. private void PortCommand(string command)
  109. {
  110. RemoteCommand remoteCommand = new RemoteCommand();
  111. remoteCommand.Command = command;
  112. RemoteParameter remoteParameter = new RemoteParameter();
  113. remoteParameter.Name = "PortID";
  114. remoteParameter.Value = new StringItem(SecsGem.Core.DataFormat.Ascii, portId);
  115. remoteCommand.RemoteParameters.Add(remoteParameter);
  116. SecsGem.Core.SecsMessage secsMessage = SecsMessageSendUtil.CreateS2F49Message(remoteCommand);
  117. if (GlobalData.Client != null)
  118. {
  119. GlobalData.Client.SendMessage(secsMessage);
  120. }
  121. if (OnSendMessage != null)
  122. {
  123. OnSendMessage(this, SmlSerializationUtil.SerializeItemToString(secsMessage));
  124. }
  125. }
  126. private void btnMapCassette_Click(object sender, RoutedEventArgs e)
  127. {
  128. PortCommand("MapCassette");
  129. }
  130. }
  131. }