Example #1
0
 /// <summary>
 /// AdsClient Constructor
 /// This can be used if you wan't to use your own IAmsSocket implementation.
 /// </summary>
 /// <param name="amsSocket">Your own IAmsSocket implementation</param>
 /// <param name="amsNetIdSource">
 /// The AmsNetId of this device. You can choose something in the form of x.x.x.x.x.x
 /// You have to define this ID in combination with the IP as a route on the target Ads device
 /// </param>
 /// <param name="amsNetIdTarget">The AmsNetId of the target Ads device</param>
 /// <param name="amsPortTarget">Ams port. Default 801</param>
 public AdsClient(string amsNetIdSource, IAmsSocket amsSocket, string amsNetIdTarget, ushort amsPortTarget = 801)
 {
     ams = new Ams(amsSocket);
     ams.AmsNetIdSource = new AmsNetId(amsNetIdSource);
     ams.AmsNetIdTarget = new AmsNetId(amsNetIdTarget);
     ams.AmsPortTarget  = amsPortTarget;
 }
Example #2
0
        public static IAmsSocket GetOrCreateAmsSocket <T>(string ipTarget, int portTarget) where T : IAmsSocket, new()
        {
            IAmsSocket amsSocket = SocketList.FirstOrDefault(s => (s.IpTarget == ipTarget) && (s.PortTarget == portTarget));

            if (amsSocket == null)
            {
                amsSocket = (T)Activator.CreateInstance(typeof(T), ipTarget, portTarget);
                SocketList.Add(amsSocket);
            }
            amsSocket.Subscribers++;
            return(amsSocket);
        }
Example #3
0
        public static void UnsibscribeAmsSocket(string ipTarget)
        {
            IAmsSocket amsSocket = SocketList.FirstOrDefault(s => s.IpTarget == ipTarget);

            if (amsSocket != null)
            {
                amsSocket.Subscribers--;
                if (amsSocket.Subscribers <= 0)
                {
                    SocketList.Remove(amsSocket);
                    amsSocket.Dispose();
                }
            }
        }
Example #4
0
//        internal Ams(string ipTarget, int ipPortTarget = 48898)
//        {
//            this.IpTarget = ipTarget;
//            this.NotificationRequests = new List<AdsNotification>();
//            this.amsSocket = AmsSocketHelper.GetOrCreateAmsSocket(ipTarget, ipPortTarget);
//            this.amsSocket.OnReadCallBack += new AmsSocketResponseDelegate(ReadCallback);
//        }

        internal Ams(IAmsSocket amsSocket)
        {
            this.NotificationRequests      = new List <AdsNotification>();
            this.amsSocket                 = amsSocket;
            this.amsSocket.OnReadCallBack += new AmsSocketResponseDelegate(ReadCallback);
        }
Example #5
0
 internal Ams(IAmsSocket amsSocket)
 {
     this.amsSocket = amsSocket;
     this.amsSocket.OnReadCallBack += new AmsSocketResponseDelegate(ReadCallback);
 }