|
|
@@ -19,7 +19,7 @@ namespace BPASmartClient.S7Net |
|
|
|
select p; |
|
|
|
} |
|
|
|
|
|
|
|
private static double GetIncreasedNumberOfBytes(double numBytes, Type type) |
|
|
|
private static double GetIncreasedNumberOfBytes(double numBytes, Type type, PropertyInfo propertyInfo) |
|
|
|
{ |
|
|
|
switch (type.Name) |
|
|
|
{ |
|
|
@@ -46,7 +46,13 @@ namespace BPASmartClient.S7Net |
|
|
|
break; |
|
|
|
case "String": |
|
|
|
//numBytes += 256.0; |
|
|
|
numBytes += 1.0; |
|
|
|
double len = 256.0; |
|
|
|
if (propertyInfo.CustomAttributes.Count() > 0) |
|
|
|
{ |
|
|
|
var tempLen = propertyInfo.GetCustomAttribute<SiemensAttribute>(); |
|
|
|
if (tempLen != null) len = Convert.ToDouble(tempLen.Len) + 2.0; |
|
|
|
} |
|
|
|
numBytes += len; |
|
|
|
break; |
|
|
|
default: |
|
|
|
numBytes = GetClassSize(Activator.CreateInstance(type), numBytes, isInnerProperty: true); |
|
|
@@ -80,12 +86,12 @@ namespace BPASmartClient.S7Net |
|
|
|
IncrementToEven(ref numBytes); |
|
|
|
for (int i = 0; i < array.Length; i++) |
|
|
|
{ |
|
|
|
numBytes = GetIncreasedNumberOfBytes(numBytes, elementType); |
|
|
|
numBytes = GetIncreasedNumberOfBytes(numBytes, elementType, accessableProperty); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
numBytes = GetIncreasedNumberOfBytes(numBytes, accessableProperty.PropertyType); |
|
|
|
numBytes = GetIncreasedNumberOfBytes(numBytes, accessableProperty.PropertyType, accessableProperty); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -101,7 +107,7 @@ namespace BPASmartClient.S7Net |
|
|
|
return numBytes; |
|
|
|
} |
|
|
|
|
|
|
|
private static object? GetPropertyValue(Type propertyType, byte[] bytes, ref double numBytes) |
|
|
|
private static object? GetPropertyValue(Type propertyType, byte[] bytes, PropertyInfo propertyInfo, ref double numBytes) |
|
|
|
{ |
|
|
|
object obj = null; |
|
|
|
switch (propertyType.Name) |
|
|
@@ -195,10 +201,20 @@ namespace BPASmartClient.S7Net |
|
|
|
//obj = GetGb2312()?.GetString(sarray).Trim().Replace(" ", "").Replace("\n", ""); |
|
|
|
//numBytes += 256.0; |
|
|
|
|
|
|
|
byte[] sarray = new byte[1]; |
|
|
|
Array.Copy(bytes, (int)numBytes, sarray, 0, 1); |
|
|
|
obj = GetGb2312()?.GetString(sarray).Trim().Replace(" ", "").Replace("\n", ""); |
|
|
|
numBytes += 1; |
|
|
|
int len = 256; |
|
|
|
if (propertyInfo.CustomAttributes.Count() > 0) |
|
|
|
{ |
|
|
|
var tempLen = propertyInfo.GetCustomAttribute<SiemensAttribute>(); |
|
|
|
if (tempLen != null) len = tempLen.Len + 2; |
|
|
|
} |
|
|
|
|
|
|
|
byte[] sarray = new byte[len]; |
|
|
|
Array.Copy(bytes, (int)numBytes, sarray, 0, len); |
|
|
|
List<byte> bytes1 = new List<byte>(); |
|
|
|
if (sarray.Length > 2) |
|
|
|
for (int i = 2; i < sarray.Length; i++) if (sarray[i] > 0) bytes1.Add(sarray[i]); |
|
|
|
obj = GetGb2312()?.GetString(bytes1.ToArray()).Trim().Replace(" ", "").Replace("\n", ""); |
|
|
|
numBytes += len; |
|
|
|
break; |
|
|
|
default: |
|
|
|
{ |
|
|
@@ -240,19 +256,19 @@ namespace BPASmartClient.S7Net |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
array.SetValue(GetPropertyValue(elementType, bytes, ref numBytes), i); |
|
|
|
array.SetValue(GetPropertyValue(elementType, bytes, accessableProperty, ref numBytes), i); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
accessableProperty.SetValue(sourceClass, GetPropertyValue(accessableProperty.PropertyType, bytes, ref numBytes), null); |
|
|
|
accessableProperty.SetValue(sourceClass, GetPropertyValue(accessableProperty.PropertyType, bytes, accessableProperty, ref numBytes), null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return numBytes; |
|
|
|
} |
|
|
|
|
|
|
|
private static double SetBytesFromProperty(object propertyValue, byte[] bytes, double numBytes) |
|
|
|
private static double SetBytesFromProperty(object propertyValue, byte[] bytes, double numBytes, PropertyInfo propertyInfo) |
|
|
|
{ |
|
|
|
int num = 0; |
|
|
|
int num2 = 0; |
|
|
@@ -298,9 +314,25 @@ namespace BPASmartClient.S7Net |
|
|
|
array = LReal.ToByteArray((double)propertyValue); |
|
|
|
break; |
|
|
|
case "String": |
|
|
|
array = new byte[256]; |
|
|
|
//array = new byte[256]; |
|
|
|
//var res = GetGb2312()?.GetBytes(propertyValue?.ToString()); |
|
|
|
//for (int i = 0; i < res?.Length; i++) { array[i] = res[i]; } |
|
|
|
int len = 256; |
|
|
|
if (propertyInfo.CustomAttributes.Count() > 0) |
|
|
|
{ |
|
|
|
var tempLen = propertyInfo.GetCustomAttribute<SiemensAttribute>(); |
|
|
|
if (tempLen != null) len = tempLen.Len + 2; |
|
|
|
} |
|
|
|
array = new byte[len]; |
|
|
|
var res = GetGb2312()?.GetBytes(propertyValue?.ToString()); |
|
|
|
for (int i = 0; i < res?.Length; i++) { array[i] = res[i]; } |
|
|
|
if (array.Length > 2) array[0] = (byte)(len - 2); array[1] = (byte)res.Length; |
|
|
|
|
|
|
|
for (int i = 0; i < res?.Length; i++) |
|
|
|
{ |
|
|
|
int index = i + 2; |
|
|
|
if (index < array.Length) |
|
|
|
array[index] = res[i]; |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
numBytes = ToBytes(propertyValue, bytes, numBytes); |
|
|
@@ -339,12 +371,12 @@ namespace BPASmartClient.S7Net |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
numBytes = SetBytesFromProperty(array.GetValue(i), bytes, numBytes); |
|
|
|
numBytes = SetBytesFromProperty(array.GetValue(i), bytes, numBytes, accessableProperty); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
numBytes = SetBytesFromProperty(accessableProperty.GetValue(sourceClass, null), bytes, numBytes); |
|
|
|
numBytes = SetBytesFromProperty(accessableProperty.GetValue(sourceClass, null), bytes, numBytes, accessableProperty); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|