/// <summary> /// 停止监听。 /// </summary> public void Stop() { if (this.opcProject != null) { KEPServerExRelayServiceProxy.Instance.DataChange -= this.KEPServerExRelayServiceProxy_Instance_DataChange; KEPServerExRelayServiceProxy.Instance.Stop(); this.opcProject = null; } this.channelRotationOpcByChannelId.Clear(); }
/// <summary> /// 启动代理。 /// </summary> public void Start(string serverIP, int servicePort, OpcProject project) { this.Stop(); this.serverIP = serverIP; this.servicePort = servicePort; this.project = project; this.ensureClientConnectedThread = new Thread(this.ensureClientConnectedThreadStart); this.ensureClientConnectedThread.Name = string.Format(CultureInfo.InvariantCulture, "{0}.ensureClientConnectedThreadStart", this.GetType().FullName); this.ensureClientConnectedThread.IsBackground = true; this.ensureClientConnectedThread.CurrentCulture = Thread.CurrentThread.CurrentCulture; this.ensureClientConnectedThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture; this.needRestart = true; this.ensureClientConnectedThreadNeedQuit = false; this.ensureClientConnectedThread.Start(); this.IsRunning = true; }
/// <summary> /// 启动监听。 /// </summary> public void Start(string serviceName, string serverIP) { using (GeelyPtlEntities dbContext = new GeelyPtlEntities()) { List <CFG_Channel> cfgChannels = dbContext.CFG_Channels .OrderBy(c => c.Code) .ToList(); foreach (CFG_Channel cfgChannel in cfgChannels) { ChannelRotationOpc channelRotationOpc = new ChannelRotationOpc(cfgChannel.Id); this.channelRotationOpcByChannelId.Add(cfgChannel.Id, channelRotationOpc); } } OpcItem opcItemChannel1RotationStart = new OpcItem { ID = this.opcItemChannel1RotationStartName, DataType = OpcDataType.Boolean }; OpcItem opcItemChannel1ReverseRotationStart = new OpcItem { ID = this.opcItemChannel1ReverseRotationStartName, DataType = OpcDataType.Boolean }; OpcItem opcItemChannel2RotationStart = new OpcItem { ID = this.opcItemChannel2RotationStartName, DataType = OpcDataType.Boolean }; OpcItem opcItemChannel2ReverseRotationStart = new OpcItem { ID = this.opcItemChannel2ReverseRotationStartName, DataType = OpcDataType.Boolean }; OpcItem opcItemChannel3RotationStart = new OpcItem { ID = this.opcItemChannel3RotationStartName, DataType = OpcDataType.Boolean }; OpcItem opcItemChannel3ReverseRotationStart = new OpcItem { ID = this.opcItemChannel3ReverseRotationStartName, DataType = OpcDataType.Boolean }; OpcItem opcItemChannel4RotationStart = new OpcItem { ID = this.opcItemChannel4RotationStartName, DataType = OpcDataType.Boolean }; OpcItem opcItemChannel4ReverseRotationStart = new OpcItem { ID = this.opcItemChannel4ReverseRotationStartName, DataType = OpcDataType.Boolean }; OpcItem opcItemChannel5RotationStart = new OpcItem { ID = this.opcItemChannel5RotationStartName, DataType = OpcDataType.Boolean }; OpcItem opcItemChannel5ReverseRotationStart = new OpcItem { ID = this.opcItemChannel5ReverseRotationStartName, DataType = OpcDataType.Boolean }; OpcItem opcItemChannel6RotationStart = new OpcItem { ID = this.opcItemChannel6RotationStartName, DataType = OpcDataType.Boolean }; OpcItem opcItemChannel6ReverseRotationStart = new OpcItem { ID = this.opcItemChannel6ReverseRotationStartName, DataType = OpcDataType.Boolean }; OpcItem opcItemChannel7RotationStart = new OpcItem { ID = this.opcItemChannel7RotationStartName, DataType = OpcDataType.Boolean }; OpcItem opcItemChannel7ReverseRotationStart = new OpcItem { ID = this.opcItemChannel7ReverseRotationStartName, DataType = OpcDataType.Boolean }; OpcGroup opcGroup = new OpcGroup(); opcGroup.Name = this.opcGroupName; opcGroup.UpdateRate = this.opcUpdateRate; opcGroup.OpcItems.Add(opcItemChannel1RotationStart); opcGroup.OpcItems.Add(opcItemChannel1ReverseRotationStart); opcGroup.OpcItems.Add(opcItemChannel2RotationStart); opcGroup.OpcItems.Add(opcItemChannel2ReverseRotationStart); opcGroup.OpcItems.Add(opcItemChannel3RotationStart); opcGroup.OpcItems.Add(opcItemChannel3ReverseRotationStart); opcGroup.OpcItems.Add(opcItemChannel4RotationStart); opcGroup.OpcItems.Add(opcItemChannel4ReverseRotationStart); opcGroup.OpcItems.Add(opcItemChannel5RotationStart); opcGroup.OpcItems.Add(opcItemChannel5ReverseRotationStart); opcGroup.OpcItems.Add(opcItemChannel6RotationStart); opcGroup.OpcItems.Add(opcItemChannel6ReverseRotationStart); opcGroup.OpcItems.Add(opcItemChannel7RotationStart); opcGroup.OpcItems.Add(opcItemChannel7ReverseRotationStart); this.opcProject = new OpcProject(); this.opcProject.ServerName = serviceName; this.opcProject.OpcGroups.Add(opcGroup); KEPServerExRelayServiceProxy.Instance.Start(serverIP, 9034, this.opcProject); KEPServerExRelayServiceProxy.Instance.DataChange += this.KEPServerExRelayServiceProxy_Instance_DataChange; }