Skip to content

Commit 60e4e91

Browse files
committed
CANopenNode_v4: Enable UTF-8 inside VISIBLE_STRING.
1 parent d2ca7b1 commit 60e4e91

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

libEDSsharp/CanOpenNodeExporter_V4.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -833,21 +833,27 @@ private DataProperties Get_dataProperties(DataType dataType, string defaultvalue
833833

834834
if (valueDefined)
835835
{
836-
Encoding ascii = Encoding.ASCII;
837-
Byte[] encodedBytes = ascii.GetBytes(defaultvalue);
836+
UTF8Encoding utf8 = new UTF8Encoding();
837+
Byte[] encodedBytes = utf8.GetBytes(defaultvalue);
838838
foreach (Byte b in encodedBytes)
839839
{
840-
chars.Add($"'{StringUnescape.Escape((char)b)}'");
840+
if ((char)b == '\'')
841+
chars.Add("'\\''");
842+
else if (b >= 0x20 && b < 0x7F)
843+
chars.Add($"'{(char)b}'");
844+
else
845+
chars.Add($"0x{b:X2}");
841846
len++;
842847
}
843848
}
849+
/* fill unused bytes with nulls */
844850
for (; len < stringLength; len++)
845851
{
846-
chars.Add("'\\0'");
852+
chars.Add("0");
847853
}
848854

849855
// extra string terminator
850-
chars.Add("'\\0'");
856+
chars.Add("0");
851857

852858
data.length = len;
853859
data.cType = "char";

0 commit comments

Comments
 (0)