diff --git a/Test-S7.sln b/Test-S7.sln new file mode 100644 index 00000000..6a1ff6b4 --- /dev/null +++ b/Test-S7.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27004.2009 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test-S7", "Test-S7\Test-S7.csproj", "{A0168CBE-9DA5-4E41-82FF-AFD39C982717}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A0168CBE-9DA5-4E41-82FF-AFD39C982717}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A0168CBE-9DA5-4E41-82FF-AFD39C982717}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A0168CBE-9DA5-4E41-82FF-AFD39C982717}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A0168CBE-9DA5-4E41-82FF-AFD39C982717}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C43DB985-D122-49F0-AE6E-DADEFFC1AD3D} + EndGlobalSection +EndGlobal diff --git a/Test-S7/App.config b/Test-S7/App.config new file mode 100644 index 00000000..731f6de6 --- /dev/null +++ b/Test-S7/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Test-S7/Program.cs b/Test-S7/Program.cs new file mode 100644 index 00000000..beb9b8ae --- /dev/null +++ b/Test-S7/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Test_S7 +{ + static class Program + { + /// + /// Punto di ingresso principale dell'applicazione. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/Test-S7/Properties/AssemblyInfo.cs b/Test-S7/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..3d8e5f26 --- /dev/null +++ b/Test-S7/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Le informazioni generali relative a un assembly sono controllate dal seguente +// set di attributi. Modificare i valori di questi attributi per modificare le informazioni +// associate a un assembly. +[assembly: AssemblyTitle("Test-S7")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Test-S7")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Se si imposta ComVisible su false, i tipi in questo assembly non saranno visibili +// ai componenti COM. Se è necessario accedere a un tipo in questo assembly da +// COM, impostare su true l'attributo ComVisible per tale tipo. +[assembly: ComVisible(false)] + +// Se il progetto viene esposto a COM, il GUID seguente verrà utilizzato come ID della libreria dei tipi +[assembly: Guid("a0168cbe-9da5-4e41-82ff-afd39c982717")] + +// Le informazioni sulla versione di un assembly sono costituite dai seguenti quattro valori: +// +// Versione principale +// Versione secondaria +// Numero di build +// Revisione +// +// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build +// usando l'asterisco '*' come illustrato di seguito: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Test-S7/Properties/Resources.Designer.cs b/Test-S7/Properties/Resources.Designer.cs new file mode 100644 index 00000000..6506a348 --- /dev/null +++ b/Test-S7/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Codice generato da uno strumento. +// Versione runtime:4.0.30319.42000 +// +// Le modifiche apportate a questo file possono causare un comportamento non corretto e andranno perse se +// il codice viene rigenerato. +// +//------------------------------------------------------------------------------ + +namespace Test_S7.Properties +{ + + + /// + /// Classe di risorse fortemente tipizzata per la ricerca di stringhe localizzate e così via. + /// + // Questa classe è stata generata automaticamente dalla classe StronglyTypedResourceBuilder + // tramite uno strumento quale ResGen o Visual Studio. + // Per aggiungere o rimuovere un membro, modificare il file .ResX, quindi eseguire di nuovo ResGen + // con l'opzione /str oppure ricompilare il progetto VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Restituisce l'istanza di ResourceManager memorizzata nella cache e usata da questa classe. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Test_S7.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Esegue l'override della proprietà CurrentUICulture del thread corrente per tutte + /// le ricerche di risorse che utilizzano questa classe di risorse fortemente tipizzata. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Test-S7/Properties/Resources.resx b/Test-S7/Properties/Resources.resx new file mode 100644 index 00000000..af7dbebb --- /dev/null +++ b/Test-S7/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Test-S7/Properties/Settings.Designer.cs b/Test-S7/Properties/Settings.Designer.cs new file mode 100644 index 00000000..31caac60 --- /dev/null +++ b/Test-S7/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Test_S7.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Test-S7/Properties/Settings.settings b/Test-S7/Properties/Settings.settings new file mode 100644 index 00000000..39645652 --- /dev/null +++ b/Test-S7/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Test-S7/Test-S7.csproj b/Test-S7/Test-S7.csproj new file mode 100644 index 00000000..cb8c21d3 --- /dev/null +++ b/Test-S7/Test-S7.csproj @@ -0,0 +1,86 @@ + + + + + Debug + AnyCPU + {A0168CBE-9DA5-4E41-82FF-AFD39C982717} + WinExe + Test_S7 + Test-S7 + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\S7netplus.0.1.7\lib\net45\S7.Net.dll + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/Test-S7/mAINfORM.Designer.cs b/Test-S7/mAINfORM.Designer.cs new file mode 100644 index 00000000..89725c26 --- /dev/null +++ b/Test-S7/mAINfORM.Designer.cs @@ -0,0 +1,288 @@ +namespace Test_S7 +{ + partial class MainForm + { + /// + /// Variabile di progettazione necessaria. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Pulire le risorse in uso. + /// + /// ha valore true se le risorse gestite devono essere eliminate, false in caso contrario. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Codice generato da Progettazione Windows Form + + /// + /// Metodo necessario per il supporto della finestra di progettazione. Non modificare + /// il contenuto del metodo con l'editor di codice. + /// + private void InitializeComponent() + { + this.txtIP = new System.Windows.Forms.TextBox(); + this.lblIP = new System.Windows.Forms.Label(); + this.cbCpuType = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.txtMemArea = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.txtMemSize = new System.Windows.Forms.TextBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.label4 = new System.Windows.Forms.Label(); + this.txtRack = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.txtSlot = new System.Windows.Forms.TextBox(); + this.label6 = new System.Windows.Forms.Label(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.groupBox3.SuspendLayout(); + this.SuspendLayout(); + // + // txtIP + // + this.txtIP.Location = new System.Drawing.Point(85, 24); + this.txtIP.Name = "txtIP"; + this.txtIP.Size = new System.Drawing.Size(109, 22); + this.txtIP.TabIndex = 0; + this.txtIP.Text = "127.0.0.1"; + // + // lblIP + // + this.lblIP.AutoSize = true; + this.lblIP.Location = new System.Drawing.Point(16, 27); + this.lblIP.Name = "lblIP"; + this.lblIP.Size = new System.Drawing.Size(63, 17); + this.lblIP.TabIndex = 1; + this.lblIP.Text = "IP ADDR"; + // + // cbCpuType + // + this.cbCpuType.FormattingEnabled = true; + this.cbCpuType.Items.AddRange(new object[] { + "S7200", + "S7300", + "S7400", + "S71200", + "S71500"}); + this.cbCpuType.Location = new System.Drawing.Point(85, 61); + this.cbCpuType.Name = "cbCpuType"; + this.cbCpuType.Size = new System.Drawing.Size(109, 24); + this.cbCpuType.TabIndex = 2; + this.cbCpuType.Text = "S71200"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(7, 64); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(72, 17); + this.label1.TabIndex = 3; + this.label1.Text = "CPU Type"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(9, 24); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(80, 17); + this.label2.TabIndex = 5; + this.label2.Text = "MEM AREA"; + // + // txtMemArea + // + this.txtMemArea.Location = new System.Drawing.Point(95, 21); + this.txtMemArea.Name = "txtMemArea"; + this.txtMemArea.Size = new System.Drawing.Size(107, 22); + this.txtMemArea.TabIndex = 4; + this.txtMemArea.Text = "DB241.DBD0"; + this.txtMemArea.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(9, 61); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(73, 17); + this.label3.TabIndex = 7; + this.label3.Text = "MEM SIZE"; + // + // txtMemSize + // + this.txtMemSize.Location = new System.Drawing.Point(104, 59); + this.txtMemSize.Name = "txtMemSize"; + this.txtMemSize.Size = new System.Drawing.Size(98, 22); + this.txtMemSize.TabIndex = 6; + this.txtMemSize.Text = "16"; + this.txtMemSize.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // groupBox1 + // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.txtMemArea); + this.groupBox1.Controls.Add(this.txtMemSize); + this.groupBox1.Controls.Add(this.label3); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Location = new System.Drawing.Point(535, 12); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(208, 100); + this.groupBox1.TabIndex = 8; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Memoria: parametri lettura"; + // + // groupBox2 + // + this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox2.AutoSize = true; + this.groupBox2.Controls.Add(this.textBox1); + this.groupBox2.Location = new System.Drawing.Point(12, 118); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(731, 240); + this.groupBox2.TabIndex = 9; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Risultati"; + // + // textBox1 + // + this.textBox1.BackColor = System.Drawing.SystemColors.Desktop; + this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox1.ForeColor = System.Drawing.SystemColors.ControlLightLight; + this.textBox1.Location = new System.Drawing.Point(3, 18); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(725, 219); + this.textBox1.TabIndex = 0; + this.textBox1.Text = "..."; + // + // groupBox3 + // + this.groupBox3.Controls.Add(this.textBox2); + this.groupBox3.Controls.Add(this.label6); + this.groupBox3.Controls.Add(this.txtSlot); + this.groupBox3.Controls.Add(this.label5); + this.groupBox3.Controls.Add(this.txtRack); + this.groupBox3.Controls.Add(this.label4); + this.groupBox3.Controls.Add(this.cbCpuType); + this.groupBox3.Controls.Add(this.txtIP); + this.groupBox3.Controls.Add(this.lblIP); + this.groupBox3.Controls.Add(this.label1); + this.groupBox3.Location = new System.Drawing.Point(12, 12); + this.groupBox3.Name = "groupBox3"; + this.groupBox3.Size = new System.Drawing.Size(448, 100); + this.groupBox3.TabIndex = 10; + this.groupBox3.TabStop = false; + this.groupBox3.Text = "Parametri PLC"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(208, 27); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(40, 17); + this.label4.TabIndex = 4; + this.label4.Text = "Rack"; + // + // txtRack + // + this.txtRack.Location = new System.Drawing.Point(254, 24); + this.txtRack.Name = "txtRack"; + this.txtRack.Size = new System.Drawing.Size(41, 22); + this.txtRack.TabIndex = 5; + this.txtRack.Text = "0"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(208, 64); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(32, 17); + this.label5.TabIndex = 4; + this.label5.Text = "Slot"; + // + // txtSlot + // + this.txtSlot.Location = new System.Drawing.Point(254, 61); + this.txtSlot.Name = "txtSlot"; + this.txtSlot.Size = new System.Drawing.Size(41, 22); + this.txtSlot.TabIndex = 5; + this.txtSlot.Text = "0"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(302, 14); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(114, 17); + this.label6.TabIndex = 6; + this.label6.Text = "Note Rack / Slot:"; + // + // textBox2 + // + this.textBox2.BackColor = System.Drawing.SystemColors.Menu; + this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.textBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.textBox2.Location = new System.Drawing.Point(302, 38); + this.textBox2.Multiline = true; + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(140, 54); + this.textBox2.TabIndex = 7; + this.textBox2.Text = "S7-1200/S7-1500: 0/0\r\nS7-300/S7-400: 0/2\r\nSlot > 0 se eth ext"; + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(755, 370); + this.Controls.Add(this.groupBox3); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.groupBox1); + this.Name = "MainForm"; + this.Text = "SIEMENS S7 TEST"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.groupBox3.ResumeLayout(false); + this.groupBox3.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox txtIP; + private System.Windows.Forms.Label lblIP; + private System.Windows.Forms.ComboBox cbCpuType; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txtMemArea; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtMemSize; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.TextBox txtSlot; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox txtRack; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.Label label6; + } +} + diff --git a/Test-S7/mAINfORM.cs b/Test-S7/mAINfORM.cs new file mode 100644 index 00000000..3e81c4b5 --- /dev/null +++ b/Test-S7/mAINfORM.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using S7.Net; + +namespace Test_S7 +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + + myInit(); + } + /// + /// inizializzo + /// + private void myInit() + { + CpuType tipoCpu = CpuType.S71200; + short slot = 0; + short rack = 0; + // leggo selezione... + try + { + tipoCpu = (CpuType)cbCpuType.SelectedValue; + short.TryParse(txtSlot.Text, out slot); + short.TryParse(txtRack.Text, out rack); + } + catch + { } + if (txtIP.Text != "" && rack >= 0 && slot >= 0) + { + using (var plc = new Plc(tipoCpu, txtIP.Text, rack, slot)) + { + plc.Open(); + } + } + } + } +} diff --git a/Test-S7/mAINfORM.resx b/Test-S7/mAINfORM.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/Test-S7/mAINfORM.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Test-S7/packages.config b/Test-S7/packages.config new file mode 100644 index 00000000..82c59874 --- /dev/null +++ b/Test-S7/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file