HardwareController.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. //[DllImport("user32.dll", EntryPoint = "SendMessage")]
  17. //private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  18. private IpcSEMController remoteObj;
  19. private bool ifConnect = false;
  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. if (!ifConnect)
  35. {
  36. IpcClientChannel channel = new IpcClientChannel();
  37. //Register the channel with ChannelServices.
  38. ChannelServices.RegisterChannel(channel, false);
  39. remoteObj = (IpcSEMController)Activator.GetObject(typeof(IpcSEMController), "ipc://ServerChannel/RemoteObject");
  40. if (remoteObj == null)
  41. {
  42. return false;
  43. }
  44. ifConnect = true;
  45. }
  46. return true;
  47. }
  48. public bool DisConnect()
  49. {
  50. //remoteObj = null;
  51. return true;
  52. }
  53. public bool MoveSEMToPoint(Point poi, double rotation)
  54. {
  55. //Connect();
  56. if (remoteObj == null)
  57. {
  58. return false;
  59. }
  60. return remoteObj.MoveSEMToPoint(poi , rotation);
  61. }
  62. public bool GetSemPositionXY(ref double ls_PositionX, ref double ls_PositionY, ref double ls_PositionR)
  63. {
  64. //Connect();
  65. if (remoteObj == null)
  66. {
  67. return false;
  68. }
  69. return remoteObj.GetSemPositionXY(ref ls_PositionX,ref ls_PositionY, ref ls_PositionR);
  70. }
  71. }
  72. }