From c92270de2fd307c4acbf5f5a687bbebc17abd776 Mon Sep 17 00:00:00 2001 From: Lars Elgtvedt Susaas <9848846+nimrof@users.noreply.github.com> Date: Tue, 2 Apr 2024 20:52:57 +0200 Subject: [PATCH] removed canopen xml support --- EDSEditorGUI/Form1.cs | 139 +-------- EDSSharp/Program.cs | 21 +- README.md | 6 - libEDSsharp/Bridge.cs | 590 -------------------------------------- libEDSsharp/CanOpenXML.cs | 333 --------------------- libEDSsharp/eds.cs | 1 - 6 files changed, 7 insertions(+), 1083 deletions(-) delete mode 100644 libEDSsharp/Bridge.cs delete mode 100644 libEDSsharp/CanOpenXML.cs diff --git a/EDSEditorGUI/Form1.cs b/EDSEditorGUI/Form1.cs index 46b40837..92daaed7 100644 --- a/EDSEditorGUI/Form1.cs +++ b/EDSEditorGUI/Form1.cs @@ -25,7 +25,6 @@ You should have received a copy of the GNU General Public License using System.Windows.Forms; using System.IO; using libEDSsharp; -using Xml2CSharp; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace ODEditor @@ -140,13 +139,6 @@ void ProfileAddClick(object sender, EventArgs e) CanOpenXDD_1_1 coxml_1_1 = new CanOpenXDD_1_1(); eds = coxml_1_1.ReadXML(filename); break; - - case ".xml": - CanOpenXML coxml = new CanOpenXML(); - coxml.readXML(filename); - Bridge b = new Bridge(); - eds = b.convert(coxml.dev); - break; } if (eds == null) @@ -196,11 +188,8 @@ private void openEDSfile(string path,InfoSection.Filetype ft) try { EDSsharp eds = new EDSsharp(); - Device dev; eds.Loadfile(path); - Bridge bridge = new Bridge(); //tell me again why bridge is not static? - dev = bridge.convert(eds); DeviceView device = new DeviceView(eds, network); @@ -288,13 +277,12 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e) Warnings.warning_list.Clear(); OpenFileDialog odf = new OpenFileDialog(); - odf.Filter = "All supported files (*.xdd;*.xdc;*.xpd;*.eds;*.dcf;*.xml)|*.xdd;*.xdc;*.xpd;*.eds;*.dcf;*.xml|" + odf.Filter = "All supported files (*.xdd;*.xdc;*.xpd;*.eds;*.dcf)|*.xdd;*.xdc;*.xpd;*.eds;*.dcf|" + "CANopen XDD (*.xdd)|*.xdd|" + "CANopen XDC (*.xdc)|*.xdc|" + "CANopen XPD (*.xpd)|*.xpd|" + "Electronic Data Sheet (*.eds)|*.eds|" - + "Device Configuration File (*.dcf)|*.dcf|" - + "CANopenNode XML, old (*.xml)|*.xml"; + + "Device Configuration File (*.dcf)|*.dcf"; if (odf.ShowDialog() == DialogResult.OK) { @@ -307,10 +295,6 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e) openXDDfile(odf.FileName); break; - case ".xml": - openXMLfile(odf.FileName); - break; - case ".eds": openEDSfile(odf.FileName, InfoSection.Filetype.File_EDS); break; @@ -382,50 +366,6 @@ private void openXDDfile(string path) - } - - private void openXMLfile(string path) - { - - try - { - EDSsharp eds; - Device dev; //one day this will be multiple devices - - CanOpenXML coxml = new CanOpenXML(); - coxml.readXML(path); - - Bridge b = new Bridge(); - - eds = b.convert(coxml.dev); - eds.projectFilename = path; - - dev = coxml.dev; - - tabControl1.TabPages.Add(eds.di.ProductName); - - DeviceView device = new DeviceView(eds, network); - device.UpdateODViewForEDS += Device_UpdateODViewForEDS; - eds.OnDataDirty += Eds_onDataDirty; - - tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(device); - - device.Dock = DockStyle.Fill; - device.dispatch_updateOD(); - - network.Add(eds); - } - catch (Exception ex) - { - Warnings.warning_list.Add(ex.ToString()); - } - - if (Warnings.warning_list.Count != 0) - { - WarningsFrm frm = new WarningsFrm(); - frm.Show(); - } - } private void Device_UpdateODViewForEDS(object sender, UpdateODViewEventArgs e) @@ -544,8 +484,7 @@ private void exportDeviceFileToolStripMenuItem_Click(object sender, EventArgs e) + "Electronic Data Sheet (*.eds)|*.eds|" + "Device Configuration File (*.dcf)|*.dcf|" + "Documentation (*.md)|*.md|" - + "CANopen XDD v1.0, old (*.xdd)|*.xdd|" - + "CANopenNode XML, old (*.xml)|*.xml"; + + "CANopen XDD v1.0, old (*.xdd)|*.xdd"; sfd.InitialDirectory = Path.GetDirectoryName(dv.eds.projectFilename); sfd.RestoreDirectory = true; @@ -632,16 +571,6 @@ void dosave(DeviceView dv, string FileName, bool xddfileVersion_1_1, bool stripp dv.eds.mdfilename = FileName; break; - case ".xml": - Bridge b = new Bridge(); - Device d = b.convert(dv.eds); - - CanOpenXML coxml = new CanOpenXML(); - coxml.dev = d; - coxml.writeXML(FileName); - dv.eds.xmlfilename = FileName; - break; - case ".xdd": case ".xdc": case ".xpd": @@ -751,16 +680,12 @@ void OpenRecentFile(object sender, EventArgs e) if (ext != null) ext = ext.ToLower(); - if ( ext == ".xml" ) - openXMLfile(filepath); if (ext == ".xdd" || ext == ".xdc" || ext == ".xpd") openXDDfile(filepath); if ( ext == ".eds" ) openEDSfile(filepath, InfoSection.Filetype.File_EDS); if (ext == ".dcf") openEDSfile(filepath, InfoSection.Filetype.File_DCF); - if (ext == ".nxml") - openNetworkfile(filepath); } @@ -856,8 +781,7 @@ private void saveNetworkXmlToolStripMenuItem_Click(object sender, EventArgs e) sfd.Filter = "CANopen Network XDD v1.1 (*.nxdd)|*.nxdd|" + "CANopen Network XDC v1.1 (*.nxdc)|*.nxdc|" - + "CANopen Network XDD v1.0, old (*.nxdd)|*.nxdd|" - + "CANopenNode network XML, old (*.nxml)|*.nxml"; + + "CANopen Network XDD v1.0, old (*.nxdd)|*.nxdd"; sfd.InitialDirectory = Path.GetDirectoryName(networkfilename); sfd.RestoreDirectory = true; @@ -867,12 +791,6 @@ private void saveNetworkXmlToolStripMenuItem_Click(object sender, EventArgs e) { switch (sfd.FilterIndex) { - case 4: // .nxml - NetworkXML net = new NetworkXML(); - net.writeXML(sfd.FileName, network); - addtoMRU(sfd.FileName); - break; - case 3: // .nxdd V1.0 CanOpenXDD xdd = new CanOpenXDD(); xdd.writeMultiXML(sfd.FileName, network); @@ -895,19 +813,14 @@ private void loadNetworkXmlToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog odf = new OpenFileDialog(); - odf.Filter = "All supported files (*.nxdd;*.nxdc;*.nxml)|*.nxdd;*.nxdc;*.nxml|" + odf.Filter = "All supported files (*.nxdd;*.nxdc)|*.nxdd;*.nxdc|" + "CANopen Network XDD (*.nxdd)|*.nxdd|" - + "CANopen Network XDC (*.nxdc)|*.nxdc|" - + "CANopenNode network XML, old (*.nxml)|*.nxml"; + + "CANopen Network XDC (*.nxdc)|*.nxdc|"; if (odf.ShowDialog() == DialogResult.OK) { switch (Path.GetExtension(odf.FileName).ToLower()) { - case ".nxml": - openNetworkfile(odf.FileName); - break; - case ".nxdd": case ".nxdc": openXDDNetworkfile(odf.FileName); @@ -953,38 +866,6 @@ private void openXDDNetworkfile(string file) } - private void openNetworkfile(string file) - { - NetworkXML net = new NetworkXML(); - List devs = net.readXML(file); - - foreach (Device d in devs) - { - Bridge b = new Bridge(); - - EDSsharp eds = b.convert(d); - //eds.filename = path; //fixme: We need to save the projectfilename or SaveAs will throw an exception - - tabControl1.TabPages.Add(eds.di.ProductName); - - - DeviceView device = new DeviceView(eds, network); - - tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(device); - device.Dock = DockStyle.Fill; - - network.Add(eds); - device.UpdateODViewForEDS += Device_UpdateODViewForEDS; - eds.OnDataDirty += Eds_onDataDirty; - - device.dispatch_updateOD(); - - addtoMRU(file); - } - - networkfilename = file; - } - private void networkPDOToolStripMenuItem_Click(object sender, EventArgs e) { @@ -1305,10 +1186,6 @@ private void ODEditor_MainForm_DragDrop(object sender, DragEventArgs e) openXDDfile(fileName); break; - case ".xml": - openXMLfile(fileName); - break; - case ".eds": openEDSfile(fileName, InfoSection.Filetype.File_EDS); break; @@ -1317,10 +1194,6 @@ private void ODEditor_MainForm_DragDrop(object sender, DragEventArgs e) openEDSfile(fileName, InfoSection.Filetype.File_DCF); break; - case ".nxml": - openNetworkfile(fileName); - break; - case ".nxdc": case ".nxdd": openXDDNetworkfile(fileName); diff --git a/EDSSharp/Program.cs b/EDSSharp/Program.cs index 41153559..e149a96e 100644 --- a/EDSSharp/Program.cs +++ b/EDSSharp/Program.cs @@ -60,10 +60,6 @@ static void Main(string[] args) openXDDfile(infile, outfile,type); break; - case ".xml": - openXMLfile(infile,outfile,type); - break; - case ".eds": openEDSfile(infile, outfile,InfoSection.Filetype.File_EDS,type); break; @@ -76,7 +72,7 @@ static void Main(string[] args) } else { - Console.WriteLine("Usage EDSEditor --type [CanOpenNode|CanOpenNodeV4] --infile file.[xdd|eds|xml] --outfile [CO_OD.c|OD]"); + Console.WriteLine("Usage EDSEditor --type [CanOpenNode|CanOpenNodeV4] --infile file.[xdd|eds] --outfile [CO_OD.c|OD]"); } } catch(Exception e) @@ -117,21 +113,6 @@ private static void exportCOOD(string outpath,ExporterFactory.Exporter type) } - private static void openXMLfile(string path,string outpath,ExporterFactory.Exporter exportertype) - { - - CanOpenXML coxml = new CanOpenXML(); - coxml.readXML(path); - - Bridge b = new Bridge(); - - eds = b.convert(coxml.dev); - - eds.projectFilename = path; - exportCOOD(outpath,exportertype); - - } - private static void openXDDfile(string path, string outpath,ExporterFactory.Exporter exportertype) { CanOpenXDD_1_1 coxml_1_1 = new CanOpenXDD_1_1(); diff --git a/README.md b/README.md index 955547d4..07e60e0d 100644 --- a/README.md +++ b/README.md @@ -69,10 +69,6 @@ Library * Read EDS/DCF/XDC file and parse contents to approprate classes * Dump EDS/DCF classes via ToString() * Save EDS/DCF classes back to EDS file -* Read CanOpenNode xml project file -* Write CanOpenNode xmlproject file -* Switch formats between EDS/DCF and CanOpenNode XML (note to EDS will result in - data loss as the format supports less information). * Export C and H files in CanOpenNode format CO_OD.c and CO_OD.h * EDS/DCF supports modules * EDS/DCF supports compactPDO (read only) 1* @@ -88,8 +84,6 @@ GUI * Open multiple devices * Open EDS/DCF/XDC files * Save EDS/DCF/XDC files -* Open CanOpenNode XML Project file -* Save CanOpenNode XML File * View OD Entries and explore the Object Dictionary * Add new OD entries * Delete exisiting OD entries diff --git a/libEDSsharp/Bridge.cs b/libEDSsharp/Bridge.cs deleted file mode 100644 index 3e6a3570..00000000 --- a/libEDSsharp/Bridge.cs +++ /dev/null @@ -1,590 +0,0 @@ -/* - This file is part of libEDSsharp. - - libEDSsharp is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - libEDSsharp is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with libEDSsharp. If not, see . - - Copyright(c) 2016 - 2019 Robin Cornelius -*/ - -using System; -using System.Collections.Generic; -using System.Globalization; -using Xml2CSharp; -using System.Text.RegularExpressions; - -/* I know I'm going to regret this - * - * I quite like my eds class as it trys to validate the EDS using typing and enums etc - * but i also want the XML wrappers for the CANOpenXML - * so I'm going to make a converter outside of both classes hence this bridge - * which is more code to manage ;-( - * */ - -namespace libEDSsharp -{ - /// - /// Converts between CanOpenXML and EDSsharp - /// - public class Bridge - { - /// - /// Convert from EDSsharp to CanOpenXML - /// - /// the eds data - /// CanOpenXML device containing data from eds - public Device convert(EDSsharp eds) - { - eds.UpdatePDOcount(); - - Device dev = new Device(); - dev.CANopenObjectList = new Xml2CSharp.CANopenObjectList(); - dev.CANopenObjectList.CANopenObject = new List(); - - /* OBJECT DICTIONARY */ - - foreach (KeyValuePair kvp in eds.ods) - { - ODentry od = kvp.Value; - - // if(od.subindex==-1) - { - if (od.objecttype == ObjectType.ARRAY && od.datatype == DataType.UNKNOWN) - { - //add the datatype field to parent objects if they don't have it already - //if the 2nd subobject does not exist then we do nothing. - ODentry sub = od.Getsubobject(1); - if (sub != null) - { - od.datatype = sub.datatype; - } - } - - if (od.objecttype == ObjectType.RECORD && od.accesstype == EDSsharp.AccessType.UNKNOWN) - { - ODentry sub = od.Getsubobject(1); - if (sub != null) - { - od.accesstype = sub.accesstype; - } - } - - Xml2CSharp.CANopenObject coo = new Xml2CSharp.CANopenObject(); - coo.Index = string.Format("{0:x4}", od.Index); - coo.Name = od.parameter_name; - coo.ObjectType = od.objecttype.ToString(); - coo.Disabled = od.prop.CO_disabled.ToString().ToLower(); - coo.MemoryType = od.prop.CO_storageGroup; - eds.CO_storageGroups.Add(od.prop.CO_storageGroup); - coo.AccessType = od.accesstype.ToString(); - coo.DataType = string.Format("0x{0:x2}", (int)od.datatype); - coo.DefaultValue = od.defaultvalue; - coo.HighValue = od.HighLimit; - coo.LowValue = od.LowLimit; - coo.PDOmapping = od.PDOtype.ToString(); - coo.TPDOdetectCOS = od.prop.CO_flagsPDO.ToString().ToLower(); - - coo.Description = new Xml2CSharp.Description(); - coo.Description.Text = od.Description; - - //if (od.objecttype == ObjectType.ARRAY || od.objecttype == ObjectType.RECORD) - { - coo.SubNumber = od.Nosubindexes.ToString(); //-1?? //check me - coo.CANopenSubObject = new List(); - - foreach (KeyValuePair kvp2 in od.subobjects) - { - ODentry subod = kvp2.Value; - UInt16 subindex = kvp2.Key; - - Xml2CSharp.CANopenSubObject sub = new Xml2CSharp.CANopenSubObject(); - - sub.Name = subod.parameter_name; - sub.Description = new Xml2CSharp.Description(); - sub.Description.Text = subod.Description; - sub.ObjectType = subod.objecttype.ToString(); - sub.AccessType = subod.accesstype == EDSsharp.AccessType.UNKNOWN ? od.accesstype.ToString() : subod.accesstype.ToString(); - sub.DataType = string.Format("0x{0:x2}", (int)(subod.datatype == DataType.UNKNOWN ? od.datatype : subod.datatype)); - sub.DefaultValue = subod.defaultvalue; - sub.HighValue = subod.HighLimit; - sub.LowValue = subod.LowLimit; - sub.PDOmapping = subod.PDOtype.ToString(); - sub.SubIndex = String.Format("{0:x2}", subindex); - sub.TPDOdetectCOS = (subod.prop.CO_flagsPDO ? subod.prop.CO_flagsPDO : od.prop.CO_flagsPDO).ToString().ToLower(); - coo.CANopenSubObject.Add(sub); - - } - } - - dev.CANopenObjectList.CANopenObject.Add(coo); - } - - } - - - /* DUMMY USAGE */ - - dev.Other = new Xml2CSharp.Other(); - dev.Other.DummyUsage = new Xml2CSharp.DummyUsage(); - dev.Other.DummyUsage.Dummy = new List(); - - Xml2CSharp.Dummy d; - - d = new Xml2CSharp.Dummy(); - d.Entry = eds.du.Dummy0001.ToString(); - dev.Other.DummyUsage.Dummy.Add(d); - d = new Xml2CSharp.Dummy(); - d.Entry = eds.du.Dummy0002.ToString(); - dev.Other.DummyUsage.Dummy.Add(d); - d = new Xml2CSharp.Dummy(); - d.Entry = eds.du.Dummy0003.ToString(); - dev.Other.DummyUsage.Dummy.Add(d); - d = new Xml2CSharp.Dummy(); - d.Entry = eds.du.Dummy0004.ToString(); - dev.Other.DummyUsage.Dummy.Add(d); - d = new Xml2CSharp.Dummy(); - d.Entry = eds.du.Dummy0005.ToString(); - dev.Other.DummyUsage.Dummy.Add(d); - d = new Xml2CSharp.Dummy(); - d.Entry = eds.du.Dummy0006.ToString(); - dev.Other.DummyUsage.Dummy.Add(d); - d = new Xml2CSharp.Dummy(); - d.Entry = eds.du.Dummy0007.ToString(); - dev.Other.DummyUsage.Dummy.Add(d); - - - Xml2CSharp.SupportedBaudRate baud = new Xml2CSharp.SupportedBaudRate(); - dev.Other.Baudrate = new Xml2CSharp.Baudrate(); - dev.Other.Baudrate.SupportedBaudRate = new List(); - - baud.Value = "10 Kbps"; - if (eds.di.BaudRate_10 == true) - dev.Other.Baudrate.SupportedBaudRate.Add(baud); - - baud = new Xml2CSharp.SupportedBaudRate(); - baud.Value = "20 Kbps"; - if (eds.di.BaudRate_20 == true) - dev.Other.Baudrate.SupportedBaudRate.Add(baud); - - baud = new Xml2CSharp.SupportedBaudRate(); - baud.Value = "50 Kbps"; - if (eds.di.BaudRate_50 == true) - dev.Other.Baudrate.SupportedBaudRate.Add(baud); - - baud = new Xml2CSharp.SupportedBaudRate(); - baud.Value = "125 Kbps"; - if (eds.di.BaudRate_125 == true) - dev.Other.Baudrate.SupportedBaudRate.Add(baud); - - baud = new Xml2CSharp.SupportedBaudRate(); - baud.Value = "250 Kbps"; - if (eds.di.BaudRate_250 == true) - dev.Other.Baudrate.SupportedBaudRate.Add(baud); - - baud = new Xml2CSharp.SupportedBaudRate(); - baud.Value = "500 Kbps"; - if (eds.di.BaudRate_500 == true) - dev.Other.Baudrate.SupportedBaudRate.Add(baud); - - baud = new Xml2CSharp.SupportedBaudRate(); - baud.Value = "800 Kbps"; - if (eds.di.BaudRate_800 == true) - dev.Other.Baudrate.SupportedBaudRate.Add(baud); - - baud = new Xml2CSharp.SupportedBaudRate(); - baud.Value = "1000 Kbps"; - if (eds.di.BaudRate_1000 == true) - dev.Other.Baudrate.SupportedBaudRate.Add(baud); - - - dev.Other.Capabilities = new Xml2CSharp.Capabilities(); - dev.Other.Capabilities.CharacteristicsList = new Xml2CSharp.CharacteristicsList(); - dev.Other.Capabilities.CharacteristicsList.Characteristic = new List(); - - - dev.Other.Capabilities.CharacteristicsList.Characteristic.Add(makecharcteristic("SimpleBootUpSlave", eds.di.SimpleBootUpSlave.ToString())); - dev.Other.Capabilities.CharacteristicsList.Characteristic.Add(makecharcteristic("SimpleBootUpMaster", eds.di.SimpleBootUpMaster.ToString())); - dev.Other.Capabilities.CharacteristicsList.Characteristic.Add(makecharcteristic("DynamicChannelsSupported", eds.di.DynamicChannelsSupported.ToString())); - dev.Other.Capabilities.CharacteristicsList.Characteristic.Add(makecharcteristic("CompactPDO", eds.di.CompactPDO.ToString())); - dev.Other.Capabilities.CharacteristicsList.Characteristic.Add(makecharcteristic("GroupMessaging", eds.di.GroupMessaging.ToString())); - dev.Other.Capabilities.CharacteristicsList.Characteristic.Add(makecharcteristic("LSS_Supported", eds.di.LSS_Supported.ToString())); - dev.Other.Capabilities.CharacteristicsList.Characteristic.Add(makecharcteristic("LSS_Master", eds.di.LSS_Master.ToString())); - - dev.Other.Capabilities.CharacteristicsList.Characteristic.Add(makecharcteristic("Granularity", eds.di.Granularity.ToString())); - - dev.Other.DeviceIdentity = new Xml2CSharp.DeviceIdentity(); - dev.Other.DeviceIdentity.ProductName = eds.di.ProductName; - dev.Other.DeviceIdentity.ProductNumber = eds.di.ProductNumber; - dev.Other.DeviceIdentity.ProductText = new Xml2CSharp.ProductText(); - dev.Other.DeviceIdentity.ProductText.Description = new Xml2CSharp.Description(); - dev.Other.DeviceIdentity.ProductText.Description.Text = eds.fi.Description; - - - if (eds.dc.NodeID != 0) - dev.Other.DeviceIdentity.ConcreteNoideId = eds.dc.NodeID.ToString(); - - dev.Other.DeviceIdentity.VendorName = eds.di.VendorName; - dev.Other.DeviceIdentity.VendorNumber = eds.di.VendorNumber; - - dev.Other.File = new File(); - - dev.Other.File.FileName = System.IO.Path.GetFileName(eds.xmlfilename); - - dev.Other.File.FileCreationDate = eds.fi.CreationDateTime.ToString("MM-dd-yyyy"); - dev.Other.File.FileCreationTime = eds.fi.CreationDateTime.ToString("h:mmtt"); - dev.Other.File.FileCreator = eds.fi.CreatedBy; - - dev.Other.File.FileModificationDate = eds.fi.ModificationDateTime.ToString("MM-dd-yyyy"); - dev.Other.File.FileModificationTime = eds.fi.ModificationDateTime.ToString("h:mmtt"); - dev.Other.File.FileModifedBy = eds.fi.ModifiedBy; - - dev.Other.File.FileVersion = eds.fi.FileVersion; - dev.Other.File.FileRevision = eds.fi.FileRevision; - - dev.Other.File.ExportFolder = eds.fi.exportFolder; - dev.Other.File.EdsFile = eds.edsfilename; - //fixme dcffilename - - - return dev; - } - - - public Xml2CSharp.Characteristic makecharcteristic(string name, string content) - { - Xml2CSharp.Characteristic cl = new Xml2CSharp.Characteristic(); - - cl.CharacteristicName = new Xml2CSharp.CharacteristicName(); - cl.CharacteristicContent = new Xml2CSharp.CharacteristicContent(); - cl.CharacteristicContent.Label = new Xml2CSharp.Label(); - cl.CharacteristicName.Label = new Xml2CSharp.Label(); - - cl.CharacteristicName.Label.Text = name; - cl.CharacteristicContent.Label.Text = content; - - return cl; - } - - /// - /// Convert from CanOpenXML to EDSsharp - /// - /// CanOpenXML device - /// EDSsharp object containing data from dev - public EDSsharp convert(Device dev) - { - EDSsharp eds = new EDSsharp(); - - foreach (Xml2CSharp.CANopenObject coo in dev.CANopenObjectList.CANopenObject) - { - ODentry entry = new ODentry(); - entry.Index = Convert.ToUInt16(coo.Index, 16); - entry.parameter_name = coo.Name; - - if (coo.AccessType != null) - { - string at = coo.AccessType; - - Regex reg = new Regex(@"^cons$"); - at = reg.Replace(at, "const"); - - entry.accesstype = (EDSsharp.AccessType)Enum.Parse(typeof(EDSsharp.AccessType), at); - } - - if (coo.DataType != null) - { - byte datatype = Convert.ToByte(coo.DataType, 16); - entry.datatype = (DataType)datatype; - } - else - { - //CANopenNode Project XML did not correctly set DataTypes for record sets - - if (entry.Index == 0x1018) - entry.datatype = DataType.IDENTITY; - - if (entry.Index >= 0x1200 && entry.Index < 0x1400) //check me is this the correct range?? - entry.datatype = DataType.SDO_PARAMETER; - - - if (entry.Index >= 0x1400 && entry.Index < 0x1600) //check me is this the correct range?? - entry.datatype = DataType.PDO_COMMUNICATION_PARAMETER; - - - if (entry.Index >= 0x1600 && entry.Index < 0x1800) //check me is this the correct range?? - entry.datatype = DataType.PDO_MAPPING; - - - if (entry.Index >= 0x1800 && entry.Index < 0x1a00) //check me is this the correct range?? - entry.datatype = DataType.PDO_COMMUNICATION_PARAMETER; - - - if (entry.Index >= 0x1a00 && entry.Index < 0x1c00) //check me is this the correct range?? - entry.datatype = DataType.PDO_MAPPING; - - - } - - //Fix for old CanOpen XML; - if (coo.ObjectType == "REC") - { - coo.ObjectType = "RECORD"; - } - - ObjectType oType; - if(Enum.TryParse(coo.ObjectType, out oType)) - { - //TDO Parsing failed, we should alert the user - } - entry.objecttype = oType; - - entry.defaultvalue = coo.DefaultValue; - entry.HighLimit = coo.HighValue; - entry.LowLimit = coo.LowValue; - //entry.nosubindexes = Convert.ToInt16(coo.SubNumber); - - if (coo.PDOmapping != null) - entry.PDOtype = (PDOMappingType)Enum.Parse(typeof(PDOMappingType), coo.PDOmapping); - else - entry.PDOtype = PDOMappingType.no; - - entry.prop.CO_flagsPDO = coo.TPDOdetectCOS == "true"; - entry.prop.CO_disabled = coo.Disabled == "true"; - - if (coo.Description != null) - entry.Description = coo.Description.Text; //FIXME URL/LANG - - if (coo.Label != null) - entry.Label = coo.Label.Text; //FIXME LANG - - if (coo.MemoryType != null) - { - entry.prop.CO_storageGroup = coo.MemoryType; - eds.CO_storageGroups.Add(coo.MemoryType); - } - - eds.ods.Add(entry.Index, entry); - - if (entry.Index == 0x1000 || entry.Index == 0x1001 || entry.Index == 0x1018) - { - eds.md.objectlist.Add(eds.md.objectlist.Count + 1, entry.Index); - } - else - if (entry.Index >= 0x2000 && entry.Index < 0x6000) - { - eds.mo.objectlist.Add(eds.mo.objectlist.Count + 1, entry.Index); - } - else - { - eds.oo.objectlist.Add(eds.oo.objectlist.Count + 1, entry.Index); - } - - - foreach (Xml2CSharp.CANopenSubObject coosub in coo.CANopenSubObject) - { - - ODentry subentry = new ODentry(); - - subentry.parameter_name = coosub.Name; - subentry.Index = entry.Index; - - if (coosub.AccessType != null) - subentry.accesstype = (EDSsharp.AccessType)Enum.Parse(typeof(EDSsharp.AccessType), coosub.AccessType); - - if (coosub.DataType != null) - { - byte datatype = Convert.ToByte(coosub.DataType, 16); - subentry.datatype = (DataType)datatype; - } - - if (coosub.Description != null) - subentry.Description = coosub.Description.Text; //FIXME URL/LANG - - subentry.defaultvalue = coosub.DefaultValue; - subentry.HighLimit = coosub.HighValue; - subentry.LowLimit = coosub.LowValue; - - byte subindex = Convert.ToByte(coosub.SubIndex, 16); - - if (coosub.PDOmapping != null) - subentry.PDOtype = (PDOMappingType)Enum.Parse(typeof(PDOMappingType), coosub.PDOmapping); - - if (entry.objecttype == ObjectType.ARRAY) - { - subentry.PDOtype = entry.PDOtype; - } - - subentry.prop.CO_storageGroup = entry.prop.CO_storageGroup; - subentry.parent = entry; - - subentry.objecttype = ObjectType.VAR; - - if (coosub.TPDOdetectCOS != null) - { - subentry.prop.CO_flagsPDO = coosub.TPDOdetectCOS == "true"; - } - else - { - if (coo.TPDOdetectCOS != null) - subentry.prop.CO_flagsPDO = coo.TPDOdetectCOS == "true"; - } - - - entry.subobjects.Add(subindex, subentry); - - } - } - - eds.du.Dummy0001 = dev.Other.DummyUsage.Dummy[0].Entry == "Dummy0001=1"; - eds.du.Dummy0002 = dev.Other.DummyUsage.Dummy[1].Entry == "Dummy0002=1"; - eds.du.Dummy0003 = dev.Other.DummyUsage.Dummy[2].Entry == "Dummy0003=1"; - eds.du.Dummy0004 = dev.Other.DummyUsage.Dummy[3].Entry == "Dummy0004=1"; - eds.du.Dummy0005 = dev.Other.DummyUsage.Dummy[4].Entry == "Dummy0005=1"; - eds.du.Dummy0006 = dev.Other.DummyUsage.Dummy[5].Entry == "Dummy0006=1"; - eds.du.Dummy0007 = dev.Other.DummyUsage.Dummy[6].Entry == "Dummy0007=1"; - - foreach (Xml2CSharp.SupportedBaudRate baud in dev.Other.Baudrate.SupportedBaudRate) - { - if (baud.Value == "10 Kbps") - eds.di.BaudRate_10 = true; - if (baud.Value == "20 Kbps") - eds.di.BaudRate_20 = true; - if (baud.Value == "50 Kbps") - eds.di.BaudRate_50 = true; - if (baud.Value == "125 Kbps") - eds.di.BaudRate_125 = true; - if (baud.Value == "250 Kbps") - eds.di.BaudRate_250 = true; - if (baud.Value == "500 Kbps") - eds.di.BaudRate_500 = true; - if (baud.Value == "800 Kbps") - eds.di.BaudRate_800 = true; - if (baud.Value == "1000 Kbps") - eds.di.BaudRate_1000 = true; - - } - - Dictionary keypairs = new Dictionary(); - - if (dev.Other.Capabilities != null) - { - if (dev.Other.Capabilities.CharacteristicsList != null) - { - foreach (Xml2CSharp.Characteristic c in dev.Other.Capabilities.CharacteristicsList.Characteristic) - { - try - { - keypairs.Add(c.CharacteristicName.Label.Text, c.CharacteristicContent.Label.Text); - } - catch (Exception) - { - // Warnings.warning_list.Add("Parsing characteristics failed " + e.ToString()); - } - } - } - } - - - bool boolout; - byte byteout; - - if (keypairs.ContainsKey("SimpleBootUpSlave") && bool.TryParse(keypairs["SimpleBootUpSlave"], out boolout)) - eds.di.SimpleBootUpSlave = boolout; - if (keypairs.ContainsKey("SimpleBootUpMaster") && bool.TryParse(keypairs["SimpleBootUpMaster"], out boolout)) - eds.di.SimpleBootUpMaster = boolout; - if (keypairs.ContainsKey("DynamicChannelsSupported") && bool.TryParse(keypairs["DynamicChannelsSupported"], out boolout)) - eds.di.DynamicChannelsSupported = boolout; - if (keypairs.ContainsKey("CompactPDO") && byte.TryParse(keypairs["CompactPDO"], out byteout)) - eds.di.CompactPDO = byteout; - if (keypairs.ContainsKey("GroupMessaging") && bool.TryParse(keypairs["GroupMessaging"], out boolout)) - eds.di.GroupMessaging = boolout; - if (keypairs.ContainsKey("LSS_Supported") && bool.TryParse(keypairs["LSS_Supported"], out boolout)) - eds.di.LSS_Supported = boolout; - if (keypairs.ContainsKey("LSS_Master") && bool.TryParse(keypairs["LSS_Master"], out boolout)) - eds.di.LSS_Master = boolout; - else if (keypairs.ContainsKey("LSS_Type") && keypairs["LSS_Type"] != null && keypairs["LSS_Type"].ToString() == "Client") - eds.di.LSS_Master = true; - if (keypairs.ContainsKey("Granularity") && byte.TryParse(keypairs["Granularity"], out byteout)) - eds.di.Granularity = byteout; - - eds.di.ProductName = dev.Other.DeviceIdentity.ProductName; - eds.di.ProductNumber = dev.Other.DeviceIdentity.ProductNumber; - - if (dev.Other.DeviceIdentity.ProductText != null && dev.Other.DeviceIdentity.ProductText.Description != null & dev.Other.DeviceIdentity.ProductText.Description.Text != null) - eds.fi.Description = dev.Other.DeviceIdentity.ProductText.Description.Text; - - eds.di.VendorName = dev.Other.DeviceIdentity.VendorName; - eds.di.VendorNumber = dev.Other.DeviceIdentity.VendorNumber; - - if (dev.Other.DeviceIdentity.ConcreteNoideId != null) - { - eds.dc.NodeID = Convert.ToByte(dev.Other.DeviceIdentity.ConcreteNoideId); - } - else - { - eds.dc.NodeID = 0; - } - - string dtcombined; - - eds.fi.FileName = dev.Other.File.FileName; - eds.edsfilename = dev.Other.File.EdsFile; - //fixme dcffilename - - dtcombined = string.Format("{0} {1}", dev.Other.File.FileCreationTime, dev.Other.File.FileCreationDate); - try - { - eds.fi.CreationDateTime = DateTime.ParseExact(dtcombined, "h:mmtt MM-dd-yyyy", CultureInfo.InvariantCulture); - eds.fi.CreationDate = eds.fi.CreationDateTime.ToString("MM-dd-yyyy"); - eds.fi.CreationTime = eds.fi.CreationDateTime.ToString("h:mmtt"); - - } - catch (Exception) { } - - eds.fi.CreatedBy = dev.Other.File.FileCreator; - eds.fi.exportFolder = dev.Other.File.ExportFolder; - - dtcombined = string.Format("{0} {1}", dev.Other.File.FileModificationTime, dev.Other.File.FileModificationDate); - try - { - eds.fi.ModificationDateTime = DateTime.ParseExact(dtcombined, "h:mmtt MM-dd-yyyy", CultureInfo.InvariantCulture); - eds.fi.ModificationDate = eds.fi.ModificationDateTime.ToString("MM-dd-yyyy"); - eds.fi.ModificationTime = eds.fi.ModificationDateTime.ToString("h:mmtt"); - } - catch (Exception) { } - - - - - eds.fi.ModifiedBy = dev.Other.File.FileModifedBy; - - - dev.Other.Capabilities = dev.Other.Capabilities; - - eds.fi.FileVersion = dev.Other.File.FileVersion; - - eds.fi.FileRevision = dev.Other.File.FileRevision; - - eds.fi.EDSVersion = "4.0"; - - //FIX me any other appropriate defaults for eds here?? - - eds.UpdatePDOcount(); - - return eds; - } - - - - } - -} diff --git a/libEDSsharp/CanOpenXML.cs b/libEDSsharp/CanOpenXML.cs deleted file mode 100644 index d80da611..00000000 --- a/libEDSsharp/CanOpenXML.cs +++ /dev/null @@ -1,333 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 - * - * The XML contents of this file are auto generated by XML to C# - - http://www.apache.org/licenses/LICENSE-2.0 - */ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml; -using System.Xml.Serialization; -using Xml2CSharp; -using System.IO; - -namespace libEDSsharp -{ - public class CanOpenXML - { - public Device dev; - public void readXML(string file) - { - - XmlSerializer serializer = new XmlSerializer(typeof(Device)); - StreamReader reader = new StreamReader(file); - dev = (Device)serializer.Deserialize(reader); - reader.Close(); - } - - public void writeXML(string file) - { - - XmlSerializer serializer = new XmlSerializer(typeof(Device)); - StreamWriter writer = new StreamWriter(file); - serializer.Serialize(writer, dev); - writer.Close(); - } - } - - - public class NetworkXML - { - Network network = new Network(); - - public List readXML(string file) - { - XmlSerializer serializer = new XmlSerializer(typeof(Network)); - StreamReader reader = new StreamReader(file); - network = (Network)serializer.Deserialize(reader); - reader.Close(); - return network.devices; - } - - public void writeXML(string file, List enet) - { - - network.devices = new List(); - foreach(EDSsharp e in enet) - { - Bridge b = new Bridge(); - Device d = b.convert(e); - network.devices.Add(d); - } - - XmlSerializer serializer = new XmlSerializer(typeof(Network)); - StreamWriter writer = new StreamWriter(file); - serializer.Serialize(writer, network); - writer.Close(); - } - } -} - -namespace Xml2CSharp -{ - [XmlRoot(ElementName="label")] - public class Label { - [XmlAttribute(AttributeName="lang")] - public string Lang { get; set; } - [XmlText] - public string Text { get; set; } - } - - [XmlRoot(ElementName="description")] - public class Description { - [XmlAttribute(AttributeName="lang")] - public string Lang { get; set; } - [XmlAttribute(AttributeName="URI")] - public string URI { get; set; } - [XmlText] - public string Text { get; set; } - } - - [XmlRoot(ElementName="associatedObject")] - public class AssociatedObject { - [XmlAttribute(AttributeName="index")] - public string Index { get; set; } - [XmlAttribute(AttributeName="indexMax")] - public string IndexMax { get; set; } - [XmlAttribute(AttributeName="indexStep")] - public string IndexStep { get; set; } - } - - [XmlRoot(ElementName="feature")] - public class Feature { - [XmlElement(ElementName="label")] - public Label Label { get; set; } - [XmlElement(ElementName="description")] - public Description Description { get; set; } - [XmlElement(ElementName="associatedObject")] - public List AssociatedObject { get; set; } - [XmlAttribute(AttributeName="name")] - public string Name { get; set; } - [XmlAttribute(AttributeName="value")] - public string Value { get; set; } - } - - [XmlRoot(ElementName="features")] - public class Features { - [XmlElement(ElementName="feature")] - public List Feature { get; set; } - } - - [XmlRoot(ElementName="CANopenObject")] - public class CANopenObject { - [XmlElement(ElementName="label")] - public Label Label { get; set; } - [XmlElement(ElementName="description")] - public Description Description { get; set; } - [XmlAttribute(AttributeName="index")] - public string Index { get; set; } - [XmlAttribute(AttributeName="name")] - public string Name { get; set; } - [XmlAttribute(AttributeName="objectType")] - public string ObjectType { get; set; } - [XmlAttribute(AttributeName="memoryType")] - public string MemoryType { get; set; } - [XmlAttribute(AttributeName="dataType")] - public string DataType { get; set; } - [XmlAttribute(AttributeName="accessType")] - public string AccessType { get; set; } - [XmlAttribute(AttributeName="PDOmapping")] - public string PDOmapping { get; set; } - [XmlAttribute(AttributeName="defaultValue")] - public string DefaultValue { get; set; } - [XmlAttribute(AttributeName = "highValue")] - public string HighValue { get; set; } - [XmlAttribute(AttributeName = "lowValue")] - public string LowValue { get; set; } - [XmlElement(ElementName="CANopenSubObject")] - public List CANopenSubObject { get; set; } - [XmlAttribute(AttributeName="subNumber")] - public string SubNumber { get; set; } - [XmlAttribute(AttributeName="disabled")] - public string Disabled { get; set; } - [XmlAttribute(AttributeName="TPDOdetectCOS")] - public string TPDOdetectCOS { get; set; } - } - - [XmlRoot(ElementName="CANopenSubObject")] - public class CANopenSubObject { - [XmlAttribute(AttributeName="subIndex")] - public string SubIndex { get; set; } - [XmlAttribute(AttributeName="name")] - public string Name { get; set; } - [XmlElement(ElementName = "description")] - public Description Description { get; set; } - [XmlAttribute(AttributeName="objectType")] - public string ObjectType { get; set; } - [XmlAttribute(AttributeName="dataType")] - public string DataType { get; set; } - [XmlAttribute(AttributeName="accessType")] - public string AccessType { get; set; } - [XmlAttribute(AttributeName="PDOmapping")] - public string PDOmapping { get; set; } - [XmlAttribute(AttributeName="defaultValue")] - public string DefaultValue { get; set; } - [XmlAttribute(AttributeName = "highValue")] - public string HighValue { get; set; } - [XmlAttribute(AttributeName = "lowValue")] - public string LowValue { get; set; } - [XmlAttribute(AttributeName = "TPDOdetectCOS")] - public string TPDOdetectCOS { get; set; } - } - - [XmlRoot(ElementName="CANopenObjectList")] - public class CANopenObjectList { - [XmlElement(ElementName="CANopenObject")] - public List CANopenObject { get; set; } - } - - [XmlRoot(ElementName="file")] - public class File { - [XmlAttribute(AttributeName="fileName")] - public string FileName { get; set; } - [XmlAttribute(AttributeName="fileCreator")] - public string FileCreator { get; set; } - [XmlAttribute(AttributeName="fileCreationDate")] - public string FileCreationDate { get; set; } - [XmlAttribute(AttributeName="fileCreationTime")] - public string FileCreationTime { get; set; } - [XmlAttribute(AttributeName = "fileModifedBy")] - public string FileModifedBy { get; set; } - [XmlAttribute(AttributeName = "fileMotifcationDate")] - public string FileModificationDate { get; set; } - [XmlAttribute(AttributeName = "fileModificationTime")] - public string FileModificationTime { get; set; } - [XmlAttribute(AttributeName="fileVersion")] - public string FileVersion { get; set; } - [XmlAttribute(AttributeName = "fileRevision")] - public byte FileRevision { get; set; } - [XmlAttribute(AttributeName = "exportFolder")] - public string ExportFolder { get; set; } - [XmlAttribute(AttributeName = "EdsFile")] - public string EdsFile { get; set; } - - } - - [XmlRoot(ElementName="productText")] - public class ProductText { - [XmlElement(ElementName="label")] - public Label Label { get; set; } - [XmlElement(ElementName="description")] - public Description Description { get; set; } - } - - [XmlRoot(ElementName="DeviceIdentity")] - public class DeviceIdentity { - [XmlElement(ElementName="vendorName")] - public string VendorName { get; set; } - [XmlElement(ElementName = "vendorNumber")] - public string VendorNumber { get; set; } - [XmlElement(ElementName="productName")] - public string ProductName { get; set; } - [XmlElement(ElementName="productNumber")] - public string ProductNumber { get; set; } - [XmlElement(ElementName = "productText")] - public ProductText ProductText { get; set; } - [XmlElement(ElementName = "concreteNoideId")] - public string ConcreteNoideId { get; set; } - } - - [XmlRoot(ElementName="characteristicName")] - public class CharacteristicName { - [XmlElement(ElementName="label")] - public Label Label { get; set; } - } - - [XmlRoot(ElementName="characteristicContent")] - public class CharacteristicContent { - [XmlElement(ElementName="label")] - public Label Label { get; set; } - } - - [XmlRoot(ElementName="characteristic")] - public class Characteristic { - [XmlElement(ElementName="characteristicName")] - public CharacteristicName CharacteristicName { get; set; } - [XmlElement(ElementName="characteristicContent")] - public CharacteristicContent CharacteristicContent { get; set; } - } - - [XmlRoot(ElementName="characteristicsList")] - public class CharacteristicsList { - [XmlElement(ElementName="characteristic")] - public List Characteristic { get; set; } - } - - [XmlRoot(ElementName="capabilities")] - public class Capabilities { - [XmlElement(ElementName="characteristicsList")] - public CharacteristicsList CharacteristicsList { get; set; } - } - - [XmlRoot(ElementName="supportedBaudRate")] - public class SupportedBaudRate { - [XmlAttribute(AttributeName="value")] - public string Value { get; set; } - } - - [XmlRoot(ElementName="baudRate")] - public class Baudrate { - [XmlElement(ElementName="supportedBaudRate")] - public List SupportedBaudRate { get; set; } - } - - [XmlRoot(ElementName="dummy")] - public class Dummy { - [XmlAttribute(AttributeName="entry")] - public string Entry { get; set; } - } - - [XmlRoot(ElementName="dummyUsage")] - public class DummyUsage { - [XmlElement(ElementName="dummy")] - public List Dummy { get; set; } - } - - [XmlRoot(ElementName="other")] - public class Other { - [XmlElement(ElementName="file")] - public File File { get; set; } - [XmlElement(ElementName="DeviceIdentity")] - public DeviceIdentity DeviceIdentity { get; set; } - [XmlElement(ElementName="capabilities")] - public Capabilities Capabilities { get; set; } - [XmlElement(ElementName="baudRate")] - public Baudrate Baudrate { get; set; } - [XmlElement(ElementName="dummyUsage")] - public DummyUsage DummyUsage { get; set; } - } - - [XmlRoot(ElementName="device")] - public class Device { - [XmlElement(ElementName="features")] - public Features Features { get; set; } - [XmlElement(ElementName="CANopenObjectList")] - public CANopenObjectList CANopenObjectList { get; set; } - [XmlElement(ElementName="other")] - public Other Other { get; set; } - } - - [XmlRoot(ElementName = "network")] - public class Network - { - [XmlElement(ElementName = "devices")] - public List devices { get; set; } - } - - -} diff --git a/libEDSsharp/eds.cs b/libEDSsharp/eds.cs index 17cb39e2..929d89dd 100644 --- a/libEDSsharp/eds.cs +++ b/libEDSsharp/eds.cs @@ -28,7 +28,6 @@ You should have received a copy of the GNU General Public License using System.Runtime.Remoting.Messaging; using System.Net.NetworkInformation; using System.Security.Cryptography; -using Xml2CSharp; namespace libEDSsharp {