public NewIndex(EDSsharp eds, DataType dt = DataType.UNKNOWN, ObjectType ot = ObjectType.UNKNOWN, ODentry parent = null) { this.eds = eds; InitializeComponent(); foreach (DataType foo in Enum.GetValues(typeof(DataType))) { comboBox_datatype.Items.Add(foo.ToString()); } if (ot == ObjectType.REC) { radioButton_array.Enabled = false; radioButton_rec.Enabled = false; radioButton_var.Enabled = false; numericUpDown_index.Enabled = false; numericUpDown_subindexes.Enabled = false; //order of next two matters radioButton_rec.Checked = true; comboBox_datatype.Enabled = true; childaddition = true; numericUpDown_index.Value = parent.Index; Text = "Create new sub index"; } DialogResult = DialogResult.Cancel; }
public void TestArrays() { ODentry od = new ODentry { objecttype = ObjectType.ARRAY, datatype = DataType.VISIBLE_STRING, parameter_name = "Test Array", accesstype = EDSsharp.AccessType.ro, Index = 0x2000 }; eds = new EDSsharp { ods = new System.Collections.Generic.SortedDictionary <ushort, ODentry>() }; eds.ods.Add(0x2000, od); prewalkArrays(); od.subobjects.Add(0x00, new ODentry("No Entries", 0x00, DataType.UNSIGNED8, "4", EDSsharp.AccessType.ro, PDOMappingType.no)); od.subobjects.Add(0x01, new ODentry("LINE1", 0x01, DataType.VISIBLE_STRING, new string('*', 1), EDSsharp.AccessType.ro, PDOMappingType.optional)); od.subobjects.Add(0x02, new ODentry("LINE1", 0x02, DataType.VISIBLE_STRING, new string('*', 10), EDSsharp.AccessType.ro, PDOMappingType.optional)); od.subobjects.Add(0x03, new ODentry("LINE1", 0x03, DataType.VISIBLE_STRING, new string('*', 16), EDSsharp.AccessType.ro, PDOMappingType.optional)); od.subobjects.Add(0x04, new ODentry("LINE1", 0x04, DataType.VISIBLE_STRING, new string('*', 32), EDSsharp.AccessType.ro, PDOMappingType.optional)); string test = print_h_entry(od); if (test != "/*2000 */ VISIBLE_STRING testArray[32][4];" + Environment.NewLine) { throw (new Exception("TestArrays() test 1 failed")); } }
private void addSubItemToolStripMenuItem_Click(object sender, EventArgs e) { if (selecteditemsub.Tag != null) { ODentry od = (ODentry)selecteditemsub.Tag; if (od.parent != null) { od = od.parent; } if (od.objecttype == ObjectType.ARRAY) { ODentry newsub = new ODentry(); newsub.parent = od; newsub.datatype = od.datatype; newsub.accesstype = od.accesstype; newsub.PDOtype = od.PDOtype; newsub.index = od.index; newsub.objecttype = ObjectType.VAR; newsub.subindex = (UInt16)od.subobjects.Count; od.subobjects.Add((UInt16)(od.subobjects.Count), newsub); UInt16 def = EDSsharp.ConvertToUInt16(od.subobjects[0].defaultvalue); def++; od.subobjects[0].defaultvalue = def.ToString(); } if (od.objecttype == ObjectType.REC) { DataType dt = od.datatype; NewIndex ni = new NewIndex(eds, dt, od.objecttype, od); if (ni.ShowDialog() == DialogResult.OK) { ODentry newsub = new ODentry(); newsub.parent = od; newsub.datatype = ni.dt; newsub.accesstype = od.accesstype; newsub.PDOtype = od.PDOtype; newsub.index = od.index; newsub.objecttype = ObjectType.VAR; newsub.subindex = (UInt16)od.subobjects.Count; newsub.parameter_name = ni.name; od.subobjects.Add((UInt16)(od.subobjects.Count), newsub); UInt16 def = EDSsharp.ConvertToUInt16(od.subobjects[0].defaultvalue); def++; od.subobjects[0].defaultvalue = def.ToString(); } } eds.dirty = true; updateselectedindexdisplay(selectedobject.index); validateanddisplaydata(); } }
private void openNetworkfile(string file) { NetworkXML net = new NetworkXML(); List <Device> devs = net.readXML(file); foreach (Device d in devs) { Bridge b = new Bridge(); EDSsharp eds = b.convert(d); //eds.filename = path; //fixme tabControl1.TabPages.Add(eds.di.ProductName); DeviceView device = new DeviceView(); device.eds = eds; tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(device); device.Dock = DockStyle.Fill; network.Add(eds); eds.onDataDirty += Eds_onDataDirty; device.dispatch_updateOD(); addtoMRU(file); } networkfilename = file; }
// Dictionary<DataType, defstruct> defstructs = new Dictionary<DataType, defstruct>(); public void export(string folderpath, EDSsharp eds) { this.folderpath = folderpath; this.eds = eds; foreach (KeyValuePair <UInt16, ODentry> kvp in eds.ods) { if (kvp.Value.Disabled == false) { enabledcount++; } } countPDOS(); export_h(); export_c(); }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { EDSsharp eds = new EDSsharp(); eds.di.ProductName = "New Product"; tabControl1.TabPages.Add(eds.di.ProductName); DeviceView device = new DeviceView(); device.eds = eds; eds.onDataDirty += Eds_onDataDirty; tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(device); device.Dock = DockStyle.Fill; device.dispatch_updateOD(); }
private void Eds_onDataDirty(bool dirty, EDSsharp sender) { foreach (TabPage page in tabControl1.TabPages) { foreach (Control c in page.Controls) { if (c.GetType() == typeof(DeviceView)) { DeviceView d = (DeviceView)c; if (d.eds.dirty == true) { page.BackColor = Color.Red; } else { page.BackColor = default(Color); } } } } }
private void removeSubItemleaveGapToolStripMenuItem_Click(object sender, EventArgs e) { if (selecteditemsub.Tag != null) { ODentry od = (ODentry)selecteditemsub.Tag; if (od.parent.objecttype == ObjectType.ARRAY || od.parent.objecttype == ObjectType.REC) { UInt16 count = EDSsharp.ConvertToUInt16(od.parent.subobjects[0].defaultvalue); if (count > 0) { count--; } od.parent.subobjects[0].defaultvalue = count.ToString(); } bool success = od.parent.subobjects.Remove(od.Subindex); /* * UInt16 countx = 0; * * SortedDictionary<UInt16, ODentry> newlist = new SortedDictionary<ushort, ODentry>(); * * foreach (KeyValuePair<UInt16, ODentry> kvp in od.parent.subobjects) * { * ODentry sub = kvp.Value; * newlist.Add(countx, sub); * countx++; * } * * od.parent.subobjects = newlist; */ eds.Dirty = true; updateselectedindexdisplay(selectedobject.Index, currentmodule); validateanddisplaydata(); } }
private void openEDSfile(string path) { Warnings.warning_list.Clear(); 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.onDataDirty += Eds_onDataDirty; device.eds = eds; tabControl1.TabPages.Add(eds.di.ProductName); 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.ShowDialog(); } }
private void removeSubItemToolStripMenuItem_Click(object sender, EventArgs e) { if (selecteditemsub.Tag != null) { ODentry od = (ODentry)selecteditemsub.Tag; if (od.parent.objecttype == ObjectType.ARRAY) { UInt16 count = EDSsharp.ConvertToUInt16(od.parent.subobjects[0].defaultvalue); if (count > 0) { count--; } od.parent.subobjects[0].defaultvalue = count.ToString(); } bool success = od.parent.subobjects.Remove(od.subindex); UInt16 countx = 0; SortedDictionary <UInt16, ODentry> newlist = new SortedDictionary <ushort, ODentry>(); foreach (KeyValuePair <UInt16, ODentry> kvp in od.parent.subobjects) { ODentry sub = kvp.Value; sub.subindex = countx; newlist.Add(countx, sub); countx++; } od.parent.subobjects = newlist; eds.dirty = true; updateselectedindexdisplay(selectedobject.index); validateanddisplaydata(); } }
private void PrintPdo(ushort start, ushort end, string caption, EDSsharp eds) { file.WriteLine("## {0}", caption); file.WriteLine(); foreach (var kvp in eds.ods) { ODentry od = kvp.Value; int index = kvp.Key; if (od.Disabled) { continue; } if (od.Index >= start && od.Index < end) { file.WriteLine(string.Format("### {0} {1:x4}", caption, od.Index)); file.WriteLine(); byte current_bit = 0; foreach (var kvp2 in od.subobjects) { ODentry odsub = kvp2.Value; ushort subindex = kvp2.Key; if (subindex == 0) { continue; } var data = Convert.ToUInt32(odsub.defaultvalue, EDSsharp.Getbase(odsub.defaultvalue)); if (data != 0) { byte datasize = (byte)(data & 0x000000FF); ushort pdoindex = (ushort)((data >> 16) & 0x0000FFFF); byte pdosub = (byte)((data >> 8) & 0x000000FF); file.Write($"* Byte{current_bit / 8}: "); if (eds.ods.ContainsKey(pdoindex) && (pdosub == 0 || eds.ods[pdoindex].Containssubindex(pdosub))) { ODentry maptarget; if (pdosub == 0) { maptarget = eds.ods[pdoindex]; } else { maptarget = eds.ods[pdoindex].Getsubobject(pdosub); } if (!maptarget.Disabled && datasize == (8 * maptarget.Sizeofdatatype())) { if (maptarget.parent == null) { file.Write(string.Format("[0x{0:x4} - {1}]", maptarget.Index, maptarget.parameter_name)); } else { file.Write(string.Format("[0x{0:x4} sub 0x{1:x2} - {2}]", maptarget.Index, maptarget.Subindex, maptarget.parameter_name)); } } } file.WriteLine(); var by = (datasize / 8); for (int i = 1; i < by; ++i) { file.WriteLine($"* Byte{current_bit / 8 + i}: -\"-"); } current_bit += datasize; } } for (int i = (current_bit / 8); i < 8; ++i) { file.WriteLine($"* Byte{i}: empty"); } file.WriteLine(); } } }
public void TestArrayNoEntries() { eds = new EDSsharp { ods = new System.Collections.Generic.SortedDictionary <ushort, ODentry>() }; ODentry od = new ODentry { objecttype = ObjectType.ARRAY, datatype = DataType.VISIBLE_STRING, parameter_name = "Test Array", accesstype = EDSsharp.AccessType.ro, Index = 0x1011 }; eds.ods.Add(0x1011, od); od.subobjects.Add(0x00, new ODentry("No Entries", 0x00, DataType.UNSIGNED8, "0x7f", EDSsharp.AccessType.ro, PDOMappingType.no)); od.subobjects.Add(0x01, new ODentry("LINE1", 0x01, DataType.UNSIGNED32, "0x01", EDSsharp.AccessType.ro, PDOMappingType.optional)); string test = write_od_line(od); if (test != "{0x1011, 0x7f, 0x06, 0, (void*)&CO_OD_RAM.testArray[0]}," + Environment.NewLine) { throw (new Exception("TestArrayNoEntries() failed")); } od = new ODentry { objecttype = ObjectType.ARRAY, datatype = DataType.VISIBLE_STRING, parameter_name = "Test Array", accesstype = EDSsharp.AccessType.ro, Index = 0x2000 }; eds.ods.Add(0x2000, od); od.subobjects.Add(0x00, new ODentry("No Entries", 0x00, DataType.UNSIGNED8, "0x7f", EDSsharp.AccessType.ro, PDOMappingType.no)); od.subobjects.Add(0x01, new ODentry("LINE1", 0x01, DataType.UNSIGNED32, "0x01", EDSsharp.AccessType.ro, PDOMappingType.optional)); test = write_od_line(od); if (test != "{0x2000, 0x7f, 0x06, 0, (void*)&CO_OD_RAM.testArray[0]}," + Environment.NewLine) { throw (new Exception("TestArrayNoEntries() failed")); } od = new ODentry { objecttype = ObjectType.ARRAY, datatype = DataType.VISIBLE_STRING, parameter_name = "Test Array", accesstype = EDSsharp.AccessType.ro, Index = 0x1003 }; eds.ods.Add(0x1003, od); od.subobjects.Add(0x00, new ODentry("No Entries", 0x00, DataType.UNSIGNED8, "0x00", EDSsharp.AccessType.ro, PDOMappingType.no)); od.subobjects.Add(0x01, new ODentry("LINE1", 0x01, DataType.UNSIGNED32, "0x01", EDSsharp.AccessType.ro, PDOMappingType.optional)); od.subobjects.Add(0x02, new ODentry("LINE1", 0x02, DataType.UNSIGNED32, "0x01", EDSsharp.AccessType.ro, PDOMappingType.optional)); od.subobjects.Add(0x03, new ODentry("LINE1", 0x03, DataType.UNSIGNED32, "0x01", EDSsharp.AccessType.ro, PDOMappingType.optional)); test = write_od_line(od); if (test != "{0x1003, 0x03, 0x06, 0, (void*)&CO_OD_RAM.testArray[0]}," + Environment.NewLine) { throw (new Exception("TestArrayNoEntries() failed")); } }
public void gennetpdodoc(string filepath, List <EDSsharp> network) { file = new StreamWriter(filepath, false); file.Write("<!DOCTYPE html><html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" /> <title>Network PDO report</title></head><body>"); file.Write(string.Format("<h1>PDO Network Documentation </h1>")); file.Write("<table id=\"nodelist\">"); write2linetableheader("Node ID", "Name"); foreach (EDSsharp eds in network) { write2linetablerow(eds.dc.NodeId.ToString(), eds.di.ProductName); } file.Write("</table>"); file.Write(string.Format("<h1>PDO Map</h1>")); //now for each node find each TX PDO foreach (EDSsharp eds in network) { foreach (KeyValuePair <UInt16, ODentry> kvp in eds.ods) { //find the com params for each TX pdo if (kvp.Key >= 0x1800 && kvp.Key < 0x1a00) { //check the mapping also exists if (eds.ods.ContainsKey((UInt16)(kvp.Key + 0x200))) { ODentry map = eds.ods[(UInt16)(kvp.Key + 0x200)]; ODentry compar = eds.ods[(UInt16)(kvp.Key)]; //Fix me we need some generic PDO access functions UInt32 TXCOB = 0; byte syncstart = 0; UInt16 timer = 0; UInt16 inhibit = 0; byte type = 0; bool nodeidpresent; if (kvp.Value.Containssubindex(1)) { TXCOB = eds.GetNodeID(kvp.Value.Getsubobject(1).defaultvalue, out nodeidpresent); } if (kvp.Value.Containssubindex(2)) { type = EDSsharp.ConvertToByte(kvp.Value.Getsubobject(2).defaultvalue); } if (kvp.Value.Containssubindex(3)) { inhibit = EDSsharp.ConvertToUInt16(kvp.Value.Getsubobject(3).defaultvalue); } if (kvp.Value.Containssubindex(5)) { timer = EDSsharp.ConvertToUInt16(kvp.Value.Getsubobject(5).defaultvalue); } if (kvp.Value.Containssubindex(6)) { syncstart = EDSsharp.ConvertToByte(kvp.Value.Getsubobject(6).defaultvalue); } byte totalsize = 0; for (UInt16 sub = 1; sub <= map.Getmaxsubindex(); sub++) { if (!map.Containssubindex(sub)) { continue; } UInt32 mapping = EDSsharp.ConvertToUInt32(map.Getsubobject(sub).defaultvalue); if (mapping == 0) { continue; } Byte size = (byte)mapping; totalsize += size; } if (totalsize != 0) { file.Write(string.Format("<h2> PDO 0x{0:x3} <h2>", TXCOB)); file.Write("<table><tr> <th>Parameter</th> <th>value</th> </tr>"); file.Write(string.Format("<tr><td>{0}</td><td>0x{1:x3}</td></tr>", "COB", TXCOB)); file.Write(string.Format("<tr><td>{0}</td><td>0x{1:x}</td></tr>", "Type", type)); file.Write(string.Format("<tr><td>{0}</td><td>0x{1:x} ({2})</td></tr>", "Inhibit", inhibit, inhibit)); file.Write(string.Format("<tr><td>{0}</td><td>0x{1:x} ({2})</td></tr>", "Event timer", timer, timer)); file.Write(string.Format("<tr><td>{0}</td><td>0x{1:x} ({2})</td></tr>", "Sync start", syncstart, syncstart)); file.Write(string.Format("<tr><td>{0}</td><td>0x{1:x}</td></tr>", "PDO Size (Bytes)", totalsize / 8)); file.Write("<table class=\"pdomap\">"); file.Write(string.Format("<tr><th>{0}</th><th>{1}</th><th>{2}</th><th>{3}</th><th>{4}</th><th>{5}</th></tr>", "Node", "Dev name", "OD Index", "Name", "Size", "Receivers")); } byte offsetend = 0; byte offsetstart = 0; for (UInt16 sub = 1; sub <= map.Getmaxsubindex(); sub++) { if (!map.Containssubindex(sub)) { continue; } if (map.Getsubobjectdefaultvalue(sub) == "") { continue; } UInt32 mapping = EDSsharp.ConvertToUInt32(map.Getsubobjectdefaultvalue(sub)); if (mapping == 0) { continue; } //its real extract the OD and sub index UInt16 index = (UInt16)(mapping >> 16); UInt16 subindex = (UInt16)(0x00FF & (mapping >> 8)); Byte size = (byte)mapping; String name; if (!eds.ods.ContainsKey(index)) { break; } if (subindex == 0) { name = eds.ods[index].parameter_name; } else { name = eds.ods[index].Getsubobject(subindex).parameter_name; } file.Write(string.Format("<tr> <td>0x{0:x2}</td> <td>{1}</td> <td>0x{2:x4}/0x{3:x2}</td><td>{4}</td> <td>{5}</td><td>", eds.dc.NodeId, eds.di.ProductName, index, subindex, name, size)); //find all receivers here file.Write("<table class=\"receivers\">"); file.Write(string.Format("<tr> <th>Node</th> <th>Dev Name</th> <th>OD Index</th> <th>Name</th> <th>Size</td></tr>")); offsetend += (byte)(size / 8); foreach (EDSsharp eds2 in network) { if (eds == eds2) { continue; } else { foreach (KeyValuePair <UInt16, ODentry> kvp2 in eds2.ods) { if (kvp2.Key >= 0x1400 && kvp2.Key < 0x1600) { if (eds2.ods.ContainsKey((UInt16)(kvp2.Key + 0x200))) { bool nodeidpresent2; UInt32 RXCOB = eds2.GetNodeID(kvp2.Value.Getsubobjectdefaultvalue(1), out nodeidpresent2); if (RXCOB == TXCOB) { ODentry map2 = eds2.ods[(UInt16)(kvp2.Key + 0x200)]; //Get the actual subindex to use byte offsetstart2 = 0; byte offsetend2 = 0; Byte size2 = 0; UInt32 mapping2 = 0; UInt16 index2 = 0; UInt16 subindex2 = 0; byte totalsize2 = 0; //Sanity check the total size for (byte sub2 = 1; sub2 <= map2.Getmaxsubindex(); sub2++) { mapping2 = EDSsharp.ConvertToUInt32(map2.Getsubobjectdefaultvalue(sub2)); size2 = (byte)(mapping2); totalsize2 += size2; } if (totalsize2 != totalsize) { file.WriteLine("<B> Critical error with network RX PDO size != TX PDO SIZE"); } for (byte sub2 = 1; sub2 <= map2.Getmaxsubindex(); sub2++) { mapping2 = EDSsharp.ConvertToUInt32(map2.Getsubobjectdefaultvalue(sub2)); index2 = (UInt16)(mapping2 >> 16); subindex2 = (UInt16)(0x00FF & (mapping2 >> 8)); size2 = (byte)mapping2; if (mapping2 == 0) { continue; } offsetend2 += (byte)(size2 / 8); // if(offsetstart == offsetstart2 && offsetend == offsetend2) //we are all good equal data 1:1 mapping if (offsetstart2 < offsetstart) { //more data needed to reach start offsetstart2 += (byte)(size2 / 8); continue; } if (offsetend2 > offsetend && offsetstart2 > offsetstart) { break; //we are done } offsetstart2 += (byte)(size2 / 8); if (offsetend2 > offsetend) { //merge cell required on parent table //meh difficult to do from here } String name2; if (subindex2 == 0) { //fixme getobject could return null name2 = eds2.Getobject(index2).parameter_name; } else { //fixme getobject could return null name2 = eds2.Getobject(index2).Getsubobject(subindex2).parameter_name; } string sizemsg = ""; if (size != size2) { sizemsg = " <b>WARNING</b>"; } file.Write(string.Format("<tr> <td>0x{0:x2}</td> <td>{1}</td> <td>0x{2:x4}/0x{3:x2}</td> <td>{4}</td><td>{5}{6}</td></tr>", eds2.dc.NodeId, eds2.di.ProductName, index2, subindex2, name2, size2, sizemsg)); } } } } } } } offsetstart += (byte)(size / 8); file.Write("</table>"); file.Write("</td>"); file.Write(string.Format("</tr>")); } } file.Write("</table>"); } } } file.Close(); }
public void Test_CompactSubObj() { string testobject = @"[1003] ParameterName=Pre-defined error field ObjectType=0x8 DataType=0x0007 AccessType=rw CompactSubObj=9 "; injectobject(testobject); if (!ods.ContainsKey(0x1003)) { throw (new Exception("parseEDSentry() failed no object")); } ODentry od = ods[0x1003]; if (od.subobjects.Count != 10) { throw (new Exception("parseEDSentry() CompactSubObj failed to generate children")); } ODentry sub = od.Getsubobject(0); if (sub.parameter_name != "NrOfObjects") { throw (new Exception("parseEDSentry() CompactSubObj incorrect generation")); } if (sub.datatype != DataType.UNSIGNED8) { throw (new Exception("parseEDSentry() CompactSubObj incorrect generation")); } if (sub.accesstype != AccessType.ro) { throw (new Exception("parseEDSentry() CompactSubObj incorrect generation")); } UInt16 defaultvalue = EDSsharp.ConvertToByte(sub.defaultvalue); if (defaultvalue != 9) { throw (new Exception("parseEDSentry() CompactSubObj incorrect generation")); } if (sub.PDOtype != PDOMappingType.no) { throw (new Exception("parseEDSentry() CompactSubObj incorrect generation")); } for (UInt16 x = 1; x < 10; x++) { if (!od.Containssubindex(x)) { throw (new Exception("parseEDSentry() CompactSubObj incorrect generation")); } sub = od.Getsubobject(x); string name = string.Format("{0}{1:00}", od.parameter_name, x); if (sub.parameter_name != name) { throw (new Exception("parseEDSentry() CompactSubObj incorrect generation")); } if (sub.datatype != DataType.UNSIGNED32) { throw (new Exception("parseEDSentry() CompactSubObj incorrect generation")); } if (sub.accesstype != AccessType.rw) { throw (new Exception("parseEDSentry() CompactSubObj incorrect generation")); } } }
void updatePDOTXslot(ODentry od, int row) { UInt16 idx = (UInt16)(od.index + 0x200); if (!eds.ods.ContainsKey(idx)) { return; } ODentry oddef = eds.ods[idx]; int byteoff = 0; foreach (KeyValuePair <UInt16, ODentry> kvp in oddef.subobjects) { if (byteoff >= 8) { continue; } ODentry sub = kvp.Value; if (sub.subindex == 0) { continue; } UInt32 data = 0; if (sub.defaultvalue != "") { data = Convert.ToUInt32(sub.defaultvalue, EDSsharp.getbase(sub.defaultvalue)); } if (data == 0) { listView_TXCOBmap.AddComboBoxCell(row, byteoff + 2, TXchoices); listView_TXCOBmap.Items[row].SubItems[byteoff + 2].Text = "empty"; byteoff++; continue; } //format is 0x6000 01 08 byte datasize = (byte)(data & 0x000000FF); UInt16 pdoindex = (UInt16)((data >> 16) & 0x0000FFFF); byte pdosub = (byte)((data >> 8) & 0x000000FF); //sanity check the real OD against the mapping parameters section bool mappingfail = true; if (eds.ods.ContainsKey(pdoindex) && (pdosub == 0 || eds.ods[pdoindex].containssubindex(pdosub))) { ODentry maptarget; if (pdosub == 0) { maptarget = eds.ods[pdoindex]; } else { maptarget = eds.ods[pdoindex].getsubobject(pdosub); } if (maptarget.Disabled == false && datasize == (8 * maptarget.sizeofdatatype())) { mappingfail = false; } if (mappingfail == true) { MessageBox.Show(String.Format("PDO mapping failed for object 0x{0:x4}/{1:x2}\nplease manaully check the PDO mapping in the TX and RX PDO tabs\n as it does not agree with the mapping paramater 0x{2:x4}/{3:x2}\nThis can occur if you edit objects that are already mapped", pdoindex, pdosub, idx, sub.subindex)); } } String target = ""; int PDOdatasize = 0; //dummy objects if (pdoindex >= 0x0002 && pdoindex <= 0x007) { //the dummy objects switch (pdoindex) { case 0x002: target = "0x0002/00/Dummy Int8"; PDOdatasize = 1; break; case 0x003: target = "0x0003/00/Dummy Int16"; PDOdatasize = 2; break; case 0x004: target = "0x0004/00/Dummy Int32"; PDOdatasize = 4; break; case 0x005: target = "0x0005/00/Dummy UInt8"; PDOdatasize = 1; break; case 0x006: target = "0x0006/00/Dummy UInt16"; PDOdatasize = 2; break; case 0x007: target = "0x0007/00/Dummy UInt32"; PDOdatasize = 4; break; } if (PDOdatasize == 0) { continue; } } else { //fixme sanity checking here please if (!eds.ods.ContainsKey(pdoindex)) { continue; } ODentry targetod = eds.ods[pdoindex]; if (pdosub != 0) { //FIXME direct sub array access, unprotected and will fault with holes in range targetod = targetod.subobjects[pdosub]; } target = String.Format("0x{0:x4}/{1:x2}/", targetod.index, targetod.subindex) + targetod.parameter_name; PDOdatasize = targetod.sizeofdatatype(); } listView_TXCOBmap.AddComboBoxCell(row, byteoff + 2, TXchoices); listView_TXCOBmap.Items[row].SubItems[byteoff + 2].Text = target; int oldPDOdatasize = PDOdatasize; while (oldPDOdatasize != 1) { listView_TXCOBmap.Items[row].SubItems[byteoff + oldPDOdatasize + 1].Text = " - "; oldPDOdatasize--; } byteoff += PDOdatasize; } }
public EDSsharp convert(Device dev) { EDSsharp eds = new EDSsharp(); foreach (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; } } entry.objecttype = (ObjectType)Enum.Parse(typeof(ObjectType), coo.ObjectType); entry.defaultvalue = coo.DefaultValue; //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.TPDODetectCos = coo.TPDOdetectCOS == "true"; entry.AccessFunctionName = coo.AccessFunctionName; entry.AccessFunctionPreCode = coo.AccessFunctionPreCode; entry.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.location = (StorageLocation)Enum.Parse(typeof(StorageLocation), 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 (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; } subentry.defaultvalue = coosub.DefaultValue; subentry.subindex = Convert.ToUInt16(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.location = entry.location; subentry.parent = entry; subentry.objecttype = ObjectType.VAR; if (coosub.TPDOdetectCOS != null) { subentry.TPDODetectCos = coosub.TPDOdetectCOS == "true"; } else { if (coo.TPDOdetectCOS != null) { subentry.TPDODetectCos = coo.TPDOdetectCOS == "true"; } } entry.subobjects.Add(subentry.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 (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 <string, string> keypairs = new Dictionary <string, string>(); if (dev.Other.Capabilities != null) { if (dev.Other.Capabilities.CharacteristicsList != null) { foreach (Characteristic c in dev.Other.Capabilities.CharacteristicsList.Characteristic) { try { keypairs.Add(c.CharacteristicName.Label.Text, c.CharacteristicContent.Label.Text); } catch (Exception e) { // Warnings.warning_list.Add("Parsing characteristics failed " + e.ToString()); } } } } bool boolout; 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") && bool.TryParse(keypairs["CompactPDO"], out boolout)) { eds.di.CompactPDO = boolout; } 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_Type")) { eds.di.LSS_Type = keypairs["LSS_Type"].ToString(); } byte byteout; 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.di.concreteNodeId = Convert.ToByte(dev.Other.DeviceIdentity.ConcreteNoideId); } else { eds.di.concreteNodeId = -1; } string dtcombined; eds.fi.FileName = dev.Other.File.FileName; eds.edsfilename = dev.Other.File.EdsFile; 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 e) { } 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 e) { } eds.fi.ModifiedBy = dev.Other.File.FileModifedBy; dev.Other.Capabilities = dev.Other.Capabilities; try { eds.fi.FileVersion = Convert.ToByte(dev.Other.File.FileVersion); } catch (Exception e) { if (dev.Other.File != null) { // CanOpenNode default project.xml conatins - for fileversion, its suspose to be a byte field according to DS306 if (dev.Other.File.FileVersion == "-") { dev.Other.File.FileVersion = "0"; } else { Warnings.warning_list.Add(String.Format("Unable to parse FileVersion\"{0}\" {1}", dev.Other.File.FileVersion, e.ToString())); } } eds.fi.FileVersion = 0; } eds.fi.FileRevision = dev.Other.File.FileRevision; eds.fi.EDSVersion = "4.0"; //FIX me any other approprate defaults for eds here?? eds.updatePDOcount(); return(eds); }
public Device convert(EDSsharp eds) { eds.updatePDOcount(); Device dev = new Device(); dev.CANopenObjectList = new CANopenObjectList(); dev.CANopenObjectList.CANopenObject = new List <CANopenObject>(); /* OBJECT DICTIONARY */ foreach (KeyValuePair <UInt16, ODentry> kvp in eds.ods) { ODentry od = kvp.Value; // if(od.subindex==-1) { CANopenObject coo = new CANopenObject(); coo.Index = string.Format("{0:x4}", od.index); coo.Name = od.parameter_name; coo.ObjectType = od.objecttype.ToString(); coo.Disabled = od.Disabled.ToString().ToLower(); coo.MemoryType = od.location.ToString(); coo.AccessType = od.accesstype.ToString(); coo.DataType = string.Format("0x{0:x2}", (int)od.datatype); coo.DefaultValue = od.defaultvalue; coo.PDOmapping = od.PDOtype.ToString(); coo.TPDOdetectCOS = od.TPDODetectCos.ToString().ToLower(); coo.AccessFunctionPreCode = od.AccessFunctionPreCode; coo.AccessFunctionName = od.AccessFunctionName; coo.Description = new Description(); coo.Description.Text = od.Description; //if (od.objecttype == ObjectType.ARRAY || od.objecttype == ObjectType.REC) { coo.SubNumber = od.nosubindexes.ToString(); //-1?? //check me coo.CANopenSubObject = new List <CANopenSubObject>(); foreach (KeyValuePair <UInt16, ODentry> kvp2 in od.subobjects) { ODentry subod = kvp2.Value; CANopenSubObject sub = new CANopenSubObject(); sub.Name = subod.parameter_name; sub.ObjectType = subod.objecttype.ToString(); sub.AccessType = subod.accesstype.ToString(); sub.DataType = string.Format("0x{0:x2}", (int)subod.datatype); sub.DefaultValue = subod.defaultvalue; sub.PDOmapping = subod.PDOtype.ToString(); sub.SubIndex = String.Format("{0:x2}", subod.subindex); sub.TPDOdetectCOS = subod.TPDODetectCos.ToString().ToLower(); coo.CANopenSubObject.Add(sub); } } 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; } } dev.CANopenObjectList.CANopenObject.Add(coo); } } /* DUMMY USAGE */ dev.Other = new Other(); dev.Other.DummyUsage = new DummyUsage(); dev.Other.DummyUsage.Dummy = new List <Dummy>(); Dummy d; d = new Dummy(); d.Entry = eds.du.Dummy0001.ToString(); dev.Other.DummyUsage.Dummy.Add(d); d = new Dummy(); d.Entry = eds.du.Dummy0002.ToString(); dev.Other.DummyUsage.Dummy.Add(d); d = new Dummy(); d.Entry = eds.du.Dummy0003.ToString(); dev.Other.DummyUsage.Dummy.Add(d); d = new Dummy(); d.Entry = eds.du.Dummy0004.ToString(); dev.Other.DummyUsage.Dummy.Add(d); d = new Dummy(); d.Entry = eds.du.Dummy0005.ToString(); dev.Other.DummyUsage.Dummy.Add(d); d = new Dummy(); d.Entry = eds.du.Dummy0006.ToString(); dev.Other.DummyUsage.Dummy.Add(d); d = new Dummy(); d.Entry = eds.du.Dummy0007.ToString(); dev.Other.DummyUsage.Dummy.Add(d); SupportedBaudRate baud = new SupportedBaudRate(); dev.Other.BaudRate = new BaudRate(); dev.Other.BaudRate.SupportedBaudRate = new List <SupportedBaudRate>(); baud.Value = "10 Kbps"; if (eds.di.BaudRate_10 == true) { dev.Other.BaudRate.SupportedBaudRate.Add(baud); } baud = new SupportedBaudRate(); baud.Value = "20 Kbps"; if (eds.di.BaudRate_20 == true) { dev.Other.BaudRate.SupportedBaudRate.Add(baud); } baud = new SupportedBaudRate(); baud.Value = "50 Kbps"; if (eds.di.BaudRate_50 == true) { dev.Other.BaudRate.SupportedBaudRate.Add(baud); } baud = new SupportedBaudRate(); baud.Value = "125 Kbps"; if (eds.di.BaudRate_125 == true) { dev.Other.BaudRate.SupportedBaudRate.Add(baud); } baud = new SupportedBaudRate(); baud.Value = "250 Kbps"; if (eds.di.BaudRate_250 == true) { dev.Other.BaudRate.SupportedBaudRate.Add(baud); } baud = new SupportedBaudRate(); baud.Value = "500 Kbps"; if (eds.di.BaudRate_500 == true) { dev.Other.BaudRate.SupportedBaudRate.Add(baud); } baud = new SupportedBaudRate(); baud.Value = "800 Kbps"; if (eds.di.BaudRate_800 == true) { dev.Other.BaudRate.SupportedBaudRate.Add(baud); } baud = new SupportedBaudRate(); baud.Value = "1000 Kbps"; if (eds.di.BaudRate_1000 == true) { dev.Other.BaudRate.SupportedBaudRate.Add(baud); } dev.Other.Capabilities = new Capabilities(); dev.Other.Capabilities.CharacteristicsList = new CharacteristicsList(); dev.Other.Capabilities.CharacteristicsList.Characteristic = new List <Characteristic>(); 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_Type", eds.di.LSS_Type)); dev.Other.Capabilities.CharacteristicsList.Characteristic.Add(makecharcteristic("Granularity", eds.di.Granularity.ToString())); dev.Other.DeviceIdentity = new DeviceIdentity(); dev.Other.DeviceIdentity.ProductName = eds.di.ProductName; dev.Other.DeviceIdentity.ProductNumber = eds.di.ProductNumber; dev.Other.DeviceIdentity.ProductText = new ProductText(); dev.Other.DeviceIdentity.ProductText.Description = new Description(); dev.Other.DeviceIdentity.ProductText.Description.Text = eds.fi.Description; if (eds.di.concreteNodeId != -1) { dev.Other.DeviceIdentity.ConcreteNoideId = eds.di.concreteNodeId.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.ToString(); dev.Other.File.FileRevision = eds.fi.FileRevision; dev.Other.File.ExportFolder = eds.fi.exportFolder; dev.Other.File.EdsFile = eds.edsfilename; return(dev); }
public void genmddoc(string filepath, EDSsharp eds) { file = new StreamWriter(filepath, false); file.WriteLine(); file.WriteLine("# Device Information"); file.WriteLine(); file.WriteLine("Product name"); file.WriteLine($" ~ {eds.di.ProductName}"); file.WriteLine(); file.WriteLine("Product number"); file.WriteLine($" ~ {eds.di.ProductNumber}"); file.WriteLine(); file.WriteLine("Revision number"); file.WriteLine($" ~ {eds.di.RevisionNumber}"); file.WriteLine(); file.WriteLine("Vendor name"); file.WriteLine($" ~ {eds.di.VendorName}"); file.WriteLine(); file.WriteLine($"Granularity: {eds.di.Granularity}"); file.WriteLine(); file.WriteLine("Supported Baudrates:"); file.WriteLine(); file.WriteLine($"- [{(eds.di.BaudRate_1000 ? "x" : " ")}] 1000 kBit/s"); file.WriteLine($"- [{(eds.di.BaudRate_800 ? "x" : " ")}] 800 kBit/s"); file.WriteLine($"- [{(eds.di.BaudRate_500 ? "x" : " ")}] 500 kBit/s"); file.WriteLine($"- [{(eds.di.BaudRate_250 ? "x" : " ")}] 250 kBit/s"); file.WriteLine($"- [{(eds.di.BaudRate_125 ? "x" : " ")}] 125 kBit/s"); //file.WriteLine($"- [{(true ? "x" : " ")}] 100 kBit/s"); file.WriteLine($"- [{(eds.di.BaudRate_50 ? "x" : " ")}] 50 kBit/s"); file.WriteLine($"- [{(eds.di.BaudRate_20 ? "x" : " ")}] 20 kBit/s"); file.WriteLine($"- [{(eds.di.BaudRate_10 ? "x" : " ")}] 10 kBit/s"); file.WriteLine(); file.WriteLine("# PDO Mapping"); file.WriteLine(); PrintPdo(0x1600, 0x1800, "RPDO", eds); PrintPdo(0x1a00, 0x1c00, "TPDO", eds); file.WriteLine("# Mandatory objects"); file.WriteLine(); foreach (KeyValuePair <UInt16, ODentry> kvp in eds.ods) { ODentry od = kvp.Value; if (od.Disabled == true) { continue; } if (od.Index == 0x1000 || od.Index == 0x1001 || od.Index == 0x1018) { writeODentrymd(od); } } file.WriteLine("# Optional objects"); file.WriteLine(); foreach (KeyValuePair <UInt16, ODentry> kvp in eds.ods) { ODentry od = kvp.Value; if (od.Disabled == true) { continue; } if ((od.Index > 0x1001 && od.Index != 0x1018 && od.Index < 0x2000) || od.Index >= 0x6000) { writeODentrymd(od); } } file.WriteLine("# Manufacturer specific objects"); file.WriteLine(); foreach (KeyValuePair <UInt16, ODentry> kvp in eds.ods) { ODentry od = kvp.Value; if (od.Disabled == true) { continue; } if (od.Index >= 0x2000 && od.Index < 0x6000) { writeODentrymd(od); } } file.Close(); }
private void loadeds(string filename) { if (filename == null || filename == "") { return; } bool isdcf = false; switch (Path.GetExtension(filename).ToLower()) { case ".xml": { CanOpenXML coxml = new CanOpenXML(); coxml.readXML(filename); Bridge b = new Bridge(); eds = b.convert(coxml.dev); eds.xmlfilename = filename; } break; case ".dcf": { isdcf = true; eds = new EDSsharp(); eds.Loadfile(filename); } break; case ".eds": { eds = new EDSsharp(); eds.Loadfile(filename); } break; } textBox_edsfilename.Text = eds.di.ProductName; //if (eds.di.concreteNodeId >= numericUpDown_node.Minimum && eds.di.concreteNodeId <= numericUpDown_node.Maximum) // numericUpDown_node.Value = eds.di.concreteNodeId; listView1.BeginUpdate(); if (!isdcf) { listView1.Items.Clear(); } // StorageLocation loc = StorageLocation foreach (ODentry tod in eds.ods.Values) { if (comboBoxtype.SelectedItem.ToString() != "ALL") { if (comboBoxtype.SelectedItem.ToString() == "EEPROM" && (tod.StorageLocation.ToUpper() != "EEPROM")) { continue; } if (comboBoxtype.SelectedItem.ToString() == "ROM" && (tod.StorageLocation.ToUpper() != "ROM")) { continue; } if (comboBoxtype.SelectedItem.ToString() == "RAM" && (tod.StorageLocation.ToUpper() != "RAM")) { continue; } } if (tod.Disabled == true) { continue; } if (tod.Index < 0x2000 && checkBox_useronly.Checked == true) { continue; } if (tod.objecttype == ObjectType.ARRAY || tod.objecttype == ObjectType.REC) { foreach (ODentry subod in tod.subobjects.Values) { if (subod.Subindex == 0) { continue; } addtolist(subod, isdcf); } continue; } addtolist(tod, isdcf); } listView1.EndUpdate(); this.filename = filename; addtoMRU(filename); }
public void genhtmldoc(string filepath, EDSsharp eds) { file = new StreamWriter(filepath, false); file.Write("<!DOCTYPE html><html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" /></head><body>"); file.Write(string.Format("<h1> {0} Documementation </h1>", eds.di.ProductName)); file.Write("<h2>Device Information</h2>"); file.Write("<table id=\"deviceinfo\">"); write2linetableheader("Product name", eds.di.ProductName); write2linetableheader("Product number", eds.di.ProductNumber); write2linetableheader("Revision number", eds.di.RevisionNumber); write2linetableheader("Vendor name", eds.di.VendorName); file.Write("</table>"); file.Write("<h2>Mandatory objects</h2>"); foreach (KeyValuePair <UInt16, ODentry> kvp in eds.ods) { ODentry od = kvp.Value; if (od.Disabled == true) { continue; } if (od.index == 0x1000 || od.index == 0x1001 || od.index == 0x1018) { writeODentryhtml(od); } } file.Write("<h2>Optional objects</h2>"); foreach (KeyValuePair <UInt16, ODentry> kvp in eds.ods) { ODentry od = kvp.Value; if (od.Disabled == true) { continue; } if ((od.index > 0x1001 && od.index != 0x1018 && od.index < 0x2000) || od.index >= 0x6000) { writeODentryhtml(od); } } file.Write("<h2>Manufacturer specific objects</h2>"); foreach (KeyValuePair <UInt16, ODentry> kvp in eds.ods) { ODentry od = kvp.Value; if (od.Disabled == true) { continue; } if (od.index >= 0x2000 && od.index < 0x6000) { writeODentryhtml(od); } } file.Write("</body></html>"); file.Close(); }