S7.NET Testability Updates

Removed the Controls project and existing Test projects. Added new Test
project and references to NUnit and Should projects for testing.
Extracted IPlc interface to help test projects that reference this
library. Also implemented the IDisposable interface on the Plc object so
that references to mSocket would be cleaned up appropriately when the
object is blown away.
This commit is contained in:
Derek Heiser
2013-02-09 10:17:47 -06:00
parent 03e3c8abc3
commit e65c0eed25
31 changed files with 13175 additions and 0 deletions

38
S7.Net/Types/String.cs Normal file
View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace S7.Types
{
public static class String
{
// publics
#region ToByteArray
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;
}
#endregion
#region FromByteArray
public static string FromByteArray(byte[] bytes)
{
return System.Text.Encoding.ASCII.GetString(bytes);
}
#endregion
// privates
private static int Asc(string s)
{
byte[] b = System.Text.Encoding.ASCII.GetBytes(s);
if (b.Length > 0)
return b[0];
return 0;
}
}
}