/// <summary>
		/// Initializes a new instance of the <see cref="EpicsServerChannel"/> class.
		/// </summary>
		/// <param name="server">
		/// The server.
		/// </param>
		/// <param name="serverId">
		/// The server id.
		/// </param>
		/// <param name="clientId">
		/// The client id.
		/// </param>
		/// <param name="channelName">
		/// The channel name.
		/// </param>
		/// <param name="conn">
		/// The conn.
		/// </param>
		internal EpicsServerChannel(
			EpicsServer server, int serverId, int clientId, string channelName, EpicsServerTCPConnection conn)
		{
			this.NotDisposing = true;
			this.ServerId = serverId;
			this.ClientId = clientId;
			this.ChannelName = channelName;
			this.Server = server;
			this.Conn = conn;
			this.Conn.ConnectionStateChanged += this.Conn_ConnectionStateChanged;

			try
			{
				if (channelName.Contains("."))
				{
					var splitted = channelName.Split('.');
					this.Record = this.Server.recordList[splitted[0]];
					this.Property = (RecordProperty)Enum.Parse(typeof(RecordProperty), splitted[1]);
				}
				else
				{
					this.Record = this.Server.recordList[this.ChannelName];
				}

				this.Conn.Send(
					this.Server.Codec.channelCreatedMessage(
						this.ClientId, this.ServerId, this.Record.TYPE, this.Record.dataCount, this.Access));
			}
			catch (Exception e)
			{
				this.Conn.Send(this.Server.Codec.channelCreationFailMessage(this.ClientId));
				this.Dispose();
			}
		}
示例#2
0
        public static void Main()
        {
            /*Application.EnableVisualStyles();
             * Application.SetCompatibleTextRenderingDefault(false);
             * Application.Run(new TestApp());*/

            var client  = new EpicsClient();
            var monitor = client.CreateChannel("TestChannel01:Counter");

            monitor.MonitorChanged += (sender, value) => Console.WriteLine(value);

            Task.Factory.StartNew(() =>
            {
                var server = new EpicsServer();
                var record = server.GetEpicsRecord <string>("TestChannel01:Counter");

                for (int i = 0; i < 500; i++)
                {
                    record.VAL = i.ToString();
                    Thread.Sleep(1000);
                }
            });



            /*var server = new EpicsServer();
             * var record = server.GetEpicsRecord<double>("TestChannel01:Counter");
             * record.HIGH = 50;
             * record.HIHI = 75;
             * record.VAL = 19;
             *
             * for (int i = 0; i < 10; i++)
             * {
             *      record.VAL = i;
             *      Thread.Sleep(1000);
             * }*/

            Console.ReadKey();
        }
		public void ClientServer()
		{
			using (var server = new EpicsServer())
			using (var client = new EpicsClient())
			{
				server.Config.BeaconPort = 95;
				server.Config.TCPPort = 115;
				server.Config.UDPPort = 115;
				server.Config.UDPDestPort = 115;

				var record = server.GetEpicsRecord<double>("OMA:Counter");
				record.HIGH = 50;
				record.HIHI = 75;
				record.VAL = 19;

				client.Config.UDPBeaconPort = 95;
				client.Config.UDPIocPort = 115;

				var monitor = client.CreateChannel("OMA:Counter");
				Assert.Equal(19, monitor.Get());
			}
		}
示例#4
0
        public void ClientServer()
        {
            using (var server = new EpicsServer())
                using (var client = new EpicsClient())
                {
                    server.Config.BeaconPort  = 95;
                    server.Config.TCPPort     = 115;
                    server.Config.UDPPort     = 115;
                    server.Config.UDPDestPort = 115;

                    var record = server.GetEpicsRecord <double>("OMA:Counter");
                    record.HIGH = 50;
                    record.HIHI = 75;
                    record.VAL  = 19;

                    client.Config.UDPBeaconPort = 95;
                    client.Config.UDPIocPort    = 115;

                    var monitor = client.CreateChannel("OMA:Counter");
                    Assert.Equal(19, monitor.Get());
                }
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="EpicsServerUDPConnection"/> class.
		/// </summary>
		/// <param name="server">
		/// The server.
		/// </param>
		public EpicsServerUDPConnection(EpicsServer server)
			: base(new IPEndPoint(IPAddress.Parse(server.Config.ListenIP), server.Config.UDPPort))
		{
			this.Server = server;

			this.UDPSocket.ReceiveBufferSize = server.Config.UDPBufferSize;
			this.UDPSocket.SendBufferSize = server.Config.UDPBufferSize;

			var targetAddresses = new List<string>();
			var interfaces = NetworkInterface.GetAllNetworkInterfaces();
			long longIp = 0;
			IPAddress ip = null;

			foreach (var iface in interfaces)
			{
				var prop = iface.GetIPProperties();

				try
				{
					longIp = (prop.UnicastAddresses[0].IPv4Mask.Address ^ IPAddress.Broadcast.Address)
					         | prop.UnicastAddresses[0].Address.Address;
					ip = new IPAddress(longIp);
				}
				catch (Exception e)
				{
					continue;
				}

				targetAddresses.Add(ip + ":" + this.Server.Config.UDPDestPort);
			}

			if (targetAddresses.Count == 0)
			{
				targetAddresses.Add(IPAddress.Broadcast + ":" + this.Server.Config.UDPDestPort);
			}

			this.wrapTargetList(targetAddresses);
		}
示例#6
0
		public static void Main()
		{
			/*Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new TestApp());*/

			var client = new EpicsClient();
			var monitor = client.CreateChannel("TestChannel01:Counter");
			monitor.MonitorChanged += (sender, value) => Console.WriteLine(value);
			
			Task.Factory.StartNew(() =>
				{
					var server = new EpicsServer();
					var record = server.GetEpicsRecord<string>("TestChannel01:Counter");
					
					for (int i = 0; i < 500; i++)
					{
						record.VAL = i.ToString();
						Thread.Sleep(1000);
					}
				});



			/*var server = new EpicsServer();
			var record = server.GetEpicsRecord<double>("TestChannel01:Counter");
			record.HIGH = 50;
			record.HIHI = 75;
			record.VAL = 19;

			for (int i = 0; i < 10; i++)
			{
				record.VAL = i;
				Thread.Sleep(1000);
			}*/

			Console.ReadKey();
		}
示例#7
0
		/// <summary>
		/// Initializes a new instance of the <see cref="EpicsServerCodec"/> class.
		/// </summary>
		/// <param name="server">
		/// The server.
		/// </param>
		public EpicsServerCodec(EpicsServer server)
		{
			this.Server = server;
		}
示例#8
0
 public Server()
 {
     this.epicsServer = new EpicsServer();
     this.Channels    = new Dictionary <string, Channel>();
 }
示例#9
0
		/// <summary>
		/// Initializes a new instance of the <see cref="EpicsRecord"/> class.
		/// </summary>
		/// <param name="Name">
		/// The name.
		/// </param>
		/// <param name="server">
		/// The server.
		/// </param>
		internal EpicsRecord(string Name, EpicsServer server)
		{
			this.name = Name;
			this.Server = server;
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="EpicsServerTCPConnection"/> class.
		/// </summary>
		/// <param name="TCPSocket">
		/// The tcp socket.
		/// </param>
		/// <param name="server">
		/// The server.
		/// </param>
		internal EpicsServerTCPConnection(Socket TCPSocket, EpicsServer server)
			: base(TCPSocket)
		{
			this.Server = server;
			this.remoteKey = TCPSocket.RemoteEndPoint.ToString();
		}