using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.InteropServices; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Ipc; using OTSMeasureApp.ServiceCenter; namespace ServiceInterface { public class HardwareController { private IpcSEMController remoteObj; private bool ifConnect = false; static HardwareController sem = null; public static HardwareController GetSemController() { if (sem == null) { sem = new HardwareController(); } return sem; } private HardwareController() { } public bool Connect() { if (!ifConnect) { IpcClientChannel channel = new IpcClientChannel(); //Register the channel with ChannelServices. ChannelServices.RegisterChannel(channel, false); remoteObj = (IpcSEMController)Activator.GetObject(typeof(IpcSEMController), "ipc://ServerChannel/RemoteObject"); if (remoteObj == null) { return false; } ifConnect = true; } return true; } public bool DisConnect() { //remoteObj = null; return true; } public bool MoveSEMToPoint(Point poi, double rotation) { //Connect(); if (remoteObj == null) { return false; } try { return remoteObj.MoveSEMToPoint(poi); } catch (Exception e) { NLog.LogManager.GetCurrentClassLogger().Error(e.Message); } return false; } public bool GetSemPositionXY(ref double ls_PositionX, ref double ls_PositionY, ref double ls_PositionR) { //Connect(); if (remoteObj == null) { return false; } try { return remoteObj.GetSemPositionXY(ref ls_PositionX, ref ls_PositionY, ref ls_PositionR); } catch (Exception e) { NLog.LogManager.GetCurrentClassLogger().Error(e.Message); } return false; } } }