Skip to content

Commit

Permalink
First pass work at #48
Browse files Browse the repository at this point in the history
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
  • Loading branch information
robincornelius committed Jan 31, 2017
1 parent a760324 commit 0603ce3
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 17 deletions.
61 changes: 50 additions & 11 deletions libEDSsharp/Bridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ You should have received a copy of the GNU General Public License

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using Xml2CSharp;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -191,24 +189,32 @@ public Device convert(EDSsharp eds)

dev.Other.DeviceIdentity = new DeviceIdentity();
dev.Other.DeviceIdentity.ProductName = eds.di.ProductName;
//dev.Other.DeviceIdentity.ProductText = new ProductText();
//dev.Other.DeviceIdentity.ProductText.Description
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 Other.File();
dev.Other.File = new File();

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

dev.Other.File.FileCreationDate = eds.fi.CreationDate;
dev.Other.File.FileCreationTime = eds.fi.CreationTime;
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;

Expand Down Expand Up @@ -392,8 +398,13 @@ public EDSsharp convert(Device dev)
}

eds.di.ProductName = dev.Other.DeviceIdentity.ProductName;
//dev.Other.DeviceIdentity.ProductText
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)
{
Expand All @@ -404,12 +415,38 @@ public EDSsharp convert(Device dev)
eds.di.concreteNodeId = -1;
}

string dtcombined;

eds.fi.FileName = dev.Other.File.FileName;
eds.fi.CreationDate = dev.Other.File.FileCreationDate;
eds.fi.CreationTime = dev.Other.File.FileCreationTime;

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
Expand All @@ -424,6 +461,8 @@ public EDSsharp convert(Device dev)
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??
Expand Down
20 changes: 16 additions & 4 deletions libEDSsharp/CanOpenXML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,16 @@ public class File {
public string FileCreationDate { get; set; }
[XmlAttribute(AttributeName="fileCreationTime")]
public string FileCreationTime { get; set; }
[XmlAttribute(AttributeName="fileVersion")]
[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; }

Expand All @@ -214,10 +222,14 @@ public class ProductText {
public class DeviceIdentity {
[XmlElement(ElementName="vendorName")]
public string VendorName { get; set; }
[XmlElement(ElementName="productName")]
[XmlElement(ElementName = "vendorNumber")]
public uint VendorNumber { get; set; }
[XmlElement(ElementName="productName")]
public string ProductName { get; set; }
[XmlElement(ElementName="productText")]
public ProductText ProductText { get; set; }
[XmlElement(ElementName="productNumber")]
public uint ProductNumber { get; set; }
[XmlElement(ElementName = "productText")]
public ProductText ProductText { get; set; }
[XmlElement(ElementName = "concreteNoideId")]
public string ConcreteNoideId { get; set; }
}
Expand Down
20 changes: 18 additions & 2 deletions libEDSsharp/eds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,14 @@ public class FileInfo : InfoSection

[EdsExport]
public string CreatedBy = "";//=CANFestival //max245

public DateTime ModificationDateTime;//

[EdsExport]
public string ModificationTime="";
[EdsExport]
public string ModificationDate="";

[EdsExport]
public string ModifiedBy="";//=CANFestival //max244

Expand Down Expand Up @@ -1019,7 +1021,6 @@ public EDSsharp()
fi.FileVersion = 1;
fi.FileRevision = 1;

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

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


updatePDOcount();
}
// catch(Exception e)
Expand All @@ -1222,6 +1224,20 @@ public void savefile(string filename)

updatePDOcount();

//generate date times in DS306 format; h:mmtt MM-dd-yyyy

fi.CreationDate = fi.CreationDateTime.ToString("MM-dd-yyyy");
fi.CreationTime = fi.CreationDateTime.ToString("h:mmtt");

fi.ModificationDate = fi.ModificationDateTime.ToString("MM-dd-yyyy");
fi.ModificationTime = fi.ModificationDateTime.ToString("h:mmtt");

fi.FileName = filename;

fi.EDSVersion = "4.0";
fi.EDSVersionMajor = 4;
fi.EDSVersionMinor = 0;

StreamWriter writer = File.CreateText(filename);
fi.write(writer);
di.write(writer);
Expand Down

0 comments on commit 0603ce3

Please sign in to comment.