Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix in Parsing of FB and Datablocks and Proper S7Attribute Parsing #75

Merged
merged 2 commits into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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