HardwareController.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Runtime.InteropServices;
  9. using System.Runtime.Remoting.Channels;
  10. using System.Runtime.Remoting.Channels.Ipc;
  11. using OTSMeasureApp.ServiceCenter;
  12. using OTSCommon.Model;
  13. using OTSCLRINTERFACE;
  14. using OTSDataType;
  15. namespace ServiceInterface
  16. {
  17. public class HardwareController
  18. {
  19. private IpcSEMController remoteObj;
  20. private bool ifConnect = false;
  21. static HardwareController sem = null;
  22. public static HardwareController GetSemController()
  23. {
  24. if (sem == null)
  25. {
  26. sem = new HardwareController();
  27. }
  28. return sem;
  29. }
  30. private HardwareController()
  31. {
  32. }
  33. public bool Connect()
  34. {
  35. if (!ifConnect)
  36. {
  37. IpcClientChannel channel = new IpcClientChannel();
  38. //Register the channel with ChannelServices.
  39. ChannelServices.RegisterChannel(channel, false);
  40. remoteObj = (IpcSEMController)Activator.GetObject(typeof(IpcSEMController), "ipc://ServerChannel/RemoteObject");
  41. if (remoteObj == null)
  42. {
  43. return false;
  44. }
  45. ifConnect = true;
  46. }
  47. return true;
  48. }
  49. public bool DisConnect()
  50. {
  51. //remoteObj = null;
  52. ifConnect = false;
  53. return true;
  54. }
  55. public bool SetMagnification(double a_dMagnification)
  56. {
  57. //Connect();
  58. if (remoteObj == null)
  59. {
  60. return false;
  61. }
  62. try
  63. {
  64. return remoteObj.SetMagnification(a_dMagnification);
  65. }
  66. catch (Exception e)
  67. {
  68. NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  69. }
  70. return false;
  71. }
  72. public bool AcquireBSEImage(int width, int height, int dwellTime, ref byte[] ImageByte)
  73. {
  74. //Connect();
  75. if (remoteObj == null)
  76. {
  77. return false;
  78. }
  79. try
  80. {
  81. return remoteObj.AcquireBSEImage(width, height, dwellTime, ref ImageByte);
  82. }
  83. catch (Exception e)
  84. {
  85. NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  86. }
  87. return false;
  88. }
  89. public bool MoveSEMToPoint(Point poi, double rotation)
  90. {
  91. //Connect();
  92. if (remoteObj == null)
  93. {
  94. return false;
  95. }
  96. try
  97. {
  98. return remoteObj.MoveSEMToPoint(poi);
  99. }
  100. catch (Exception e)
  101. {
  102. NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  103. }
  104. return false;
  105. }
  106. public bool GetSemPositionXY(ref double ls_PositionX, ref double ls_PositionY, ref double ls_PositionR)
  107. {
  108. //Connect();
  109. if (remoteObj == null)
  110. {
  111. return false;
  112. }
  113. try
  114. {
  115. return remoteObj.GetSemPositionXY(ref ls_PositionX, ref ls_PositionY, ref ls_PositionR);
  116. }
  117. catch (Exception e)
  118. {
  119. NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  120. }
  121. return false;
  122. }
  123. public bool ReMeasure(string samplePath, int width, int height, Dictionary<int, List<Particle>> keyValues, int IMGSCANSPEED_INDEX, int XRAYSCANMODE_INDEX, int NUD_SCANTIME_COUNT)
  124. {
  125. //Connect();
  126. if (remoteObj == null)
  127. {
  128. return false;
  129. }
  130. try
  131. {
  132. return remoteObj.ReMeasure(samplePath, width, height, keyValues, IMGSCANSPEED_INDEX, XRAYSCANMODE_INDEX, NUD_SCANTIME_COUNT);
  133. }
  134. catch (Exception e)
  135. {
  136. NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  137. }
  138. return false;
  139. }
  140. }
  141. }