Skip to content

Commit 0603ce3

Browse files
First pass work at #48
I think the following now works in both eds and xml Product number Vendor number Description Creation Date/Time Modification Date/Time Modified by New fields in xml have appropriate uint/byte types not string. String was used for compatibility with CanOpen Nodes original OD editor the following caveats exist with date time : In the EDS file the storage format is on two lines one for date and one for time, the format MUST be DS306 format that is time- h:mmtt date- MM-dd-yyyy XML also stores in same format one field for time one for date Internally it is stored as a datetime. When you type and update it uses the DateTime.parse() function so it should support normal local datetime input. It may crash, it attempts to always parse in a try() but we will see
1 parent a760324 commit 0603ce3

File tree

3 files changed

+84
-17
lines changed

3 files changed

+84
-17
lines changed

‎libEDSsharp/Bridge.cs‎

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ You should have received a copy of the GNU General Public License
1919

2020
using System;
2121
using System.Collections.Generic;
22-
using System.Linq;
23-
using System.Text;
24-
using System.Threading.Tasks;
22+
using System.Globalization;
2523
using Xml2CSharp;
2624
using System.Text.RegularExpressions;
2725

@@ -191,24 +189,32 @@ public Device convert(EDSsharp eds)
191189

192190
dev.Other.DeviceIdentity = new DeviceIdentity();
193191
dev.Other.DeviceIdentity.ProductName = eds.di.ProductName;
194-
//dev.Other.DeviceIdentity.ProductText = new ProductText();
195-
//dev.Other.DeviceIdentity.ProductText.Description
192+
dev.Other.DeviceIdentity.ProductNumber = eds.di.ProductNumber;
193+
dev.Other.DeviceIdentity.ProductText = new ProductText();
194+
dev.Other.DeviceIdentity.ProductText.Description = new Description();
195+
dev.Other.DeviceIdentity.ProductText.Description.Text = eds.fi.Description;
196196

197+
197198
if (eds.di.concreteNodeId!=-1)
198199
dev.Other.DeviceIdentity.ConcreteNoideId = eds.di.concreteNodeId.ToString();
199200

200201
dev.Other.DeviceIdentity.VendorName = eds.di.VendorName;
202+
dev.Other.DeviceIdentity.VendorNumber = eds.di.VendorNumber;
201203

202-
//dev.Other.File = new Other.File();
203204
dev.Other.File = new File();
204205

205206
dev.Other.File.FileName = eds.fi.FileName;
206207

207-
dev.Other.File.FileCreationDate = eds.fi.CreationDate;
208-
dev.Other.File.FileCreationTime = eds.fi.CreationTime;
208+
dev.Other.File.FileCreationDate = eds.fi.CreationDateTime.ToString("MM-dd-yyyy");
209+
dev.Other.File.FileCreationTime = eds.fi.CreationDateTime.ToString("h:mmtt");
209210
dev.Other.File.FileCreator = eds.fi.CreatedBy;
210211

212+
dev.Other.File.FileModificationDate = eds.fi.ModificationDateTime.ToString("MM-dd-yyyy");
213+
dev.Other.File.FileModificationTime = eds.fi.ModificationDateTime.ToString("h:mmtt");
214+
dev.Other.File.FileModifedBy = eds.fi.ModifiedBy;
215+
211216
dev.Other.File.FileVersion = eds.fi.FileVersion.ToString();
217+
dev.Other.File.FileRevision = eds.fi.FileRevision;
212218

213219
dev.Other.File.ExportFolder = eds.fi.exportFolder;
214220

@@ -392,8 +398,13 @@ public EDSsharp convert(Device dev)
392398
}
393399

394400
eds.di.ProductName = dev.Other.DeviceIdentity.ProductName;
395-
//dev.Other.DeviceIdentity.ProductText
401+
eds.di.ProductNumber = dev.Other.DeviceIdentity.ProductNumber;
402+
403+
if(dev.Other.DeviceIdentity.ProductText!=null && dev.Other.DeviceIdentity.ProductText.Description!=null & dev.Other.DeviceIdentity.ProductText.Description.Text!=null)
404+
eds.fi.Description = dev.Other.DeviceIdentity.ProductText.Description.Text;
405+
396406
eds.di.VendorName = dev.Other.DeviceIdentity.VendorName;
407+
eds.di.VendorNumber = dev.Other.DeviceIdentity.VendorNumber;
397408

398409
if (dev.Other.DeviceIdentity.ConcreteNoideId != null)
399410
{
@@ -404,12 +415,38 @@ public EDSsharp convert(Device dev)
404415
eds.di.concreteNodeId = -1;
405416
}
406417

418+
string dtcombined;
419+
407420
eds.fi.FileName = dev.Other.File.FileName;
408-
eds.fi.CreationDate = dev.Other.File.FileCreationDate;
409-
eds.fi.CreationTime = dev.Other.File.FileCreationTime;
421+
422+
dtcombined = string.Format("{0} {1}", dev.Other.File.FileCreationTime, dev.Other.File.FileCreationDate);
423+
try
424+
{
425+
eds.fi.CreationDateTime = DateTime.ParseExact(dtcombined, "h:mmtt MM-dd-yyyy", CultureInfo.InvariantCulture);
426+
eds.fi.CreationDate = eds.fi.CreationDateTime.ToString("MM-dd-yyyy");
427+
eds.fi.CreationTime = eds.fi.CreationDateTime.ToString("h:mmtt");
428+
429+
}
430+
catch(Exception e) { }
431+
410432
eds.fi.CreatedBy = dev.Other.File.FileCreator;
411433
eds.fi.exportFolder = dev.Other.File.ExportFolder;
412434

435+
dtcombined = string.Format("{0} {1}", dev.Other.File.FileModificationTime, dev.Other.File.FileModificationDate);
436+
try
437+
{
438+
eds.fi.ModificationDateTime = DateTime.ParseExact(dtcombined, "h:mmtt MM-dd-yyyy", CultureInfo.InvariantCulture);
439+
eds.fi.ModificationDate = eds.fi.ModificationDateTime.ToString("MM-dd-yyyy");
440+
eds.fi.ModificationTime = eds.fi.ModificationDateTime.ToString("h:mmtt");
441+
}
442+
catch (Exception e) { }
443+
444+
445+
446+
447+
eds.fi.ModifiedBy = dev.Other.File.FileModifedBy;
448+
449+
413450
dev.Other.Capabilities = dev.Other.Capabilities;
414451

415452
try
@@ -424,6 +461,8 @@ public EDSsharp convert(Device dev)
424461
eds.fi.FileVersion = 0;
425462
}
426463

464+
eds.fi.FileRevision = dev.Other.File.FileRevision;
465+
427466
eds.fi.EDSVersion = "4.0";
428467

429468
//FIX me any other approprate defaults for eds here??

‎libEDSsharp/CanOpenXML.cs‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,16 @@ public class File {
195195
public string FileCreationDate { get; set; }
196196
[XmlAttribute(AttributeName="fileCreationTime")]
197197
public string FileCreationTime { get; set; }
198-
[XmlAttribute(AttributeName="fileVersion")]
198+
[XmlAttribute(AttributeName = "fileModifedBy")]
199+
public string FileModifedBy { get; set; }
200+
[XmlAttribute(AttributeName = "fileMotifcationDate")]
201+
public string FileModificationDate { get; set; }
202+
[XmlAttribute(AttributeName = "fileModificationTime")]
203+
public string FileModificationTime { get; set; }
204+
[XmlAttribute(AttributeName="fileVersion")]
199205
public string FileVersion { get; set; }
206+
[XmlAttribute(AttributeName = "fileRevision")]
207+
public byte FileRevision { get; set; }
200208
[XmlAttribute(AttributeName = "exportFolder")]
201209
public string ExportFolder { get; set; }
202210

@@ -214,10 +222,14 @@ public class ProductText {
214222
public class DeviceIdentity {
215223
[XmlElement(ElementName="vendorName")]
216224
public string VendorName { get; set; }
217-
[XmlElement(ElementName="productName")]
225+
[XmlElement(ElementName = "vendorNumber")]
226+
public uint VendorNumber { get; set; }
227+
[XmlElement(ElementName="productName")]
218228
public string ProductName { get; set; }
219-
[XmlElement(ElementName="productText")]
220-
public ProductText ProductText { get; set; }
229+
[XmlElement(ElementName="productNumber")]
230+
public uint ProductNumber { get; set; }
231+
[XmlElement(ElementName = "productText")]
232+
public ProductText ProductText { get; set; }
221233
[XmlElement(ElementName = "concreteNoideId")]
222234
public string ConcreteNoideId { get; set; }
223235
}

‎libEDSsharp/eds.cs‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,14 @@ public class FileInfo : InfoSection
480480

481481
[EdsExport]
482482
public string CreatedBy = "";//=CANFestival //max245
483-
483+
484484
public DateTime ModificationDateTime;//
485+
485486
[EdsExport]
486487
public string ModificationTime="";
487488
[EdsExport]
488489
public string ModificationDate="";
490+
489491
[EdsExport]
490492
public string ModifiedBy="";//=CANFestival //max244
491493

@@ -1019,7 +1021,6 @@ public EDSsharp()
10191021
fi.FileVersion = 1;
10201022
fi.FileRevision = 1;
10211023

1022-
//FixMe too need a extra function to sort the data out;
10231024
fi.CreationDateTime = DateTime.Now;
10241025
fi.ModificationDateTime = DateTime.Now;
10251026

@@ -1208,6 +1209,7 @@ public void loadfile(string filename)
12081209
if (eds.ContainsKey("Comments"))
12091210
c.parse(eds["Comments"]);
12101211

1212+
12111213
updatePDOcount();
12121214
}
12131215
// catch(Exception e)
@@ -1222,6 +1224,20 @@ public void savefile(string filename)
12221224

12231225
updatePDOcount();
12241226

1227+
//generate date times in DS306 format; h:mmtt MM-dd-yyyy
1228+
1229+
fi.CreationDate = fi.CreationDateTime.ToString("MM-dd-yyyy");
1230+
fi.CreationTime = fi.CreationDateTime.ToString("h:mmtt");
1231+
1232+
fi.ModificationDate = fi.ModificationDateTime.ToString("MM-dd-yyyy");
1233+
fi.ModificationTime = fi.ModificationDateTime.ToString("h:mmtt");
1234+
1235+
fi.FileName = filename;
1236+
1237+
fi.EDSVersion = "4.0";
1238+
fi.EDSVersionMajor = 4;
1239+
fi.EDSVersionMinor = 0;
1240+
12251241
StreamWriter writer = File.CreateText(filename);
12261242
fi.write(writer);
12271243
di.write(writer);

0 commit comments

Comments
 (0)