diff --git a/libEDSsharp/eds.cs b/libEDSsharp/eds.cs index 5f845a5c..56e63e87 100644 --- a/libEDSsharp/eds.cs +++ b/libEDSsharp/eds.cs @@ -13,7 +13,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the You should have received a copy of the GNU General Public License along with libEDSsharp. If not, see . - + Copyright(c) 2016 - 2019 Robin Cornelius */ @@ -29,7 +29,7 @@ You should have received a copy of the GNU General Public License namespace libEDSsharp { - + public enum DataType { UNKNOWN = 0, @@ -229,7 +229,7 @@ public bool IsReadOnly() return commentonly; } - + } public class DcfExport : EdsExport @@ -271,7 +271,7 @@ public bool GetField(string name, string varname) { FieldInfo f = null; - try + try { foreach (var element in section) { @@ -388,10 +388,10 @@ public void Write(StreamWriter writer, Filetype ft) writer.WriteLine(""); } - + } - + public class MandatoryObjects : SupportedObjects { public MandatoryObjects() @@ -440,7 +440,7 @@ public ManufacturerObjects(Dictionary section) } public class TypeDefinitions : SupportedObjects - { + { public TypeDefinitions() : base() { infoheader = "Type Definitions"; @@ -524,10 +524,10 @@ public class Comments public Comments() { - + } - public Comments(Dictionary section) + public Comments(Dictionary section) { Parse(section); } @@ -581,7 +581,7 @@ public void Write(StreamWriter writer) } writer.WriteLine(""); - } + } } @@ -602,7 +602,7 @@ public class Dummyusage : InfoSection [EdsExport] public bool Dummy0007; - + public Dummyusage() { infoheader = "CAN OPEN Dummy Usage"; @@ -629,7 +629,7 @@ public class FileInfo : InfoSection public string LastEDS = ""; public byte EDSVersionMajor;//=4.0 - + public byte EDSVersionMinor;//=4.0 [EdsExport] public string EDSVersion=""; @@ -645,7 +645,7 @@ public class FileInfo : InfoSection [EdsExport(maxlength = 245)] public string CreatedBy = "";//=CANFestival //max245 - + public DateTime ModificationDateTime;// [EdsExport] @@ -858,7 +858,7 @@ public SupportedModules(Dictionary section) : this() Parse(section,edssection); } - + } public class ConnectedModules : SupportedObjects @@ -883,7 +883,7 @@ public ConnectedModules(Dictionary section) : this() { Parse(section); - + foreach(KeyValuePair kvp in this.objectlist) { @@ -897,7 +897,7 @@ public ConnectedModules(Dictionary section) : this() } } - + } public class MxFixedObjects : SupportedObjects @@ -1046,7 +1046,7 @@ public UInt16 Index //throw (new Exception("Typing to set index of a subobject")); } - + } } @@ -1076,7 +1076,7 @@ public UInt16 Index public string actualvalue = ""; [EdsExport] - public Byte ObjFlags = 0; + public UInt32 ObjFlags = 0; [EdsExport] public byte CompactSubObj = 0; @@ -1185,7 +1185,7 @@ public ODentry(string parameter_name, UInt16 index, DataType datatype, string d this.PDOtype = PDOMapping; } - + /// /// ODEntry constructor for array subobjects @@ -1199,7 +1199,7 @@ public ODentry(string parameter_name,UInt16 index, byte nosubindex) this.objecttype = ObjectType.ARRAY; this.Index = index; //this.nosubindexes = nosubindex; - this.objecttype = ObjectType.VAR; + this.objecttype = ObjectType.VAR; } /// @@ -1243,7 +1243,7 @@ public override string ToString() if (subobjects.Count > 0) { return String.Format("{0:x4}[{1}] : {2} : {3}", Index, subobjects.Count, parameter_name, datatype); - + } else { @@ -1478,7 +1478,7 @@ public string Formatoctetstring(string value) /// /// Handle to the stream writer to write to /// File type being written - /// + /// public void Write(StreamWriter writer, InfoSection.Filetype ft, Odtype odt= Odtype.NORMAL, int module=0) { @@ -1541,7 +1541,7 @@ public void Write(StreamWriter writer, InfoSection.Filetype ft, Odtype odt= Odty { writer.WriteLine(string.Format("LowLimit={0}", Formatoctetstring(LowLimit))); } - + writer.WriteLine(string.Format("DefaultValue={0}", Formatoctetstring(defaultvalue))); //TODO If the ObjectType is domain (0x2) the value of the object may be stored in a file,UploadFile and DownloadFile @@ -1594,7 +1594,7 @@ public string Paramater_cname() } /// - /// Return the size in bytes for the given CANopen datatype of this object, eg the size of what ever the datatype field is set to + /// Return the size in bytes for the given CANopen datatype of this object, eg the size of what ever the datatype field is set to /// /// no of bytes public int Sizeofdatatype() @@ -1603,7 +1603,7 @@ public int Sizeofdatatype() if (dt == DataType.UNKNOWN && this.parent != null) dt = parent.datatype; - + switch (dt) { case DataType.BOOLEAN: @@ -1659,7 +1659,7 @@ public int Sizeofdatatype() } } - + /// /// This is the no of subindexes present in the object, it is NOT the maximum subobject index /// @@ -1671,7 +1671,7 @@ public int Nosubindexes return subobjects.Count; } } - + //warning eds files with gaps in subobject lists have been seen in the wild //this function tries to get the array index based on sub number not array number //it may return null @@ -1746,7 +1746,7 @@ public int Lengthofstring } public UInt16 Subindex - { + { get { if(this.parent!=null) @@ -2079,7 +2079,7 @@ public void Parseline(string linex,int no) { eds.Add(sectionname, new Dictionary()); } - + if (custom_extension == false) { try @@ -2139,9 +2139,9 @@ public void ParseEDSentry(KeyValuePair> kvp) modules.Add(modindex, new Module(modindex)); if (m2.Groups[2].ToString() == "SubExt") - { + { target = modules[modindex].modulesubext; - + } else { @@ -2179,7 +2179,7 @@ public void ParseEDSentry(KeyValuePair> kvp) if(kvp.Value.ContainsKey("ObjFlags")) { - od.ObjFlags = Convert.ToByte(kvp.Value["ObjFlags"], Getbase(kvp.Value["ObjFlags"])); + od.ObjFlags = Convert.ToUInt32(kvp.Value["ObjFlags"], Getbase(kvp.Value["ObjFlags"])); } else { @@ -2251,7 +2251,7 @@ public void ParseEDSentry(KeyValuePair> kvp) if (!kvp.Value.ContainsKey("DataType")) throw new ParameterException("Missing required field DataType on" + section); od.datatype = (DataType)Convert.ToInt16(kvp.Value["DataType"], Getbase(kvp.Value["DataType"])); - + if (!kvp.Value.ContainsKey("AccessType")) throw new ParameterException("Missing required AccessType on" + section); @@ -2272,7 +2272,7 @@ public void ParseEDSentry(KeyValuePair> kvp) od.PDOtype = PDOMappingType.no; if (kvp.Value.ContainsKey("PDOMapping")) { - + bool pdo = Convert.ToInt16(kvp.Value["PDOMapping"],Getbase(kvp.Value["PDOMapping"])) == 1; if (pdo == true) od.PDOtype = PDOMappingType.optional; @@ -2280,7 +2280,7 @@ public void ParseEDSentry(KeyValuePair> kvp) } - + if(od.objecttype == ObjectType.REC|| od.objecttype == ObjectType.ARRAY || od.objecttype == ObjectType.DEFSTRUCT) { @@ -2309,7 +2309,7 @@ public void ParseEDSentry(KeyValuePair> kvp) od.CompactSubObj = 0xfe; } - ODentry subi = new ODentry("NrOfObjects", od.Index, DataType.UNSIGNED8, String.Format("0x{0:x2}",od.CompactSubObj), AccessType.ro, PDOMappingType.no, od); + ODentry subi = new ODentry("NrOfObjects", od.Index, DataType.UNSIGNED8, String.Format("0x{0:x2}",od.CompactSubObj), AccessType.ro, PDOMappingType.no, od); od.subobjects.Add(0x00, subi); for (int x=1; x<= od.CompactSubObj; x++) @@ -2409,7 +2409,7 @@ public void Loadfile(string filename) dc.Parse(eds["DeviceCommissioning"],"DeviceCommissioning"); edsfilename = fi.LastEDS; } - + c = new Comments(); if (eds.ContainsKey("Comments")) @@ -2499,7 +2499,7 @@ public void Loadfile(string filename) if (eds.ContainsKey("ConnectedModules")) { - cm = new ConnectedModules(eds["ConnectedModules"]); + cm = new ConnectedModules(eds["ConnectedModules"]); } //COMPACT PDO @@ -2646,7 +2646,7 @@ public void Savefile(string filename, InfoSection.Filetype ft) fi.EDSVersionMajor = 4; fi.EDSVersionMinor = 0; - StreamWriter writer = File.CreateText(filename); + StreamWriter writer = File.CreateText(filename); writer.NewLine = "\n"; fi.Write(writer,ft); di.Write(writer,ft); @@ -2697,7 +2697,7 @@ public void Savefile(string filename, InfoSection.Filetype ft) { ODentry od2 = kvp2.Value; od2.Write(writer,ft); - } + } } } @@ -2713,7 +2713,7 @@ public void Savefile(string filename, InfoSection.Filetype ft) { ODentry od2 = kvp2.Value; od2.Write(writer,ft); - } + } } } @@ -2729,7 +2729,7 @@ public void Savefile(string filename, InfoSection.Filetype ft) { ODentry od2 = kvp2.Value; od2.Write(writer,ft); - } + } } } @@ -2911,7 +2911,7 @@ public UInt32 GetNodeID(string input, out bool nodeidpresent) input = input.ToUpper(); - if(input.Contains("$NODEID")) + if(input.Contains("$NODEID")) nodeidpresent = true; else nodeidpresent = false; @@ -3085,7 +3085,7 @@ mapped object (subindex 1...8) ODentry sub; - + if(rx) { sub = new ODentry("max sub-index", index, DataType.UNSIGNED8, "2", AccessType.ro, PDOMappingType.no, od_comparam); @@ -3179,7 +3179,7 @@ public ODentry Getobject(string uniqueID) } } - + } @@ -3222,10 +3222,10 @@ public class ParameterException : Exception public ParameterException(String message) : base(message) { - + } } - + }