Skip to content

Commit

Permalink
Merge pull request #75 from StefanHasensperling/master
Browse files Browse the repository at this point in the history
Bug Fix in Parsing of FB and Datablocks and Proper S7Attribute Parsing
  • Loading branch information
jogibear9988 authored Jul 28, 2017
2 parents d36af41 + bc83009 commit 746b100
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
43 changes: 41 additions & 2 deletions LibNoDaveConnectionLibrary/DataTypes/Blocks/Step7V5/S7Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public class S7Block : Block
{
internal S7ConvertingOptions usedS7ConvertingOptions;

public string BlockVersion;
public Version BlockVersion;

public String BlockAttribute; // .0 not unlinked, .1 standart block + know how protect, .3 know how protect, .5 not retain
public S7BlockAtributes BlockAttribute; // .0 not unlinked, .1 standart block + know how protect, .3 know how protect, .5 not retain

public List<Step7Attribute> Attributes { get; set; }

Expand Down Expand Up @@ -103,6 +103,45 @@ public override SymbolTableEntry SymbolTableEntry
return null;
}
}

[Flags]
public enum S7BlockAtributes: byte
{
/// <summary>
/// The block exists in the controller, and is also linked into execution.
/// if this attribute is FALSE:
/// -For Code blocks such as FB or FC, this means that they are existing in the controller but not actually executed
/// -For data blocks this means, that they do not have any Actual values assigned to them. Any attempt to read current data from them will fail.
/// </summary>
/// <remarks>
/// This corresponds to the "Unlinked" attribute in the Simatic manager, which actually shows the status in reverse
/// This Attribute is only false when either especifically selected from simatic manager (only possible for Datablocks)
/// or during a breif period when an Code block is alrady downloaded, but not yet linked (usually part of the "Block Download" process
/// </remarks>
Linked = 1, //.0

/// <summary>
/// This is an standard block from the default library
/// </summary>
StandardBlock = 2, //.1

/// <summary>
/// The block is protected by an Password
/// </summary>
KnowHowProtected = 8, //.3

/// <summary>
/// Only applies to datablocks. if an DB is non retentive, its actual data get reset to its initial values every time the controller
/// restarts
/// </summary>
NonRetain = 32 //.5

//These two Attributes somehow do not appear on online blocks, even though they are settabele in Simatic Manager
//Maybe some more testing is necesary
//WriteProtected
//ReadOnly

}
}
}

8 changes: 4 additions & 4 deletions LibNoDaveConnectionLibrary/PLCs/S7_xxx/MC7/MC7Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ internal static S7Block GetAWLBlockBasicInfo(byte[] MC7Code, int MnemoricLanguag
* xx = Nertworks
*/

retBlock.BlockVersion = Convert.ToString(MC7Code[2] - 1);
retBlock.BlockAttribute = Convert.ToString(MC7Code[3] - 1);
retBlock.BlockVersion = new Version (MC7Code[2] /10, MC7Code[2] % 10);
retBlock.BlockAttribute = (S7Block.S7BlockAtributes)MC7Code[3];
retBlock.BlockLanguage = (DataTypes.PLCLanguage)MC7Code[4]; // Enum.Parse(typeof(DataTypes.PLCLanguage), Helper.GetLang(MC7Code[4]));
retBlock.MnemonicLanguage = (MnemonicLanguage)MnemoricLanguage;
retBlock.BlockType = Helper.GetPLCBlockType(MC7Code[5]);
Expand Down Expand Up @@ -189,8 +189,8 @@ internal static S7Block GetAWLBlockBasicInfoFromBlockHeader(byte[] MC7Code, int
* xx = Nertworks
*/

retBlock.BlockVersion = Convert.ToString(MC7Code[2] - 1);
retBlock.BlockAttribute = Convert.ToString(MC7Code[3] - 1);
retBlock.BlockVersion = new Version(MC7Code[2] / 10, MC7Code[2] % 10);
retBlock.BlockAttribute = (S7Block.S7BlockAtributes)MC7Code[3];
retBlock.BlockLanguage = (DataTypes.PLCLanguage)MC7Code[4]; // Enum.Parse(typeof(DataTypes.PLCLanguage), Helper.GetLang(MC7Code[4]));
retBlock.MnemonicLanguage = (MnemonicLanguage)MnemoricLanguage;
retBlock.BlockType = Helper.GetPLCBlockType(MC7Code[5]);
Expand Down
2 changes: 1 addition & 1 deletion LibNoDaveConnectionLibrary/PLCs/S7_xxx/MC7/Parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ internal static S7DataRow GetInterface(byte[] interfaceBytes, byte[] actualvalue
while (pos <= (interfaceBytes.Length-2)) // && pos < BD.Length - 2) //pos<BD.Length-2 was added so SDBs can be converted!! but is this needed?
{
object startVal;
if (Helper.IsWithStartVal(interfaceBytes[pos + 1]))
if (Helper.IsWithStartVal(interfaceBytes[pos + 1]) && actualvalueBytes != null)
{
if (interfaceBytes[pos] != 0x10) //Datentyp == Array...
startVal = GetVarTypeVal(interfaceBytes[pos], actualvalueBytes, ref Valpos);
Expand Down

0 comments on commit 746b100

Please sign in to comment.