private void listView_TXCOBmap_MouseClick(object sender, MouseEventArgs e) { if (listView_TXCOBmap.SelectedItems.Count != 1) { return; } UInt16 index = Convert.ToUInt16(listView_TXCOBmap.SelectedItems[0].SubItems[1].Text, 16); UInt32 COB = Convert.ToUInt32(listView_TXCOBmap.SelectedItems[0].SubItems[0].Text, 16); ODentry od = eds.ods[index]; textBox_slot.Text = string.Format("0x{0:x4}", od.index); if (od.containssubindex(1) == true) { textBox_cob.Text = od.getsubobject(1).defaultvalue; } if (od.containssubindex(2) == true) { textBox_type.Text = od.getsubobject(2).defaultvalue; } if (od.containssubindex(3) == true) { textBox_inhibit.Text = od.getsubobject(3).defaultvalue; } if (od.containssubindex(5) == true) { textBox_eventtimer.Text = od.getsubobject(5).defaultvalue; } if (od.containssubindex(6) == true) { textBox_syncstart.Text = od.getsubobject(6).defaultvalue; } if (isTXPDO) { textBox_eventtimer.Enabled = true; textBox_inhibit.Enabled = true; textBox_syncstart.Enabled = true; } textBox_type.Enabled = true; textBox_cob.Enabled = true; button_deletePDO.Enabled = true; button_savepdochanges.Enabled = true; //Is invalid bit set checkBox_invalidpdo.Checked = ((COB & 0x80000000) != 0); }
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 Documementation </h1>")); file.Write("<table id=\"nodelist\">"); write2linetableheader("Node ID", "Name"); foreach (EDSsharp eds in network) { write2linetablerow(eds.di.concreteNodeId.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.di.concreteNodeId, eds.di.ProductName, index, subindex, name, size)); //find all recievers 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.di.concreteNodeId, 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 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); }