HardwareController.cs 4.5 KB

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