Exemple #1
0
		static void Run()
		{
			OPCDAServer = new OPCDAServer();
			OPCDAServer.Events.ServerReleased += new ServerReleasedEventHandler(Events_ServerReleased);
			OPCDAServer.Events.ReadItems += new ReadItemsEventHandler(Events_ReadItems);
			OPCDAServer.Events.WriteItems += new WriteItemsEventHandler(Events_WriteItems);
			OPCDAServer.Events.ActivateItems += new ActivateItemsEventHandler(Events_ActivateItems);
			OPCDAServer.Events.DeactivateItems += new DeactivateItemsEventHandler(Events_DeactivateItems);

			OPCDAServer.Initialize(srvGuid, 50, 50, ServerOptions.NoAccessPaths, '/', 100);

			foreach (var device in GKManager.Devices.Where(x => GKManager.DeviceConfiguration.OPCSettings.DeviceUIDs.Contains(x.UID)).ToList())
			{
				if (TagsCount >= 100)
					break;
				var tagName = new StringBuilder();
				foreach (var parentDevice in device.AllParents)
				{
					if (parentDevice.Driver.DriverType != GKDriverType.System)
					{
						if (parentDevice.Driver.HasAddress)
							tagName.Append(parentDevice.ShortName + " - " + parentDevice.PresentationAddress + "/");
						else
							tagName.Append(parentDevice.ShortName + "/");
					}
				}
				if (device.Driver.HasAddress)
					tagName.Append(device.ShortName + " - " + device.PresentationAddress + "/");
				else
					tagName.Append(device.ShortName + "/");

				var name = tagName.ToString();
				var tagId = OPCDAServer.CreateTag(
					TagsCount,
					name,
					//AccessRights.readable,
					AccessRights.readWritable,
					(double)0);

				var tagDevice = new TagBase(tagId, device.State, device.UID);
				TagDevices.Add(tagDevice);
				TagsCount++;
			}

			foreach (var zone in GKManager.Zones.Where(x => GKManager.DeviceConfiguration.OPCSettings.ZoneUIDs.Contains(x.UID)).ToList())
			{
				if (TagsCount >= 100)
					break;

				var tagId = OPCDAServer.CreateTag(
					TagsCount,
					"Zones/" + zone.PresentationName,
					//AccessRights.readable,
					AccessRights.readWritable,
					(double)0);

				var tagZone = new TagBase(tagId, zone.State, zone.UID);
				TagZones.Add(tagZone);
				TagsCount++;
			}

			foreach (var direction in GKManager.Directions.Where(x=> GKManager.DeviceConfiguration.OPCSettings.DiretionUIDs.Contains(x.UID)).ToList())
			{
				if (TagsCount >= 100)
					break;

				var tagId = OPCDAServer.CreateTag(
					TagsCount,
					"Directions/" + direction.PresentationName,
					//AccessRights.readable,
					AccessRights.readWritable,
					(double)0);

				var tagDirection = new TagBase(tagId, direction.State, direction.UID);
				TagDirections.Add(tagDirection);
				TagsCount++;
			}

			foreach (var zone in GKManager.GuardZones.Where(x => GKManager.DeviceConfiguration.OPCSettings.GuardZoneUIDs.Contains(x.UID)).ToList())
			{
				if (TagsCount >= 100)
					break;

				var tagId = OPCDAServer.CreateTag(
					TagsCount,
					"GuardZones/" + zone.PresentationName,
					//AccessRights.readable,
					AccessRights.readWritable,
					(double)0);

				var tagGuardZone = new TagBase(tagId, zone.State, zone.UID);
				TagGuardZones.Add(tagGuardZone);
				TagsCount++;
			}

			foreach (var delay in GKManager.Delays.Where(x => GKManager.DeviceConfiguration.OPCSettings.DelayUIDs.Contains(x.UID)).ToList())
			{
				if (TagsCount >= 100)
					break;

				var tagId = OPCDAServer.CreateTag(
					TagsCount,
					"Delays/" + delay.PresentationName,
					//AccessRights.readable,
					AccessRights.readWritable,
					(double)0);

				var tagdelay = new TagBase(tagId, delay.State, delay.UID);
				TagDelays.Add(tagdelay);
				TagsCount++;
			}

			foreach (var mpt in GKManager.MPTs.Where(x => GKManager.DeviceConfiguration.OPCSettings.MPTUIDs.Contains(x.UID)).ToList())
			{
				if (TagsCount >= 100)
					break;

				var tagId = OPCDAServer.CreateTag(
					TagsCount,
					"MPTs/" + mpt.PresentationName,
					//AccessRights.readable,
					AccessRights.readWritable,
					(double)0);

				var tagmpt = new TagBase(tagId, mpt.State, mpt.UID);
				TagMPTs.Add(tagmpt);
				TagsCount++;
			}

			foreach (var pump in GKManager.PumpStations.Where(x => GKManager.DeviceConfiguration.OPCSettings.NSUIDs.Contains(x.UID)).ToList())
			{
				if (TagsCount >= 100)
					break;

				var tagId = OPCDAServer.CreateTag(
					TagsCount,
					"PumpStations/" + pump.PresentationName,
					//AccessRights.readable,
					AccessRights.readWritable,
					(double)0);

				var tagns = new TagBase(tagId, pump.State, pump.UID);
				TagPumpStations.Add(tagns);
				TagsCount++;
			}

			foreach (var door in GKManager.Doors.Where(x => GKManager.DeviceConfiguration.OPCSettings.DoorUIDs.Contains(x.UID)).ToList())
			{
				if (TagsCount >= 100)
					break;

				var tagId = OPCDAServer.CreateTag(
					TagsCount,
					"Doors/" + door.PresentationName,
					//AccessRights.readable,
					AccessRights.readWritable,
					(double)0);

				var tagdoor = new TagBase(tagId, door.State, door.UID);
				TagDoors.Add(tagdoor);
				TagsCount++;
			}

			OPCDAServer.RegisterClassObject();

			OPCDAServer.BeginUpdate();
			foreach (var tagDevice in TagDevices)
			{
				OPCDAServer.SetTag(tagDevice.TagId, tagDevice.State.StateClass);
			}
			foreach (var tagZone in TagZones)
			{
				OPCDAServer.SetTag(tagZone.TagId, tagZone.State.StateClass);
			}
			foreach (var tagDirection in TagDirections)
			{
				OPCDAServer.SetTag(tagDirection.TagId, tagDirection.State.StateClass);
			}
			foreach (var tagGuardZone in TagGuardZones)
			{
				OPCDAServer.SetTag(tagGuardZone.TagId, tagGuardZone.State.StateClass);	
			}
			foreach (var tagDelay in TagDelays)
			{
				OPCDAServer.SetTag(tagDelay.TagId, tagDelay.State.StateClass);
			}
			foreach (var tagMPT in TagMPTs)
			{
				OPCDAServer.SetTag(tagMPT.TagId, tagMPT.State.StateClass);
			}
			foreach (var tagPumps in TagPumpStations)
			{
				OPCDAServer.SetTag(tagPumps.TagId, tagPumps.State.StateClass);
			}
			foreach (var tagDoors in TagDoors)
			{
				OPCDAServer.SetTag(tagDoors.TagId, tagDoors.State.StateClass);
			}
			OPCDAServer.EndUpdate(false);

			while (true)
			{
				if (StopEvent.WaitOne(5000))
					break;
			}
			OPCDAServer.RevokeClassObject();
			OPCDAServer = null;
		}
		static void Run()
		{
			srv = new OPCDAServer();
			srv.Events.ServerReleased += new ServerReleasedEventHandler(Events_ServerReleased);
			srv.Events.ReadItems += new ReadItemsEventHandler(Events_ReadItems);
			srv.Events.WriteItems += new WriteItemsEventHandler(Events_WriteItems);
			srv.Events.ActivateItems += new ActivateItemsEventHandler(Events_ActivateItems);
			srv.Events.DeactivateItems += new DeactivateItemsEventHandler(Events_DeactivateItems);

			srv.Initialize(srvGuid, 50, 50, ServerOptions.NoAccessPaths, '/', 100);

			if (FiresecManager.Devices == null)
				return;

			foreach (var device in FiresecManager.Devices)
			{
				if (TagsCount >= 100)
					break;

				if (!device.IsOPCUsed)
					continue;

				var tagName = new StringBuilder();
				foreach (var parentDevice in device.AllParents)
				{
					if (parentDevice.Driver.HasAddress)
						tagName.Append(parentDevice.Driver.ShortName + " - " + parentDevice.PresentationAddress + "/");
					else
						tagName.Append(parentDevice.Driver.ShortName + "/");
				}
				if (device.Driver.HasAddress)
					tagName.Append(device.Driver.ShortName + " - " + device.PresentationAddress + "/");
				else
					tagName.Append(device.Driver.ShortName + "/");

				var tagId = srv.CreateTag(
					TagsCount,
					tagName.ToString(),
					AccessRights.readable,
					(double)0);

				var tagDevice = new TagDevice()
				{
					TagId = tagId,
					DeviceState = device.DeviceState
				};
				TagDevices.Add(tagDevice);
				TagsCount++;
			}
			foreach (var zone in (from Zone zone in FiresecManager.Zones orderby zone.No select zone))
			{
				if (TagsCount >= 100)
					break;

				if (!zone.IsOPCUsed)
					continue;

				var tagId = srv.CreateTag(
					TagsCount,
					"Zones/" + zone.PresentationName,
					AccessRights.readable,
					(double)0);

				var tagZone = new TagZone()
				{
					TagId = tagId,
					ZoneState = zone.ZoneState
				};
				TagZones.Add(tagZone);
				TagsCount++;
			}

			srv.RegisterClassObject();

			srv.BeginUpdate();
			foreach (var tagDevice in TagDevices)
			{
				srv.SetTag(tagDevice.TagId, tagDevice.DeviceState.StateType);
			}
			foreach (var tagZone in TagZones)
			{
				srv.SetTag(tagZone.TagId, tagZone.ZoneState.StateType);
			}
			srv.EndUpdate(false);

			FiresecManager.FiresecDriver.Watcher.DevicesStateChanged += new Action<List<DeviceState>>(OnDevicesStateChanged);
			FiresecManager.FiresecDriver.Watcher.ZonesStateChanged += new Action<List<ZoneState>>(OnZoneStatesChanged);

			while (true)
			{
				if (StopEvent.WaitOne(5000))
					break;
			}
			srv.RevokeClassObject();
			srv = null;
		}
Exemple #3
0
		static void Run()
		{
			OPCDAServer = new OPCDAServer();
			OPCDAServer.Events.ServerReleased += new ServerReleasedEventHandler(Events_ServerReleased);
			OPCDAServer.Events.ReadItems += new ReadItemsEventHandler(Events_ReadItems);
			OPCDAServer.Events.WriteItems += new WriteItemsEventHandler(Events_WriteItems);
			OPCDAServer.Events.ActivateItems += new ActivateItemsEventHandler(Events_ActivateItems);
			OPCDAServer.Events.DeactivateItems += new DeactivateItemsEventHandler(Events_DeactivateItems);

			OPCDAServer.Initialize(srvGuid, 50, 50, ServerOptions.NoAccessPaths, '/', 100);

			if (FiresecManager.Devices == null)
				return;

			foreach (var device in XManager.Devices)
			{
				if (TagsCount >= 100)
					break;

				if (!device.IsOPCUsed)
					continue;

				var tagName = new StringBuilder();
				foreach (var parentDevice in device.AllParents)
				{
					if (parentDevice.Driver.DriverType != XDriverType.System)
					{
						if (parentDevice.Driver.HasAddress)
							tagName.Append(parentDevice.ShortName + " - " + parentDevice.PresentationAddress + "/");
						else
							tagName.Append(parentDevice.ShortName + "/");
					}
				}
				if (device.Driver.HasAddress)
					tagName.Append(device.ShortName + " - " + device.PresentationAddress + "/");
				else
					tagName.Append(device.ShortName + "/");

				var name = tagName.ToString();
				var tagId = OPCDAServer.CreateTag(
					TagsCount,
					name,
					AccessRights.readable,
					(double)0);

				var tagDevice = new TagDevice(tagId, device.State);
				TagDevices.Add(tagDevice);
				TagsCount++;
			}
			foreach (var zone in (from XZone zone in XManager.Zones orderby zone.No select zone))
			{
				if (TagsCount >= 100)
					break;

				if (!zone.IsOPCUsed)
					continue;

				var tagId = OPCDAServer.CreateTag(
					TagsCount,
					"Zones/" + zone.PresentationName,
					AccessRights.readable,
					(double)0);

				var tagZone = new TagZone(tagId, zone.State);
				TagZones.Add(tagZone);
				TagsCount++;
			}

			foreach (var direction in (from XDirection direction in XManager.Directions orderby direction.No select direction))
			{
				if (TagsCount >= 100)
					break;

				if (!direction.IsOPCUsed)
					continue;

				var tagId = OPCDAServer.CreateTag(
					TagsCount,
					"Directions/" + direction.PresentationName,
					AccessRights.readable,
					(double)0);

				var tagDirection = new TagDirection(tagId, direction.State);
				TagDirections.Add(tagDirection);
				TagsCount++;
			}

			OPCDAServer.RegisterClassObject();

			OPCDAServer.BeginUpdate();
			foreach (var tagDevice in TagDevices)
			{
				OPCDAServer.SetTag(tagDevice.TagId, tagDevice.State.StateClass);
			}
			foreach (var tagZone in TagZones)
			{
				OPCDAServer.SetTag(tagZone.TagId, tagZone.ZoneState.StateClass);
			}
			foreach (var tagDirection in TagDirections)
			{
				OPCDAServer.SetTag(tagDirection.TagId, tagDirection.State.StateClass);
			}
			OPCDAServer.EndUpdate(false);

			while (true)
			{
				if (StopEvent.WaitOne(5000))
					break;
			}
			OPCDAServer.RevokeClassObject();
			OPCDAServer = null;
		}