HardwareController.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. namespace ServiceInterface
  13. {
  14. public class HardwareController
  15. {
  16. private IpcSEMController remoteObj;
  17. private bool ifConnect = false;
  18. static HardwareController sem = null;
  19. public static HardwareController GetSemController()
  20. {
  21. if (sem == null)
  22. {
  23. sem = new HardwareController();
  24. }
  25. return sem;
  26. }
  27. private HardwareController()
  28. {
  29. }
  30. public bool Connect()
  31. {
  32. if (!ifConnect)
  33. {
  34. IpcClientChannel channel = new IpcClientChannel();
  35. //Register the channel with ChannelServices.
  36. ChannelServices.RegisterChannel(channel, false);
  37. remoteObj = (IpcSEMController)Activator.GetObject(typeof(IpcSEMController), "ipc://ServerChannel/RemoteObject");
  38. if (remoteObj == null)
  39. {
  40. return false;
  41. }
  42. ifConnect = true;
  43. }
  44. return true;
  45. }
  46. public bool DisConnect()
  47. {
  48. //remoteObj = null;
  49. return true;
  50. }
  51. public bool MoveSEMToPoint(Point poi, double rotation)
  52. {
  53. //Connect();
  54. if (remoteObj == null)
  55. {
  56. return false;
  57. }
  58. try
  59. {
  60. return remoteObj.MoveSEMToPoint(poi);
  61. }
  62. catch (Exception e)
  63. {
  64. NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  65. }
  66. return false;
  67. }
  68. public bool GetSemPositionXY(ref double ls_PositionX, ref double ls_PositionY, ref double ls_PositionR)
  69. {
  70. //Connect();
  71. if (remoteObj == null)
  72. {
  73. return false;
  74. }
  75. try
  76. {
  77. return remoteObj.GetSemPositionXY(ref ls_PositionX, ref ls_PositionY, ref ls_PositionR);
  78. }
  79. catch (Exception e)
  80. {
  81. NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
  82. }
  83. return false;
  84. }
  85. }
  86. }