SemController.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 SemController
  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. public SemController()
  20. {
  21. }
  22. public bool Connect()
  23. {
  24. IpcClientChannel channel = new IpcClientChannel();
  25. //Register the channel with ChannelServices.
  26. ChannelServices.RegisterChannel(channel, false);
  27. remoteObj = (IpcSEMController)Activator.GetObject(typeof(IpcSEMController), "ipc://ServerChannel/RemoteObject");
  28. if (remoteObj == null)
  29. {
  30. return false;
  31. }
  32. return true;
  33. }
  34. public bool DisConnect()
  35. {
  36. remoteObj = null;
  37. return true;
  38. }
  39. public bool MoveSEMToPoint(Point poi, double rotation)
  40. {
  41. //Connect();
  42. if (remoteObj == null)
  43. {
  44. return false;
  45. }
  46. return remoteObj.MoveSEMToPoint(poi , rotation);
  47. }
  48. public bool GetSemPositionXY(ref double ls_PositionX, ref double ls_PositionY, ref double ls_PositionR)
  49. {
  50. //Connect();
  51. if (remoteObj == null)
  52. {
  53. return false;
  54. }
  55. return remoteObj.GetSemPositionXY(ref ls_PositionX,ref ls_PositionY, ref ls_PositionR);
  56. }
  57. }
  58. }