Skip to content

Commit ee64f26

Browse files
Attempt to fix #33
Please ensure you backup your xml/eds files before running this the first few times Add save eds+xml+export option that will do all three operations to a single Device Move the filenames for xml and eds into separate variables to aid exporting and also be more user friendly when exporting by hand Also save the network filename/path so that is not dependent on the last save
1 parent 764267c commit ee64f26

File tree

3 files changed

+115
-26
lines changed

3 files changed

+115
-26
lines changed

‎EDSTest/Form1.Designer.cs‎

Lines changed: 37 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎EDSTest/Form1.cs‎

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public partial class ODEditor_MainForm : Form
4141
private List<string> _mru = new List<string>();
4242
private string appdatafolder;
4343

44+
private string networkfilename;
45+
4446
public static Dictionary<UInt16, EDSsharp> TXCobMap = new Dictionary<UInt16, EDSsharp>();
4547
List<EDSsharp> network = new List<EDSsharp>();
4648

@@ -165,7 +167,6 @@ private void exportCanOpenNodeToolStripMenuItem_Click(object sender, EventArgs e
165167
SaveFileDialog sfd = new SaveFileDialog();
166168
sfd.CheckFileExists = false;
167169

168-
169170
sfd.FileName = "CO_OD.c";
170171
sfd.InitialDirectory = dv.eds.fi.exportFolder;
171172
sfd.RestoreDirectory = true;
@@ -222,7 +223,7 @@ private void openXMLfile(string path)
222223
Bridge b = new Bridge();
223224

224225
eds = b.convert(coxml.dev);
225-
eds.filename = path;
226+
eds.xmlfilename = path;
226227

227228
dev = coxml.dev;
228229

@@ -315,9 +316,9 @@ private void saveEDSToolStripMenuItem_Click(object sender, EventArgs e)
315316

316317
sfd.Filter = "Electronic Data Sheets (*.eds)|*.eds";
317318

318-
sfd.InitialDirectory = Path.GetDirectoryName(dv.eds.filename);
319+
sfd.InitialDirectory = Path.GetDirectoryName(dv.eds.edsfilename);
319320
sfd.RestoreDirectory = true;
320-
sfd.FileName = Path.GetFileNameWithoutExtension(dv.eds.filename);
321+
sfd.FileName = Path.GetFileNameWithoutExtension(dv.eds.edsfilename);
321322

322323
if (sfd.ShowDialog() == DialogResult.OK)
323324
{
@@ -336,9 +337,9 @@ private void saveProjectXMLToolStripMenuItem_Click(object sender, EventArgs e)
336337

337338
sfd.Filter = "Canopen Node XML (*.xml)|*.xml";
338339

339-
sfd.InitialDirectory = Path.GetDirectoryName(dv.eds.filename);
340+
sfd.InitialDirectory = Path.GetDirectoryName(dv.eds.xmlfilename);
340341
sfd.RestoreDirectory = true;
341-
sfd.FileName = Path.GetFileNameWithoutExtension(dv.eds.filename);
342+
sfd.FileName = Path.GetFileNameWithoutExtension(dv.eds.xmlfilename);
342343

343344
if (sfd.ShowDialog() == DialogResult.OK)
344345
{
@@ -394,6 +395,7 @@ private void enablesavemenus(bool enable)
394395
saveNetworkXmlToolStripMenuItem.Enabled = enable;
395396
documentationToolStripMenuItem.Enabled = enable;
396397
networkPDOToolStripMenuItem.Enabled = enable;
398+
saveExportAllToolStripMenuItem.Enabled = enable;
397399

398400
}
399401

@@ -492,6 +494,9 @@ private void saveNetworkXmlToolStripMenuItem_Click(object sender, EventArgs e)
492494

493495
sfd.Filter = "CanOpen network XML (*.nxml)|*.nxml";
494496

497+
sfd.InitialDirectory = Path.GetDirectoryName(networkfilename);
498+
sfd.RestoreDirectory = true;
499+
sfd.FileName = Path.GetFileNameWithoutExtension(networkfilename);
495500

496501
if (sfd.ShowDialog() == DialogResult.OK)
497502
{
@@ -543,6 +548,8 @@ private void openNetworkfile(string file)
543548

544549
addtoMRU(file);
545550
}
551+
552+
networkfilename = file;
546553
}
547554

548555
private void networkPDOToolStripMenuItem_Click(object sender, EventArgs e)
@@ -590,6 +597,65 @@ private void documentationToolStripMenuItem_Click(object sender, EventArgs e)
590597
{
591598
WarningsFrm frm = new WarningsFrm();
592599
frm.ShowDialog();
600+
}
601+
}
602+
603+
private void saveExportAllToolStripMenuItem_Click(object sender, EventArgs e)
604+
{
605+
//Attempt to save EDS,XML and export the CanOpen dictionary
606+
607+
if (tabControl1.SelectedTab != null)
608+
{
609+
DeviceView dv = (DeviceView)tabControl1.SelectedTab.Controls[0];
610+
SaveFileDialog sfd = new SaveFileDialog();
611+
612+
//save eds xml and export CO_OD.c and CO_OD.h
613+
614+
if (dv.eds.edsfilename == null || dv.eds.edsfilename == "")
615+
{
616+
MessageBox.Show("Please manually save as EDS at least once");
617+
return;
618+
}
619+
620+
if (dv.eds.xmlfilename == null || dv.eds.xmlfilename == "")
621+
{
622+
MessageBox.Show("Please manually save as XML at least once");
623+
return;
624+
}
625+
626+
if (dv.eds.fi.exportFolder == null || dv.eds.fi.exportFolder == "")
627+
{
628+
MessageBox.Show("Please expot CO_OD.c/h at least once");
629+
return;
630+
}
631+
632+
//export XML
633+
Bridge b = new Bridge();
634+
Device d = b.convert(dv.eds);
635+
636+
CanOpenXML coxml = new CanOpenXML();
637+
coxml.dev = d;
638+
639+
coxml.writeXML(dv.eds.xmlfilename);
640+
641+
642+
//export EDS
643+
dv.eds.savefile(dv.eds.edsfilename);
644+
645+
//export CO_OD.c and CO_OD.h
646+
CanOpenNodeExporter cone = new CanOpenNodeExporter();
647+
cone.export(dv.eds.fi.exportFolder, dv.eds);
648+
649+
if (Warnings.warning_list.Count != 0)
650+
{
651+
WarningsFrm frm = new WarningsFrm();
652+
frm.ShowDialog();
653+
}
654+
655+
656+
657+
658+
593659
}
594660
}
595661
}

‎libEDSsharp/eds.cs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,10 @@ public class FileInfo : InfoSection
489489
[EdsExport]
490490
public string ModifiedBy="";//=CANFestival //max244
491491

492+
//Folder CO_OD.c and CO_OD.h will be exported into
492493
public string exportFolder = "";
493494

495+
494496
public FileInfo(Dictionary<string, string> section)
495497
{
496498
infoheader = "CAN OPEN FileInfo";
@@ -956,7 +958,8 @@ public enum AccessType
956958

957959
//This is the last file name used for this eds/xml file and is not
958960
//the same as filename within the FileInfo structure.
959-
public string filename;
961+
public string edsfilename = null;
962+
public string xmlfilename = null;
960963

961964
Dictionary<string, Dictionary<string, string>> eds;
962965
public SortedDictionary<UInt16, ODentry> ods;
@@ -1159,7 +1162,7 @@ public void parseEDSentry(KeyValuePair<string, Dictionary<string, string>> kvp)
11591162
public void loadfile(string filename)
11601163
{
11611164

1162-
this.filename = filename;
1165+
edsfilename = filename;
11631166
//try
11641167
{
11651168
foreach (string linex in File.ReadLines(filename))
@@ -1190,7 +1193,7 @@ public void loadfile(string filename)
11901193

11911194
public void savefile(string filename)
11921195
{
1193-
this.filename = filename;
1196+
this.edsfilename = filename;
11941197

11951198
updatePDOcount();
11961199

0 commit comments

Comments
 (0)