HardwareController.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. static HardwareController sem = null;
  21. public static HardwareController GetSemController()
  22. {
  23. if (sem == null)
  24. {
  25. sem = new HardwareController();
  26. }
  27. return sem;
  28. }
  29. private HardwareController()
  30. {
  31. }
  32. public bool Connect()
  33. {
  34. try
  35. {
  36. if (remoteObj == null)
  37. {
  38. IpcClientChannel channel = new IpcClientChannel();
  39. //Register the channel with ChannelServices.
  40. ChannelServices.RegisterChannel(channel, false);
  41. remoteObj = (IpcSEMController)Activator.GetObject(typeof(IpcSEMController), "ipc://ServerChannel/RemoteObject");
  42. if (!remoteObj.TestConn())
  43. {
  44. remoteObj = null;
  45. return false;
  46. }
  47. }
  48. }
  49. catch (Exception e)
  50. {
  51. NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  52. remoteObj = null;
  53. return false;
  54. }
  55. return true;
  56. }
  57. public bool DisConnect()
  58. {
  59. //remoteObj = null;
  60. return true;
  61. }
  62. public bool SetMagnification(double a_dMagnification)
  63. {
  64. //Connect();
  65. if (remoteObj == null)
  66. {
  67. return false;
  68. }
  69. try
  70. {
  71. return remoteObj.SetMagnification(a_dMagnification);
  72. }
  73. catch (Exception e)
  74. {
  75. NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  76. }
  77. return false;
  78. }
  79. public bool AcquireBSEImage(string sampleName, int width, int height, int dwellTime, ref byte[] ImageByte)
  80. {
  81. //Connect();
  82. if (remoteObj == null)
  83. {
  84. return false;
  85. }
  86. try
  87. {
  88. return remoteObj.AcquireBSEImage(sampleName,width,height,dwellTime,ref ImageByte);
  89. }
  90. catch (Exception e)
  91. {
  92. NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  93. }
  94. return false;
  95. }
  96. public bool MoveSEMToPoint(Point poi, double rotation)
  97. {
  98. //Connect();
  99. if (remoteObj == null)
  100. {
  101. return false;
  102. }
  103. try
  104. {
  105. return remoteObj.MoveSEMToPoint(poi);
  106. }
  107. catch (Exception e)
  108. {
  109. NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  110. }
  111. return false;
  112. }
  113. public bool GetSemPositionXY(ref double ls_PositionX, ref double ls_PositionY, ref double ls_PositionR)
  114. {
  115. //Connect();
  116. if (remoteObj == null)
  117. {
  118. return false;
  119. }
  120. try
  121. {
  122. return remoteObj.GetSemPositionXY(ref ls_PositionX, ref ls_PositionY, ref ls_PositionR);
  123. }
  124. catch (Exception e)
  125. {
  126. NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  127. }
  128. return false;
  129. }
  130. public bool AcquisitionSpectrum(string samplePath, int xrayMode, double new_PixelSize, ref Particle particle, uint a_nXRayAQTime)
  131. {
  132. //Connect();
  133. if (remoteObj == null)
  134. {
  135. return false;
  136. }
  137. try
  138. {
  139. return remoteObj.AcquisitionSpectrum(samplePath, xrayMode, new_PixelSize, ref particle, a_nXRayAQTime);
  140. }
  141. catch (Exception e)
  142. {
  143. NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  144. }
  145. return false;
  146. }
  147. }
  148. }