mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 14:28:25 +08:00
- fix data type converting
- add new string string data type
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user