mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 22:38:27 +08:00
@@ -1221,13 +1221,13 @@ namespace S7.Net
|
||||
else
|
||||
return Types.Counter.ToArray(bytes);
|
||||
case VarType.Bit:
|
||||
if (varCount == 1 && bitAdr <= 7)
|
||||
{
|
||||
BitArray bitArr = new BitArray(new byte[] { bytes[0] });
|
||||
return bitArr[bitAdr];
|
||||
}
|
||||
if (varCount == 1)
|
||||
if (bitAdr > 7)
|
||||
return null;
|
||||
else
|
||||
return Types.Bit.FromByte(bytes[0], bitAdr);
|
||||
else
|
||||
return null;
|
||||
return Types.Bit.ToBitArray(bytes);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
<Compile Include="Enums.cs" />
|
||||
<Compile Include="PLC.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Types\Bit.cs" />
|
||||
<Compile Include="Types\Boolean.cs" />
|
||||
<Compile Include="Types\Byte.cs" />
|
||||
<Compile Include="Types\ByteArray.cs" />
|
||||
|
||||
29
S7.Net/Types/Bit.cs
Normal file
29
S7.Net/Types/Bit.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace S7.Net.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the conversion methods to convert Bit from S7 plc to C#.
|
||||
/// </summary>
|
||||
public static class Bit
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a Bit to bool
|
||||
/// </summary>
|
||||
public static bool FromByte(byte v, byte bitAdr)
|
||||
{
|
||||
BitArray bitArr = new BitArray(new byte[] { v });
|
||||
return bitArr[bitAdr];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an array of bytes to a BitArray
|
||||
/// </summary>
|
||||
public static BitArray ToBitArray(byte[] bytes)
|
||||
{
|
||||
BitArray bitArr = new BitArray(bytes);
|
||||
return bitArr;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user