mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-25 08:48:25 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6a2e11045 | ||
|
|
8005304827 | ||
|
|
ef5e060948 | ||
|
|
3178d2aa09 | ||
|
|
6a2bc708a9 |
@@ -352,13 +352,14 @@ namespace S7.Net
|
||||
/// <param name="db">Address of the memory area (if you want to read DB1, this is set to 1). This must be set also for other memory area types: counters, timers,etc.</param>
|
||||
/// <param name="startByteAdr">Start byte address. If you want to read DB1.DBW200, this is 200.</param>
|
||||
/// <param name="varType">Type of the variable/s that you are reading</param>
|
||||
/// <param name="bitAdr">Address of bit. If you want to read DB1.DBX200.6, set 6 to this parameter.</param>
|
||||
/// <param name="varCount"></param>
|
||||
public object Read(DataType dataType, int db, int startByteAdr, VarType varType, int varCount)
|
||||
public object Read(DataType dataType, int db, int startByteAdr, VarType varType, int varCount, byte bitAdr = 0)
|
||||
{
|
||||
int cntBytes = VarTypeToByteLength(varType, varCount);
|
||||
byte[] bytes = ReadBytes(dataType, db, startByteAdr, cntBytes);
|
||||
|
||||
return ParseBytes(varType, bytes, varCount);
|
||||
return ParseBytes(varType, bytes, varCount, bitAdr);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1169,8 +1170,9 @@ namespace S7.Net
|
||||
/// <param name="varType"></param>
|
||||
/// <param name="bytes"></param>
|
||||
/// <param name="varCount"></param>
|
||||
/// <param name="bitAdr"></param>
|
||||
/// <returns></returns>
|
||||
private object ParseBytes(VarType varType, byte[] bytes, int varCount)
|
||||
private object ParseBytes(VarType varType, byte[] bytes, int varCount, byte bitAdr = 0)
|
||||
{
|
||||
if (bytes == null) return null;
|
||||
|
||||
@@ -1219,7 +1221,13 @@ namespace S7.Net
|
||||
else
|
||||
return Types.Counter.ToArray(bytes);
|
||||
case VarType.Bit:
|
||||
return null; //TODO
|
||||
if (varCount == 1)
|
||||
if (bitAdr > 7)
|
||||
return null;
|
||||
else
|
||||
return Types.Bit.FromByte(bytes[0], bitAdr);
|
||||
else
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -343,7 +343,7 @@
|
||||
<param name="count">Byte count, if you want to read 120 bytes, set this to 120.</param>
|
||||
<returns>Returns the bytes in an array</returns>
|
||||
</member>
|
||||
<member name="M:S7.Net.Plc.Read(S7.Net.DataType,System.Int32,System.Int32,S7.Net.VarType,System.Int32)">
|
||||
<member name="M:S7.Net.Plc.Read(S7.Net.DataType,System.Int32,System.Int32,S7.Net.VarType,System.Int32,System.Byte)">
|
||||
<summary>
|
||||
Read and decode a certain number of bytes of the "VarType" provided.
|
||||
This can be used to read multiple consecutive variables of the same type (Word, DWord, Int, etc).
|
||||
@@ -353,6 +353,7 @@
|
||||
<param name="db">Address of the memory area (if you want to read DB1, this is set to 1). This must be set also for other memory area types: counters, timers,etc.</param>
|
||||
<param name="startByteAdr">Start byte address. If you want to read DB1.DBW200, this is 200.</param>
|
||||
<param name="varType">Type of the variable/s that you are reading</param>
|
||||
<param name="bitAdr">Address of bit. If you want to read DB1.DBX200.6, set 6 to this parameter.</param>
|
||||
<param name="varCount"></param>
|
||||
</member>
|
||||
<member name="M:S7.Net.Plc.Read(System.String)">
|
||||
@@ -520,13 +521,14 @@
|
||||
<param name="value">Bytes to write. The lenght of this parameter can't be higher than 200. If you need more, use recursion.</param>
|
||||
<returns>NoError if it was successful, or the error is specified</returns>
|
||||
</member>
|
||||
<member name="M:S7.Net.Plc.ParseBytes(S7.Net.VarType,System.Byte[],System.Int32)">
|
||||
<member name="M:S7.Net.Plc.ParseBytes(S7.Net.VarType,System.Byte[],System.Int32,System.Byte)">
|
||||
<summary>
|
||||
Given a S7 variable type (Bool, Word, DWord, etc.), it converts the bytes in the appropriate C# format.
|
||||
</summary>
|
||||
<param name="varType"></param>
|
||||
<param name="bytes"></param>
|
||||
<param name="varCount"></param>
|
||||
<param name="bitAdr"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:S7.Net.Plc.VarTypeToByteLength(S7.Net.VarType,System.Int32)">
|
||||
@@ -542,6 +544,21 @@
|
||||
Releases all resources, disonnects from the plc and closes the socket
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:S7.Net.Types.Bit">
|
||||
<summary>
|
||||
Contains the conversion methods to convert Bit from S7 plc to C#.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:S7.Net.Types.Bit.FromByte(System.Byte,System.Byte)">
|
||||
<summary>
|
||||
Converts a Bit to bool
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:S7.Net.Types.Bit.ToBitArray(System.Byte[])">
|
||||
<summary>
|
||||
Converts an array of bytes to a BitArray
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:S7.Net.Types.Boolean">
|
||||
<summary>
|
||||
Contains the methods to read, set and reset bits inside bytes
|
||||
|
||||
Binary file not shown.
@@ -343,7 +343,7 @@
|
||||
<param name="count">Byte count, if you want to read 120 bytes, set this to 120.</param>
|
||||
<returns>Returns the bytes in an array</returns>
|
||||
</member>
|
||||
<member name="M:S7.Net.Plc.Read(S7.Net.DataType,System.Int32,System.Int32,S7.Net.VarType,System.Int32)">
|
||||
<member name="M:S7.Net.Plc.Read(S7.Net.DataType,System.Int32,System.Int32,S7.Net.VarType,System.Int32,System.Byte)">
|
||||
<summary>
|
||||
Read and decode a certain number of bytes of the "VarType" provided.
|
||||
This can be used to read multiple consecutive variables of the same type (Word, DWord, Int, etc).
|
||||
@@ -353,6 +353,7 @@
|
||||
<param name="db">Address of the memory area (if you want to read DB1, this is set to 1). This must be set also for other memory area types: counters, timers,etc.</param>
|
||||
<param name="startByteAdr">Start byte address. If you want to read DB1.DBW200, this is 200.</param>
|
||||
<param name="varType">Type of the variable/s that you are reading</param>
|
||||
<param name="bitAdr">Address of bit. If you want to read DB1.DBX200.6, set 6 to this parameter.</param>
|
||||
<param name="varCount"></param>
|
||||
</member>
|
||||
<member name="M:S7.Net.Plc.Read(System.String)">
|
||||
@@ -520,13 +521,14 @@
|
||||
<param name="value">Bytes to write. The lenght of this parameter can't be higher than 200. If you need more, use recursion.</param>
|
||||
<returns>NoError if it was successful, or the error is specified</returns>
|
||||
</member>
|
||||
<member name="M:S7.Net.Plc.ParseBytes(S7.Net.VarType,System.Byte[],System.Int32)">
|
||||
<member name="M:S7.Net.Plc.ParseBytes(S7.Net.VarType,System.Byte[],System.Int32,System.Byte)">
|
||||
<summary>
|
||||
Given a S7 variable type (Bool, Word, DWord, etc.), it converts the bytes in the appropriate C# format.
|
||||
</summary>
|
||||
<param name="varType"></param>
|
||||
<param name="bytes"></param>
|
||||
<param name="varCount"></param>
|
||||
<param name="bitAdr"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:S7.Net.Plc.VarTypeToByteLength(S7.Net.VarType,System.Int32)">
|
||||
@@ -542,6 +544,21 @@
|
||||
Releases all resources, disonnects from the plc and closes the socket
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:S7.Net.Types.Bit">
|
||||
<summary>
|
||||
Contains the conversion methods to convert Bit from S7 plc to C#.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:S7.Net.Types.Bit.FromByte(System.Byte,System.Byte)">
|
||||
<summary>
|
||||
Converts a Bit to bool
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:S7.Net.Types.Bit.ToBitArray(System.Byte[])">
|
||||
<summary>
|
||||
Converts an array of bytes to a BitArray
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:S7.Net.Types.Boolean">
|
||||
<summary>
|
||||
Contains the methods to read, set and reset bits inside bytes
|
||||
|
||||
Binary file not shown.
@@ -343,7 +343,7 @@
|
||||
<param name="count">Byte count, if you want to read 120 bytes, set this to 120.</param>
|
||||
<returns>Returns the bytes in an array</returns>
|
||||
</member>
|
||||
<member name="M:S7.Net.Plc.Read(S7.Net.DataType,System.Int32,System.Int32,S7.Net.VarType,System.Int32)">
|
||||
<member name="M:S7.Net.Plc.Read(S7.Net.DataType,System.Int32,System.Int32,S7.Net.VarType,System.Int32,System.Byte)">
|
||||
<summary>
|
||||
Read and decode a certain number of bytes of the "VarType" provided.
|
||||
This can be used to read multiple consecutive variables of the same type (Word, DWord, Int, etc).
|
||||
@@ -353,6 +353,7 @@
|
||||
<param name="db">Address of the memory area (if you want to read DB1, this is set to 1). This must be set also for other memory area types: counters, timers,etc.</param>
|
||||
<param name="startByteAdr">Start byte address. If you want to read DB1.DBW200, this is 200.</param>
|
||||
<param name="varType">Type of the variable/s that you are reading</param>
|
||||
<param name="bitAdr">Address of bit. If you want to read DB1.DBX200.6, set 6 to this parameter.</param>
|
||||
<param name="varCount"></param>
|
||||
</member>
|
||||
<member name="M:S7.Net.Plc.Read(System.String)">
|
||||
@@ -520,13 +521,14 @@
|
||||
<param name="value">Bytes to write. The lenght of this parameter can't be higher than 200. If you need more, use recursion.</param>
|
||||
<returns>NoError if it was successful, or the error is specified</returns>
|
||||
</member>
|
||||
<member name="M:S7.Net.Plc.ParseBytes(S7.Net.VarType,System.Byte[],System.Int32)">
|
||||
<member name="M:S7.Net.Plc.ParseBytes(S7.Net.VarType,System.Byte[],System.Int32,System.Byte)">
|
||||
<summary>
|
||||
Given a S7 variable type (Bool, Word, DWord, etc.), it converts the bytes in the appropriate C# format.
|
||||
</summary>
|
||||
<param name="varType"></param>
|
||||
<param name="bytes"></param>
|
||||
<param name="varCount"></param>
|
||||
<param name="bitAdr"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:S7.Net.Plc.VarTypeToByteLength(S7.Net.VarType,System.Int32)">
|
||||
@@ -542,6 +544,21 @@
|
||||
Releases all resources, disonnects from the plc and closes the socket
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:S7.Net.Types.Bit">
|
||||
<summary>
|
||||
Contains the conversion methods to convert Bit from S7 plc to C#.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:S7.Net.Types.Bit.FromByte(System.Byte,System.Byte)">
|
||||
<summary>
|
||||
Converts a Bit to bool
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:S7.Net.Types.Bit.ToBitArray(System.Byte[])">
|
||||
<summary>
|
||||
Converts an array of bytes to a BitArray
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:S7.Net.Types.Boolean">
|
||||
<summary>
|
||||
Contains the methods to read, set and reset bits inside bytes
|
||||
|
||||
Reference in New Issue
Block a user