SemController.cs 1.9 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 OTSModelSharp.ServiceInterface;
  11. using System.Runtime.Remoting.Channels.Ipc;
  12. using OTSMeasureApp.ServiceCenter;
  13. namespace ServiceInterface
  14. {
  15. public class SemController
  16. {
  17. //[DllImport("user32.dll", EntryPoint = "SendMessage")]
  18. //private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  19. private IpcSEMController remoteObj;
  20. public SemController()
  21. {
  22. IpcClientChannel channel = new IpcClientChannel();
  23. //Register the channel with ChannelServices.
  24. ChannelServices.RegisterChannel(channel, false);
  25. }
  26. public bool Connect()
  27. {
  28. remoteObj = (IpcSEMController)Activator.GetObject(typeof(IpcSEMController), "ipc://ServerChannel/RemoteObject");
  29. if (remoteObj == null)
  30. {
  31. return false;
  32. }
  33. return true;
  34. }
  35. public bool DisConnect()
  36. {
  37. remoteObj = null;
  38. return true;
  39. }
  40. public bool MoveSEMToPoint(Point poi, double rotation)
  41. {
  42. //Connect();
  43. if (remoteObj == null)
  44. {
  45. return false;
  46. }
  47. return remoteObj.MoveSEMToPoint(poi , rotation);
  48. }
  49. public bool GetSemPositionXY(ref double ls_PositionX, ref double ls_PositionY, ref double ls_PositionR)
  50. {
  51. //Connect();
  52. if (remoteObj == null)
  53. {
  54. return false;
  55. }
  56. return remoteObj.GetSemPositionXY(ref ls_PositionX,ref ls_PositionY, ref ls_PositionR);
  57. }
  58. }
  59. }