Exemplo n.º 1
0
        // A new Class inside the Treeview : name & icon
        private TreeNode ClassToTreeNode(EnIPClass Class)
        {
            TreeNode tn;

            // Known classes
            if (Enum.IsDefined(typeof(CIPObjectLibrary), Class.Id))
            {
                CIPObjectLibrary cipobj = (CIPObjectLibrary)Class.Id;
                int img = Classe2Ico(cipobj);
                tn = new TreeNode(cipobj.ToString() + " #" + IdStr(Class.Id), img, img);

                // Special classes with the known instance(s)
                if ((Class.Id == 1) || (Class.Id == 2) || (Class.Id == 0xF4) || (Class.Id == 0xF5) || (Class.Id == 0xF6))
                {
                    EnIPInstance instance = new EnIPInstance(Class, 1); // Instance 1
                    TreeNode     tnI      = new TreeNode("Instance #" + IdStr(1), 9, 9);
                    tnI.Tag         = instance;
                    tnI.ToolTipText = "Node " + IdStr(Class.Id) + "." + IdStr(1);
                    tn.Nodes.Add(tnI);
                }
            }
            else
            {
                tn = new TreeNode("Proprietary #" + IdStr(Class.Id), 2, 2);
            }

            tn.ToolTipText = "Node " + IdStr(Class.Id);
            tn.Tag         = Class;
            return(tn);
        }
Exemplo n.º 2
0
        public bool AttachDecoderClass()
        {
            CIPObjectLibrary classid = (CIPObjectLibrary)myClass.Id;

            try
            {
                if (DecoderClass == null)
                {
                    var o = Activator.CreateInstance(Assembly.GetExecutingAssembly().FullName, "System.Net.EnIPStack.ObjectsLibrary.CIP_" + classid.ToString() + "_instance");
                    DecodedMembers = (CIPObject)o.Unwrap();
                }
                else
                {
                    var o = Activator.CreateInstance(DecoderClass);
                    DecodedMembers = (CIPObject)o;
                }
                return(true);
            }
            catch { }

            return(false);
        }
Exemplo n.º 3
0
        public override EnIPNetworkStatus ReadDataFromNetwork()
        {
            // Read all class static attributes
            byte[]            ClassDataPath = EnIPPath.GetPath(Id, 0, null);
            EnIPNetworkStatus ret           = ReadDataFromNetwork(ClassDataPath, CIPServiceCodes.GetAttributesAll);

            // If rejected try to read all attributes one by one
            if (ret == EnIPNetworkStatus.OnLineReadRejected)
            {
                MemoryStream rawbuffer = new MemoryStream();

                ushort AttId = 1; // first static attribut number

                do
                {
                    ClassDataPath = EnIPPath.GetPath(Id, 0, AttId);
                    ret           = ReadDataFromNetwork(ClassDataPath, CIPServiceCodes.GetAttributeSingle);

                    // push the buffer into the data stream
                    if (ret == EnIPNetworkStatus.OnLine)
                    {
                        rawbuffer.Write(RawData, 0, RawData.Length);
                    }
                    AttId++;
                }while (ret == EnIPNetworkStatus.OnLine);

                // yes OK like this, pull the data out of the stream into the RawData
                if (rawbuffer.Length != 0)
                {
                    Status  = ret = EnIPNetworkStatus.OnLine; // all is OK even if the last request is (always) rejected
                    RawData = rawbuffer.ToArray();
                }
            }

            if (ret == EnIPNetworkStatus.OnLine)
            {
                CIPObjectLibrary classid = (CIPObjectLibrary)Id;
                try
                {
                    if (DecodedMembers == null)
                    {
                        try
                        {
                            if (DecoderClass == null)
                            {
                                // try to create the associated class object
                                var o = Activator.CreateInstance(Assembly.GetExecutingAssembly().FullName, "System.Net.EnIPStack.ObjectsLibrary.CIP_" + classid.ToString() + "_class");
                                DecodedMembers = (CIPObject)o.Unwrap();
                            }
                            else
                            {
                                var o = Activator.CreateInstance(DecoderClass);
                                DecodedMembers = (CIPObject)o;
                            }
                        }
                        catch
                        {
                            // echec, get the base class as described in Volume 1, §4-4.1 Class Attributes
                            DecodedMembers = new CIPObjectBaseClass(classid.ToString());
                        }
                    }
                    DecodedMembers.SetRawBytes(RawData);
                }
                catch { }
            }
            return(ret);
        }