Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions EDSEditorGUI/DeviceInfoView.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions EDSEditorGUI/DeviceInfoView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ You should have received a copy of the GNU General Public License
using System.IO;
using System.Runtime.CompilerServices;
using System.Drawing;

namespace ODEditor

{
public partial class DeviceInfoView : MyTabUserControl
{
Expand All @@ -41,11 +41,13 @@ public void populatedeviceinfo()
return;

textBox_productname.Text = eds.di.ProductName;
textBox_productnumber.Text = eds.di.ProductNumber;
textBox_productnumber.Text = eds.di.ProductNumber.ToHexString();
textBox_vendorname.Text = eds.di.VendorName;
textBox_vendornumber.Text = eds.di.VendorNumber;
textBox_vendornumber.Text = eds.di.VendorNumber.ToHexString();
textBox_revisionnumber.Text = eds.di.RevisionNumber.ToHexString();
textBox_ordercode.Text = eds.di.OrderCode;

textBox_fileversion.Text = eds.fi.FileVersion;
textBox_fileversion.Text = eds.fi.fileVersionString;
textBox_di_description.Text = eds.fi.Description;
textBox_create_datetime.Text = eds.fi.CreationDateTime.ToString();
textBox_createdby.Text = eds.fi.CreatedBy;
Expand Down Expand Up @@ -137,11 +139,13 @@ private void update_devfile_info()
try
{
eds.di.ProductName = textBox_productname.Text;
eds.di.ProductNumber = textBox_productnumber.Text;
eds.di.ProductNumber = EDSsharp.U32Parse(textBox_productnumber.Text);
eds.di.VendorName = textBox_vendorname.Text;
eds.di.VendorNumber = textBox_vendornumber.Text;
eds.di.VendorNumber = EDSsharp.U32Parse(textBox_vendornumber.Text);
eds.di.RevisionNumber = EDSsharp.U32Parse(textBox_revisionnumber.Text);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, what is the reason that some are hex and some are not?
For instance i would imagine revision would be non-hex.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is so that we don't have to use one format and potentially make the code incompatible with some files. I have not found clear info about the format of each field so I opted to make the code more flexible.
The revision number actually consists of 2 16-bit values, see definition of 0x1018.3 in CiA 301. So having it in Hex is more natural to easily split the 2 values.

eds.di.OrderCode = textBox_ordercode.Text;

eds.fi.FileVersion = textBox_fileversion.Text;
eds.fi.fileVersionString = textBox_fileversion.Text;
eds.fi.Description = textBox_di_description.Text;
eds.fi.CreationDateTime = DateTime.Parse(textBox_create_datetime.Text);
eds.fi.CreatedBy = textBox_createdby.Text;
Expand Down
7 changes: 4 additions & 3 deletions Tests/EDSMappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ public void Test_ToProtobufferFileInfo()
CreationDate = "01-20-2000",
CreationTime = "12:20am",
Description = "Description",
FileVersion = (byte)'X',
FileRevision = (byte)'A',
FileVersion = "1.0.0",
fileVersionString = "1.0.0",
ModificationDate = "02-10-1000",
ModificationTime = "12:20pm",
ModifiedBy = "ModifiedBy"
Expand All @@ -68,7 +69,7 @@ public void Test_ToProtobufferFileInfo()
Assert.Equal(eds.fi.CreatedBy, tmp.FileInfo.CreatedBy);
Assert.Equal(creationTimestamp, tmp.FileInfo.CreationTime);
Assert.Equal(eds.fi.Description, tmp.FileInfo.Description);
Assert.Equal(eds.fi.FileVersion, tmp.FileInfo.FileVersion);
Assert.Equal(eds.fi.fileVersionString, tmp.FileInfo.FileVersion);
Assert.Equal(eds.fi.ModifiedBy, tmp.FileInfo.ModifiedBy);
Assert.Equal(modificationTimestamp, tmp.FileInfo.ModificationTime);
}
Expand Down Expand Up @@ -371,7 +372,7 @@ public void Test_FromProtobufferFileInfo()
Assert.Equal(d.FileInfo.CreationTime.ToDateTime().ToString("h:mmtt"), tmp.fi.CreationTime);
Assert.Equal(d.FileInfo.CreationTime.ToDateTime().ToString("MM-dd-yyyy"), tmp.fi.CreationDate);
Assert.Equal(d.FileInfo.Description, tmp.fi.Description);
Assert.Equal(d.FileInfo.FileVersion, tmp.fi.FileVersion);
Assert.Equal(d.FileInfo.FileVersion, tmp.fi.fileVersionString);
Assert.Equal(d.FileInfo.ModifiedBy, tmp.fi.ModifiedBy);
Assert.Equal(d.FileInfo.ModificationTime.ToDateTime().ToString("h:mmtt"), tmp.fi.ModificationTime);
Assert.Equal(d.FileInfo.ModificationTime.ToDateTime().ToString("MM-dd-yyyy"), tmp.fi.ModificationDate);
Expand Down
60 changes: 59 additions & 1 deletion libEDSsharp/CanOpenEDS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public void Write(StreamWriter writer, Filetype ft)
{
writer.WriteLine(string.Format("{2}{0}={1}", f.Name, ((bool)f.GetValue(this)) == true ? 1 : 0, comment == true ? ";" : ""));
}
else if (f.FieldType.Name == "UInt32")
{
writer.WriteLine(string.Format("{2}{0}={1}", f.Name, string.Format("0x{0:x8}", f.GetValue(this)), comment == true ? ";" : ""));
}
else
{
writer.WriteLine(string.Format("{2}{0}={1}", f.Name, f.GetValue(this).ToString(), comment == true ? ";" : ""));
Expand Down Expand Up @@ -1020,6 +1024,27 @@ void ApplycompactPDO(UInt16 index)
}
}
}
public static UInt32 U32Parse(string str)
{
if (str[0] == '0')
{
if (str[1] == 'x' || str[1] == 'X')
{
// Hex format
return System.Convert.ToUInt32(str, 16);
}
else
{
// Octal format
return System.Convert.ToUInt32(str, 8);
}
}
else
{
// Decimal format
return System.Convert.ToUInt32(str);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

octal is not supported, it should have leading 0 without x after
image

Copy link
Author

@GRoussos GRoussos Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, though I think octal is not supported in general in the project. In any case, I've updated the function to also support Octal format.

}
}

/// <summary>
/// This function scans the PDO list and compares it to NrOfRXPDO and NrOfTXPDO
Expand Down Expand Up @@ -1059,7 +1084,38 @@ protected void ApplyimplicitPDO()
}
UpdatePDOcount();
}

private void GetEDSFileInfo()
{
string[] nums = fi.fileVersionString.Split('.');
if (nums.Length == 2)
{
if (byte.TryParse(nums[0], out fi.FileVersion) == false)
{
fi.FileVersion = 1;
Warnings.warning_list.Add("EDS FileVersion cannot be extracted from string \"" + nums[0] +"\", set to 1");
}
if (byte.TryParse(nums[1], out fi.FileRevision) == false)
{
fi.FileRevision = 0;
Warnings.warning_list.Add("EDS FileRevision cannot be extracted from string \"" + nums[1] + "\", set to 0");
}
}
else if (nums.Length == 1)
{
if (byte.TryParse(nums[0], out fi.FileVersion) == false)
{
fi.FileVersion = 1;
Warnings.warning_list.Add("EDS FileVersion cannot be extracted from string \"" + nums[0] + "\", set to 1");
}
fi.FileRevision = 0;
}
else
{
fi.FileVersion = 1;
fi.FileRevision = 0;
Warnings.warning_list.Add("EDS FileVersion and FileRevision cannot be extracted from string \"" + fi.fileVersionString + "\", set to 1.0");
}
}
public void Savefile(string filename, InfoSection.Filetype ft)
{
if (ft == InfoSection.Filetype.File_EDS)
Expand Down Expand Up @@ -1087,6 +1143,8 @@ public void Savefile(string filename, InfoSection.Filetype ft)
fi.EDSVersionMajor = 4;
fi.EDSVersionMinor = 0;

GetEDSFileInfo();

StreamWriter writer = System.IO.File.CreateText(filename);
writer.NewLine = "\n";
fi.Write(writer, ft);
Expand Down
6 changes: 3 additions & 3 deletions libEDSsharp/CanOpenNodeExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ CANopen DATA TYPES
file.WriteLine("/*******************************************************************************");
file.WriteLine(" FILE INFO:");
file.WriteLine(string.Format(" FileName: {0}", Path.GetFileName(eds.projectFilename)));
file.WriteLine(string.Format(" FileVersion: {0}", eds.fi.FileVersion));
file.WriteLine(string.Format(" FileVersion: {0}", eds.fi.fileVersionString));
file.WriteLine(string.Format(" CreationTime: {0}", eds.fi.CreationTime));
file.WriteLine(string.Format(" CreationDate: {0}", eds.fi.CreationDate));
file.WriteLine(string.Format(" CreatedBy: {0}", eds.fi.CreatedBy));
Expand All @@ -517,9 +517,9 @@ CANopen DATA TYPES
file.WriteLine("/*******************************************************************************");
file.WriteLine(" DEVICE INFO:");
file.WriteLine(string.Format(" VendorName: {0}", eds.di.VendorName));
file.WriteLine(string.Format(" VendorNumber: {0}", eds.di.VendorNumber));
file.WriteLine(string.Format(" VendorNumber: {0}", eds.di.VendorNumber.ToHexString()));
file.WriteLine(string.Format(" ProductName: {0}", eds.di.ProductName));
file.WriteLine(string.Format(" ProductNumber: {0}", eds.di.ProductNumber));
file.WriteLine(string.Format(" ProductNumber: {0}", eds.di.ProductNumber.ToHexString()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change to hex?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vendor ID & Product ID are usually written in Hex form

file.WriteLine("*******************************************************************************/");
file.WriteLine("");
file.WriteLine("");
Expand Down
4 changes: 2 additions & 2 deletions libEDSsharp/CanOpenNodeExporter_V4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,9 @@ This file was automatically generated by CANopenEditor {0}
Description: {12}
*******************************************************************************/",
gitVersion, odname,
Path.GetFileName(eds.projectFilename), eds.fi.FileVersion,
Path.GetFileName(eds.projectFilename), eds.fi.fileVersionString,
eds.fi.CreationDateTime, eds.fi.CreatedBy, eds.fi.ModificationDateTime, eds.fi.ModifiedBy,
eds.di.VendorName, eds.di.VendorNumber, eds.di.ProductName, eds.di.ProductNumber,
eds.di.VendorName, eds.di.VendorNumber.ToHexString(), eds.di.ProductName, eds.di.ProductNumber.ToHexString(),
eds.fi.Description));

file.WriteLine(string.Format(@"
Expand Down
28 changes: 18 additions & 10 deletions libEDSsharp/CanOpenXDD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public ISO15745ProfileContainer convert(EDSsharp eds)
device.DeviceIdentity.vendorName.readOnly = true;

device.DeviceIdentity.vendorID = new vendorID();
device.DeviceIdentity.vendorID.Value = eds.di.VendorNumber;
device.DeviceIdentity.vendorID.Value = eds.di.VendorNumber.ToHexString();
device.DeviceIdentity.vendorID.readOnly = true;

device.DeviceIdentity.deviceFamily = new deviceFamily();
Expand All @@ -263,7 +263,7 @@ public ISO15745ProfileContainer convert(EDSsharp eds)

device.supportedLanguages = "en";

device.fileVersion = eds.fi.FileVersion;
device.fileVersion = eds.fi.FileVersion.ToString();

device.fileName = Path.GetFileName(eds.projectFilename);

Expand All @@ -277,7 +277,7 @@ public ISO15745ProfileContainer convert(EDSsharp eds)
device.DeviceIdentity.productName.readOnly = true;

device.DeviceIdentity.productID = new productID();
device.DeviceIdentity.productID.Value = eds.di.ProductNumber;
device.DeviceIdentity.productID.Value = eds.di.ProductNumber.ToHexString();
device.DeviceIdentity.productID.readOnly = true;

device.DeviceIdentity.productText = new productText();
Expand Down Expand Up @@ -401,7 +401,7 @@ public ISO15745ProfileContainer convert(EDSsharp eds)
comnet.fileModificationTime = eds.fi.ModificationDateTime;
comnet.fileModificationDateSpecified = true;

comnet.fileVersion = eds.fi.FileVersion;
comnet.fileVersion = eds.fi.FileVersion.ToString();

comnet.supportedLanguages = "en";

Expand Down Expand Up @@ -1157,9 +1157,10 @@ public EDSsharp convert(ISO15745ProfileContainer container)
if (obj.DeviceIdentity != null)
{
eds.di.ProductName = obj.DeviceIdentity.productName.Value;
eds.di.ProductNumber = obj.DeviceIdentity.productID.Value;
eds.di.ProductNumber = UInt32.Parse(obj.DeviceIdentity.productID.Value);
eds.di.VendorName = obj.DeviceIdentity.vendorName.Value;
eds.di.VendorNumber = obj.DeviceIdentity.vendorID.Value;
eds.di.VendorNumber = UInt32.Parse(obj.DeviceIdentity.vendorID.Value);


foreach (object o in obj.DeviceIdentity.productText.Items)
{
Expand All @@ -1184,12 +1185,19 @@ public EDSsharp convert(ISO15745ProfileContainer container)
eds.fi.EDSVersion = keyvalue[1];
break;
case "FileRevision":
eds.fi.FileVersion = keyvalue[1];
if (byte.TryParse(keyvalue[1], out eds.fi.FileVersion) == false)
{
eds.fi.FileVersion = 0;
Warnings.warning_list.Add("XDD FileRevision value \"" + keyvalue[1] + "\" cannot be parsed!");
}
break;
case "RevisionNum":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove this?

Copy link
Author

@GRoussos GRoussos Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was replaced with "RevisionNumber" by mistake, at the time I did not realise that the vendorTextDescription is a separate way to set the device identity fields.

byte.TryParse(keyvalue[1], out eds.fi.FileRevision); break;


if (byte.TryParse(keyvalue[1], out eds.fi.FileRevision) == false)
{
eds.fi.FileRevision = 0;
Warnings.warning_list.Add("XDD RevisionNum value \"" + keyvalue[1] + "\" cannot be parsed!");
}
break;
}
}
}
Expand Down
Loading