版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

167 строки
5.6 KiB

  1. using MaiMuAOI.SysCtrl;
  2. using MaiMuControl.Device.AxisDev;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. using System.Xml.Linq;
  16. namespace ProductionControl.UI
  17. {
  18. public partial class UISmallAxisDev : UserControl
  19. {
  20. SynchronizationContext SyncContext = null;
  21. public Action<string> GetParamsEvent;
  22. //
  23. private SmallAxisDevProp prop = new SmallAxisDevProp(ConfMgr.Instance.SysConfigParams.LensMotorCom);
  24. private AxisDev _dev;
  25. public UISmallAxisDev(AxisDev axisDev)
  26. {
  27. InitializeComponent();
  28. _dev = axisDev;
  29. propertyGrid1.PropertyValueChanged += propertyGrid1_PropertyValueChanged;
  30. refreshUIState();
  31. //获取UI线程同步上下文
  32. SyncContext = SynchronizationContext.Current;
  33. //init();
  34. }
  35. public string getParamsData()
  36. {
  37. return prop.serialize();
  38. }
  39. public void setParamsData(string json)
  40. {
  41. if (json == "") return;
  42. prop.deserialize(json);
  43. this.propertyGrid1.Refresh();
  44. }
  45. private void refreshUIState()
  46. {
  47. foreach (ToolStripItem item in this.toolStrip1.Items)
  48. {
  49. if (item.Text == "打开设备")
  50. item.Visible = (_dev == null);
  51. else
  52. this.propertyGrid1.Enabled = item.Enabled = !(_dev == null);
  53. }
  54. }
  55. public void init()
  56. {
  57. this.tbtnSave.Visible = tssSave.Visible = (GetParamsEvent != null);
  58. this.propertyGrid1.SelectedObject = prop;
  59. //prop.MaxPPU = dev.getMaxPPU();
  60. refreshUIState();
  61. }
  62. private void refreshUI()
  63. {
  64. SyncContext.Post(m =>
  65. {
  66. var result = m as string;
  67. propertyGrid1.Refresh();
  68. //tbtnJogOnOff.Text = (prop.AxState == AxisState.STA_AX_EXT_JOG) ? "关闭Jog" : "开启Jog";
  69. //tbtnLeft.Enabled = tbtnRight.Enabled = (prop.AxState == AxisState.STA_AX_EXT_JOG);
  70. }, "异步操作完成结果");
  71. }
  72. protected override void OnHandleDestroyed(EventArgs e)
  73. {
  74. base.OnHandleDestroyed(e);
  75. // 在此添加需要手动释放资源的代码
  76. }
  77. private void tbtnRun_Click(object sender, EventArgs e)
  78. {
  79. try
  80. {
  81. _dev.MoveAbsPulse(0, new VelocityCurveParams(),(int)prop.CmdPos);
  82. _dev.CheckDone(0, 10000);
  83. //if (!res)
  84. // throw new Exception("设置失败!");
  85. }
  86. catch(Exception ex)
  87. {
  88. MessageBox.Show(ex.Message, "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
  89. }
  90. }
  91. private void tbtnHome_Click(object sender, EventArgs e)
  92. {
  93. _dev.BackHome(0, new HomeVelocityParams());
  94. _dev.CheckHomeDone(0, 10000);
  95. }
  96. private void tbtnExport_Click(object sender, EventArgs e)
  97. {
  98. string filePath = ConfMgr.SaveAsFile($"SamllAxis config.json", "JSON|*.json");
  99. if (filePath != "")
  100. {
  101. string jsonText = prop.serialize();
  102. File.WriteAllText(filePath, jsonText);
  103. MessageBox.Show("保存成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
  104. }
  105. }
  106. private void tbtnImport_Click(object sender, EventArgs e)
  107. {
  108. string filePath = ConfMgr.SelectFile("JSON|*.json");
  109. if (filePath != "")
  110. {
  111. string jsonText = File.ReadAllText(filePath);
  112. prop.deserialize(jsonText);
  113. this.propertyGrid1.Refresh();
  114. //this.propertyGrid1.SelectedObject= prop;
  115. //MessageBox.Show("加载成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
  116. }
  117. }
  118. private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
  119. {
  120. //其中包含了两个重要的属性:OldValue和ChangeItem。
  121. //ChangeItem是“PropertyDescriptorGridEntry”类型。一般可以通过ChangeItem.PropertyDescriptor.ComponentType查找到属性的实际类型。
  122. //而通过ChangeItem的Label,则可以查看到当前在属性编辑输入框中显示的值。
  123. string className = e.ChangedItem.PropertyDescriptor.ComponentType.Name;
  124. string propertyName = e.ChangedItem.PropertyDescriptor.Name;
  125. var oldValue = e.OldValue;
  126. var newValue = e.ChangedItem.Value;
  127. switch (propertyName)
  128. {
  129. //case "ChannelIndex":
  130. // if((int)newValue <1 || (int)newValue >4)
  131. // {
  132. // prop.ChannelIndex = (int)oldValue;
  133. // this.refreshUI();
  134. // }
  135. // else
  136. // {
  137. // dev.getDigitalValue((int)newValue);
  138. // }
  139. // break;
  140. }
  141. }
  142. private void tbtnSave_Click(object sender, EventArgs e)
  143. {
  144. GetParamsEvent?.Invoke(prop.serialize());
  145. }
  146. private void tsbtnOpenDev_Click(object sender, EventArgs e)
  147. {
  148. this.init();
  149. }
  150. }
  151. }