- fix data type converting

- add new string string data type
This commit is contained in:
Thomas Ze
2018-03-18 21:26:22 +01:00
parent f6a2e11045
commit 7cedec5909
16 changed files with 133 additions and 265 deletions

View File

@@ -3,19 +3,14 @@
/// <summary>
/// Contains the methods to convert from S7 strings to C# strings
/// </summary>
public static class String
public class String
{
/// <summary>
/// Converts a string to S7 bytes
/// </summary>
public static byte[] ToByteArray(string value)
{
string txt = (string)value;
char[] ca = txt.ToCharArray();
byte[] bytes = new byte[txt.Length];
for (int cnt = 0; cnt <= ca.Length - 1; cnt++)
bytes[cnt] = (byte)Asc(ca[cnt].ToString());
return bytes;
return System.Text.Encoding.ASCII.GetBytes(value);
}
/// <summary>
@@ -27,13 +22,6 @@
{
return System.Text.Encoding.ASCII.GetString(bytes);
}
private static int Asc(string s)
{
byte[] b = System.Text.Encoding.ASCII.GetBytes(s);
if (b.Length > 0)
return b[0];
return 0;
}
}
}