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

Step7 improvements #158

Merged
merged 3 commits into from
Nov 10, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override string GetSourceBlock(bool useSymbols = false)
string name = this.BlockName;
if (useSymbols && SymbolTableEntry != null)
{
name = SymbolTableEntry.Symbol;
name = "\"" + SymbolTableEntry.Symbol + "\"";
}

if (this.BlockType == PLCBlockType.UDT)
Expand All @@ -121,7 +121,8 @@ public override string GetSourceBlock(bool useSymbols = false)
if (this.Structure.Children != null && !this.IsInstanceDB)
{
retVal.AppendLine(" STRUCT");
retVal.Append(AWLToSource.DataRowToSource(((S7DataRow)this.Structure), " "));
string lines = AWLToSource.DataRowToSource(((S7DataRow)this.Structure), " ");
retVal.Append(lines);
retVal.AppendLine(" END_STRUCT ;");

}
Expand All @@ -130,7 +131,7 @@ public override string GetSourceBlock(bool useSymbols = false)
if (useSymbols)
{
if (SymbolTable.GetEntryFromOperand("FB" + this.FBNumber) != null)
retVal.AppendLine(" " + SymbolTable.GetEntryFromOperand("FB" + this.FBNumber).Symbol);
retVal.AppendLine("\"" + SymbolTable.GetEntryFromOperand("FB" + this.FBNumber).Symbol + "\"");
else retVal.AppendLine(" FB " + this.FBNumber);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,13 @@ public override string GetSourceBlock(bool useSymbols = false)
string name = this.BlockName;
if (useSymbols && SymbolTableEntry != null)
{
name = SymbolTableEntry.Symbol;
name = "\"" + SymbolTableEntry.Symbol + "\"";
}

if (this.BlockType == PLCBlockType.FC)
retVal.AppendLine("FUNCTION " + name + " : VOID");
else if (this.BlockType == PLCBlockType.OB)
retVal.AppendLine("ORGANIZATION_BLOCK " + name);
else
retVal.AppendLine("FUNCTION_BLOCK " + name);

Expand Down Expand Up @@ -173,7 +175,21 @@ public override string GetSourceBlock(bool useSymbols = false)
else if (parnm == "STATIC")
ber = "VAR";
retVal.AppendLine(ber);
retVal.Append(AWLToSource.DataRowToSource(s7DataRow, " ", ((this.BlockType != PLCBlockType.FB && this.BlockType != PLCBlockType.SFB) || parnm == "TEMP")));
string vars = AWLToSource.DataRowToSource(s7DataRow, " ", ((this.BlockType != PLCBlockType.FB && this.BlockType != PLCBlockType.SFB) || parnm == "TEMP"));
if (useSymbols) {
foreach (string dependency in Dependencies)
{
if (dependency.Contains("SFC") || dependency.Contains("SFB"))
continue;
try
{
string depSymbol = "\"" + SymbolTable.GetEntryFromOperand(dependency).Symbol + "\"";
vars = vars.Replace(dependency, SymbolTable.GetEntryFromOperand(dependency).Symbol);
}
catch { }
}
}
retVal.Append(vars);
retVal.AppendLine("END_VAR");
}
}
Expand Down Expand Up @@ -202,6 +218,8 @@ public override string GetSourceBlock(bool useSymbols = false)

if (this.BlockType == PLCBlockType.FC)
retVal.Append("END_FUNCTION");
else if (this.BlockType == PLCBlockType.OB)
retVal.AppendLine("END_ORGANIZATION_BLOCK");
else
retVal.Append("END_FUNCTION_BLOCK");
//retVal.Append("END_FUNCTION");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using DotNetSiemensPLCToolBoxLibrary.Projectfiles;

namespace DotNetSiemensPLCToolBoxLibrary.DataTypes.Projectfolders.Step7V5
Expand All @@ -25,6 +26,30 @@ public List<SymbolTableEntry> SymbolTableEntrys
set { _step7SymbolTableEntrys = value; }
}

/// <summary>
/// Returns the symbol list as a string that
/// is formatted in the same way as an export from
/// the Simatic Symbol Editor when saving it as .SDF
/// (System Data Format) type.
/// </summary>
/// <param name="language"></param>
/// <returns></returns>
public string GetSymbolTableAsSdf()
{
var symbolTable = new System.Text.StringBuilder();
foreach (var entry in SymbolTableEntrys)
{
symbolTable.Append("\"" + entry.Symbol.PadRight(24) + "\",");
if(Project.ProjectLanguage == MnemonicLanguage.English)
symbolTable.Append("\"" + entry.OperandIEC.PadRight(12) + "\",");
else
symbolTable.Append("\"" + entry.Operand.PadRight(12) + "\",");
symbolTable.Append("\"" + entry.DataType.PadRight(10) + "\",");
symbolTable.AppendLine("\"" + entry.Comment.PadRight(80) + "\"");
}
return symbolTable.ToString();
}

internal bool showDeleted { get; set; }

public SymbolTableEntry GetEntryFromOperand(string operand)
Expand Down
12 changes: 6 additions & 6 deletions LibNoDaveConnectionLibrary/PLCs/S7_xxx/MC7/Mnemonic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public static class Mnemonic
public static string[] opSPB = new string[] { "SPB", "JC" };
public static string[] opSPBB = new string[] { "SPBB", "JCB" };
public static string[] opSPBI = new string[] { "SPBI", "JBI" };
public static string[] opSPBIN = new string[] { "SPBIN", "JBNI" };
public static string[] opSPBIN = new string[] { "SPBIN", "JNBI" };
public static string[] opSPBN = new string[] { "SPBN", "JCN" };
public static string[] opSPBNB = new string[] { "SPBNB", "JNB" };
public static string[] opSPL = new string[] { "SPL", "JL" };
Expand All @@ -182,16 +182,16 @@ public static class Mnemonic
public static string[] opSS = new string[] { "SS", "SS" };
public static string[] opSSD = new string[] { "SSD", "SSD" };
public static string[] opSSI = new string[] { "SSI", "SSI" };
public static string[] opSV = new string[] { "SV", "SV" };
public static string[] opSV = new string[] { "SV", "SE" };
public static string[] opT = new string[] { "T", "T" };
public static string[] opTAD = new string[] { "TAD", "TAD" };
public static string[] opTAD = new string[] { "TAD", "CAD" };
public static string[] opTAK = new string[] { "TAK", "TAK" };
public static string[] opTAN = new string[] { "TAN", "TAN" };
public static string[] opTAR = new string[] { "TAR", "TAR" };
public static string[] opTAR = new string[] { "TAR", "CAR" };
public static string[] opTAR1 = new string[] { "TAR1", "TAR1" };
public static string[] opTAR2 = new string[] { "TAR2", "TAR2" };
public static string[] opTAW = new string[] { "TAW", "TAW" };
public static string[] opTDB = new string[] { "TDB", "TDB" };
public static string[] opTAW = new string[] { "TAW", "CAW" };
public static string[] opTDB = new string[] { "TDB", "CDB" };
public static string[] opTRUNC = new string[] { "TRUNC", "TRUNC" };
public static string[] opU = new string[] { "U", "A" };
public static string[] opUO = new string[] { "U(", "A(" };
Expand Down