// 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); }
// fit an Icon according to the selected node private int Classe2Ico(CIPObjectLibrary clId) { switch (clId) { case CIPObjectLibrary.Identity: return(4); case CIPObjectLibrary.MessageRouter: return(5); case CIPObjectLibrary.ConnectionManager: return(8); case CIPObjectLibrary.Port: case CIPObjectLibrary.TCPIPInterface: case CIPObjectLibrary.EtherNetLink: case CIPObjectLibrary.ControlNet: case CIPObjectLibrary.DeviceNet: case CIPObjectLibrary.Modbus: return(6); case CIPObjectLibrary.Assembly: return(7); default: return(3); } }
public override EnIPNetworkStatus ReadDataFromNetwork() { byte[] DataPath = EnIPPath.GetPath(myInstance.myClass.Id, myInstance.Id, Id); EnIPNetworkStatus ret = ReadDataFromNetwork(DataPath, CIPServiceCodes.GetAttributeSingle); if (ret == EnIPNetworkStatus.OnLine) { CIPObjectLibrary classid = (CIPObjectLibrary)myInstance.myClass.Id; try { if (DecodedMembers == null) // No decoder { if (myInstance.DecodedMembers == null) { myInstance.AttachDecoderClass(); } DecodedMembers = myInstance.DecodedMembers; // get the same object as the associated Instance } int Idx = 0; DecodedMembers.DecodeAttr(Id, ref Idx, RawData); } catch { } } return(ret); }
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); }
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); }