metodo x display e deserializzazione inserito (da sistemare)

This commit is contained in:
Samuele Locatelli
2020-05-04 18:20:59 +02:00
parent 3ec2cbe0e9
commit ca1964c10d
5 changed files with 271 additions and 153 deletions
@@ -5,7 +5,7 @@ using System.Numerics;
namespace Siemens_S7_Test
{
public class BinaryFormatter : IFormatProvider, ICustomFormatter
public class BinaryFormat : IFormatProvider, ICustomFormatter
{
// IFormatProvider.GetFormat implementation.
public object GetFormat(Type formatType)
@@ -58,7 +58,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BinaryFormatter.cs" />
<Compile Include="BinaryFormat.cs" />
<Compile Include="connParam.cs" />
<Compile Include="memAddress.cs" />
<Compile Include="TestMainForm.cs">
+141 -122
View File
@@ -37,6 +37,8 @@
this.label3 = new System.Windows.Forms.Label();
this.txtMemSize = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtNumRep = new System.Windows.Forms.TextBox();
this.label13 = new System.Windows.Forms.Label();
this.btnReadStruct = new System.Windows.Forms.Button();
this.btnReadString = new System.Windows.Forms.Button();
this.btnReadDWord = new System.Windows.Forms.Button();
@@ -44,6 +46,7 @@
this.btnReadReal = new System.Windows.Forms.Button();
this.btnReadByte = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.label11 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.txtSlot = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
@@ -71,22 +74,20 @@
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.tabCtrl = new System.Windows.Forms.TabControl();
this.tabReadTest = new System.Windows.Forms.TabPage();
this.tabParam = new System.Windows.Forms.TabPage();
this.tabWriteTest = new System.Windows.Forms.TabPage();
this.tabParam = new System.Windows.Forms.TabPage();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.label11 = new System.Windows.Forms.Label();
this.txtNumRep = new System.Windows.Forms.TextBox();
this.label13 = new System.Windows.Forms.Label();
this.label12 = new System.Windows.Forms.Label();
this.label14 = new System.Windows.Forms.Label();
this.label15 = new System.Windows.Forms.Label();
this.label16 = new System.Windows.Forms.Label();
this.lblTimeAvg = new System.Windows.Forms.Label();
this.lblTimeMax = new System.Windows.Forms.Label();
this.lblTimeMin = new System.Windows.Forms.Label();
this.lblTotSize = new System.Windows.Forms.Label();
this.lblThroughtput = new System.Windows.Forms.Label();
this.label18 = new System.Windows.Forms.Label();
this.lblTotSize = new System.Windows.Forms.Label();
this.lblTimeMin = new System.Windows.Forms.Label();
this.lblTimeMax = new System.Windows.Forms.Label();
this.lblTimeAvg = new System.Windows.Forms.Label();
this.label16 = new System.Windows.Forms.Label();
this.label15 = new System.Windows.Forms.Label();
this.label14 = new System.Windows.Forms.Label();
this.label12 = new System.Windows.Forms.Label();
this.cmbOutType = new System.Windows.Forms.ComboBox();
this.groupBox1.SuspendLayout();
this.groupBox3.SuspendLayout();
this.statusStrip1.SuspendLayout();
@@ -94,8 +95,8 @@
this.groupBox2.SuspendLayout();
this.tabCtrl.SuspendLayout();
this.tabReadTest.SuspendLayout();
this.tabParam.SuspendLayout();
this.tabWriteTest.SuspendLayout();
this.tabParam.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
@@ -189,6 +190,7 @@
//
// groupBox1
//
this.groupBox1.Controls.Add(this.cmbOutType);
this.groupBox1.Controls.Add(this.txtNumRep);
this.groupBox1.Controls.Add(this.label13);
this.groupBox1.Controls.Add(this.btnReadStruct);
@@ -205,11 +207,30 @@
this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox1.Size = new System.Drawing.Size(521, 105);
this.groupBox1.Size = new System.Drawing.Size(672, 105);
this.groupBox1.TabIndex = 8;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Memoria: READ testing";
//
// txtNumRep
//
this.txtNumRep.Location = new System.Drawing.Point(148, 76);
this.txtNumRep.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtNumRep.Name = "txtNumRep";
this.txtNumRep.Size = new System.Drawing.Size(101, 22);
this.txtNumRep.TabIndex = 14;
this.txtNumRep.Text = "1";
this.txtNumRep.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// label13
//
this.label13.AutoSize = true;
this.label13.Location = new System.Drawing.Point(9, 79);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(72, 17);
this.label13.TabIndex = 15;
this.label13.Text = "# samples";
//
// btnReadStruct
//
this.btnReadStruct.Location = new System.Drawing.Point(405, 75);
@@ -299,6 +320,15 @@
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Parametri PLC";
//
// label11
//
this.label11.AutoSize = true;
this.label11.Location = new System.Drawing.Point(301, 39);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(148, 51);
this.label11.TabIndex = 7;
this.label11.Text = "S7-1200/S7-1500: 0/1\r\nS7-300/S7-400: 0/2\r\nSlot > 0 se eth ext";
//
// label6
//
this.label6.AutoSize = true;
@@ -581,27 +611,27 @@
this.tabReadTest.Text = "Read Test";
this.tabReadTest.UseVisualStyleBackColor = true;
//
// tabWriteTest
//
this.tabWriteTest.Controls.Add(this.groupBox4);
this.tabWriteTest.Location = new System.Drawing.Point(4, 25);
this.tabWriteTest.Name = "tabWriteTest";
this.tabWriteTest.Size = new System.Drawing.Size(871, 114);
this.tabWriteTest.TabIndex = 2;
this.tabWriteTest.Text = "Write Test";
this.tabWriteTest.UseVisualStyleBackColor = true;
//
// tabParam
//
this.tabParam.Controls.Add(this.groupBox3);
this.tabParam.Location = new System.Drawing.Point(4, 25);
this.tabParam.Name = "tabParam";
this.tabParam.Padding = new System.Windows.Forms.Padding(3);
this.tabParam.Size = new System.Drawing.Size(878, 118);
this.tabParam.Size = new System.Drawing.Size(871, 114);
this.tabParam.TabIndex = 1;
this.tabParam.Text = "Parametri";
this.tabParam.UseVisualStyleBackColor = true;
//
// tabWriteTest
//
this.tabWriteTest.Controls.Add(this.groupBox4);
this.tabWriteTest.Location = new System.Drawing.Point(4, 25);
this.tabWriteTest.Name = "tabWriteTest";
this.tabWriteTest.Size = new System.Drawing.Size(878, 118);
this.tabWriteTest.TabIndex = 2;
this.tabWriteTest.Text = "Write Test";
this.tabWriteTest.UseVisualStyleBackColor = true;
//
// splitContainer1
//
this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@@ -630,70 +660,56 @@
this.splitContainer1.SplitterDistance = 291;
this.splitContainer1.TabIndex = 15;
//
// label11
// lblThroughtput
//
this.label11.AutoSize = true;
this.label11.Location = new System.Drawing.Point(301, 39);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(148, 51);
this.label11.TabIndex = 7;
this.label11.Text = "S7-1200/S7-1500: 0/1\r\nS7-300/S7-400: 0/2\r\nSlot > 0 se eth ext";
this.lblThroughtput.AutoSize = true;
this.lblThroughtput.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblThroughtput.Location = new System.Drawing.Point(224, 105);
this.lblThroughtput.Name = "lblThroughtput";
this.lblThroughtput.Size = new System.Drawing.Size(35, 17);
this.lblThroughtput.TabIndex = 9;
this.lblThroughtput.Text = "000";
this.lblThroughtput.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// txtNumRep
// label18
//
this.txtNumRep.Location = new System.Drawing.Point(148, 76);
this.txtNumRep.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtNumRep.Name = "txtNumRep";
this.txtNumRep.Size = new System.Drawing.Size(101, 22);
this.txtNumRep.TabIndex = 14;
this.txtNumRep.Text = "1";
this.txtNumRep.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.label18.AutoSize = true;
this.label18.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label18.Location = new System.Drawing.Point(19, 105);
this.label18.Name = "label18";
this.label18.Size = new System.Drawing.Size(57, 17);
this.label18.TabIndex = 8;
this.label18.Text = "Kb/sec";
//
// label13
// lblTotSize
//
this.label13.AutoSize = true;
this.label13.Location = new System.Drawing.Point(9, 79);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(90, 21);
this.label13.TabIndex = 15;
this.label13.Text = "# samples";
this.lblTotSize.AutoSize = true;
this.lblTotSize.Location = new System.Drawing.Point(227, 20);
this.lblTotSize.Name = "lblTotSize";
this.lblTotSize.Size = new System.Drawing.Size(32, 17);
this.lblTotSize.TabIndex = 7;
this.lblTotSize.Text = "000";
this.lblTotSize.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// label12
// lblTimeMin
//
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(19, 20);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(58, 17);
this.label12.TabIndex = 0;
this.label12.Text = "Tot size";
this.lblTimeMin.AutoSize = true;
this.lblTimeMin.Location = new System.Drawing.Point(227, 41);
this.lblTimeMin.Name = "lblTimeMin";
this.lblTimeMin.Size = new System.Drawing.Size(32, 17);
this.lblTimeMin.TabIndex = 6;
this.lblTimeMin.Text = "000";
this.lblTimeMin.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// label14
// lblTimeMax
//
this.label14.AutoSize = true;
this.label14.Location = new System.Drawing.Point(19, 41);
this.label14.Name = "label14";
this.label14.Size = new System.Drawing.Size(70, 17);
this.label14.TabIndex = 1;
this.label14.Text = "TIME: min";
//
// label15
//
this.label15.AutoSize = true;
this.label15.Location = new System.Drawing.Point(19, 75);
this.label15.Name = "label15";
this.label15.Size = new System.Drawing.Size(73, 17);
this.label15.TabIndex = 2;
this.label15.Text = "TIME: max";
//
// label16
//
this.label16.AutoSize = true;
this.label16.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label16.Location = new System.Drawing.Point(19, 58);
this.label16.Name = "label16";
this.label16.Size = new System.Drawing.Size(80, 17);
this.label16.TabIndex = 3;
this.label16.Text = "TIME: avg";
this.lblTimeMax.AutoSize = true;
this.lblTimeMax.Location = new System.Drawing.Point(227, 75);
this.lblTimeMax.Name = "lblTimeMax";
this.lblTimeMax.Size = new System.Drawing.Size(32, 17);
this.lblTimeMax.TabIndex = 5;
this.lblTimeMax.Text = "000";
this.lblTimeMax.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// lblTimeAvg
//
@@ -706,56 +722,58 @@
this.lblTimeAvg.Text = "000";
this.lblTimeAvg.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// lblTimeMax
// label16
//
this.lblTimeMax.AutoSize = true;
this.lblTimeMax.Location = new System.Drawing.Point(227, 75);
this.lblTimeMax.Name = "lblTimeMax";
this.lblTimeMax.Size = new System.Drawing.Size(32, 17);
this.lblTimeMax.TabIndex = 5;
this.lblTimeMax.Text = "000";
this.lblTimeMax.TextAlign = System.Drawing.ContentAlignment.TopRight;
this.label16.AutoSize = true;
this.label16.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label16.Location = new System.Drawing.Point(19, 58);
this.label16.Name = "label16";
this.label16.Size = new System.Drawing.Size(80, 17);
this.label16.TabIndex = 3;
this.label16.Text = "TIME: avg";
//
// lblTimeMin
// label15
//
this.lblTimeMin.AutoSize = true;
this.lblTimeMin.Location = new System.Drawing.Point(227, 41);
this.lblTimeMin.Name = "lblTimeMin";
this.lblTimeMin.Size = new System.Drawing.Size(32, 17);
this.lblTimeMin.TabIndex = 6;
this.lblTimeMin.Text = "000";
this.lblTimeMin.TextAlign = System.Drawing.ContentAlignment.TopRight;
this.label15.AutoSize = true;
this.label15.Location = new System.Drawing.Point(19, 75);
this.label15.Name = "label15";
this.label15.Size = new System.Drawing.Size(73, 17);
this.label15.TabIndex = 2;
this.label15.Text = "TIME: max";
//
// lblTotSize
// label14
//
this.lblTotSize.AutoSize = true;
this.lblTotSize.Location = new System.Drawing.Point(227, 20);
this.lblTotSize.Name = "lblTotSize";
this.lblTotSize.Size = new System.Drawing.Size(32, 17);
this.lblTotSize.TabIndex = 7;
this.lblTotSize.Text = "000";
this.lblTotSize.TextAlign = System.Drawing.ContentAlignment.TopRight;
this.label14.AutoSize = true;
this.label14.Location = new System.Drawing.Point(19, 41);
this.label14.Name = "label14";
this.label14.Size = new System.Drawing.Size(70, 17);
this.label14.TabIndex = 1;
this.label14.Text = "TIME: min";
//
// lblThroughtput
// label12
//
this.lblThroughtput.AutoSize = true;
this.lblThroughtput.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblThroughtput.Location = new System.Drawing.Point(224, 126);
this.lblThroughtput.Name = "lblThroughtput";
this.lblThroughtput.Size = new System.Drawing.Size(35, 17);
this.lblThroughtput.TabIndex = 9;
this.lblThroughtput.Text = "000";
this.lblThroughtput.TextAlign = System.Drawing.ContentAlignment.TopRight;
this.label12.AutoSize = true;
this.label12.Location = new System.Drawing.Point(19, 20);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(58, 17);
this.label12.TabIndex = 0;
this.label12.Text = "Tot size";
//
// label18
// cmbOutType
//
this.label18.AutoSize = true;
this.label18.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label18.Location = new System.Drawing.Point(19, 126);
this.label18.Name = "label18";
this.label18.Size = new System.Drawing.Size(71, 21);
this.label18.TabIndex = 8;
this.label18.Text = "Kb/sec";
this.cmbOutType.FormattingEnabled = true;
this.cmbOutType.Items.AddRange(new object[] {
"byte",
"word",
"dword",
"real",
"struct"});
this.cmbOutType.Location = new System.Drawing.Point(522, 23);
this.cmbOutType.Name = "cmbOutType";
this.cmbOutType.Size = new System.Drawing.Size(121, 24);
this.cmbOutType.TabIndex = 16;
this.cmbOutType.Text = "byte";
this.cmbOutType.SelectedIndexChanged += new System.EventHandler(this.cmbOutType_SelectedIndexChanged);
//
// TestMainForm
//
@@ -780,8 +798,8 @@
this.groupBox2.PerformLayout();
this.tabCtrl.ResumeLayout(false);
this.tabReadTest.ResumeLayout(false);
this.tabParam.ResumeLayout(false);
this.tabWriteTest.ResumeLayout(false);
this.tabParam.ResumeLayout(false);
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel1.PerformLayout();
this.splitContainer1.Panel2.ResumeLayout(false);
@@ -854,6 +872,7 @@
private System.Windows.Forms.Label label12;
private System.Windows.Forms.Label lblThroughtput;
private System.Windows.Forms.Label label18;
private System.Windows.Forms.ComboBox cmbOutType;
}
}
+89 -9
View File
@@ -12,6 +12,8 @@ using System.Net.NetworkInformation;
using System.Net;
using NLog;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace Siemens_S7_Test
{
@@ -65,6 +67,10 @@ namespace Siemens_S7_Test
/// Gestione statistiche
/// </summary>
public TimingData PerfStats;
/// <summary>
/// Array oggetti letti
/// </summary>
protected Byte[] memByteRead = new byte[0];
public TestMainForm()
{
@@ -178,7 +184,6 @@ namespace Siemens_S7_Test
int.TryParse(txtMemSize.Text, out numByte);
int numTest = 1;
int.TryParse(txtNumRep.Text, out numTest);
Byte[] memByteRead = new byte[0];
// effettuo numero di test secondo indicazioni...
for (int i = 0; i < numTest; i++)
{
@@ -197,6 +202,8 @@ namespace Siemens_S7_Test
titolo = string.Format("READ BLOCK MEM BYTE: {0} --> {1} byte", txtMemArea.Text, numByte);
contenuto = "";
string byteVal = "";
// verifico se mostrare dati in modalità struct o meno...
for (int i = 0; i < memByteRead.Length; i++)
{
byteVal = Convert.ToString(memByteRead[i], 2).PadLeft(8, '0');
@@ -219,7 +226,6 @@ namespace Siemens_S7_Test
int.TryParse(txtMemSize.Text, out numByte);
int numTest = 1;
int.TryParse(txtNumRep.Text, out numTest);
Byte[] memByteRead = new byte[0];
// effettuo numero di test secondo indicazioni...
for (int i = 0; i < numTest; i++)
{
@@ -265,7 +271,6 @@ namespace Siemens_S7_Test
int.TryParse(txtMemSize.Text, out numByte);
int numTest = 1;
int.TryParse(txtNumRep.Text, out numTest);
Byte[] memByteRead = new byte[0];
for (int i = 0; i < numTest; i++)
{
sw.Restart();
@@ -318,7 +323,7 @@ namespace Siemens_S7_Test
List<ThermoParam> ElencoParametri = new List<ThermoParam>();
for (int i = 0; i < numPar; i++)
{
objPar = (ThermoParam)currPLC.ReadStruct<ThermoParam>(600, i * 20);
objPar = (ThermoParam)currPLC.ReadClass<ThermoParam>(600, i * 20);
ElencoParametri.Add(objPar);
}
sw.Stop();
@@ -525,25 +530,95 @@ namespace Siemens_S7_Test
string answ = "";
try
{
answ = string.Format(new BinaryFormatter(), "{0:B}", valore);
answ = string.Format(new BinaryFormat(), "{0:B}", valore);
}
catch
{ }
return answ;
}
/// <summary>
/// aggiorna display in base a selezione tipo output...
/// </summary>
/// <param name="title"></param>
/// <param name="content"></param>
protected void showOut(string title, string content)
{
// verifico combo e formatto...
contenuto = "";
string byteVal = "";
ushort shortVal = 0;
uint intVal = 0;
string byteValA = "";
string byteValB = "";
string byteValC = "";
string byteValD = "";
// verifico come mostrare dati (byte, word, struct ...)
switch (cmbOutType.SelectedItem)
{
case "word":
for (int i = 0; i < memByteRead.Length / 2; i++)
{
byteValA = Convert.ToString(memByteRead[i * 2], 2).PadLeft(8, '0');
byteValB = Convert.ToString(memByteRead[i * 2 + 1], 2).PadLeft(8, '0');
shortVal = S7.Net.Types.Word.FromByteArray(memByteRead.Skip(2 * i).Take(2).ToArray());
contenuto += string.Format("W{0:000}: {1} | {2}-{3}{4}", i, shortVal, byteValA, byteValB, Environment.NewLine);
}
break;
case "dword":
for (int i = 0; i < memByteRead.Length / 4; i++)
{
byteValA = Convert.ToString(memByteRead[i * 4], 2).PadLeft(8, '0');
byteValB = Convert.ToString(memByteRead[i * 4 + 1], 2).PadLeft(8, '0');
byteValC = Convert.ToString(memByteRead[i * 4 + 2], 2).PadLeft(8, '0');
byteValD = Convert.ToString(memByteRead[i * 4 + 3], 2).PadLeft(8, '0');
intVal = S7.Net.Types.DWord.FromByteArray(memByteRead.Skip(4 * i).Take(4).ToArray());
contenuto += string.Format("W{0:000}: {1} | {2}-{3}-{4}-{5}{6}", i, intVal, byteValA, byteValB, byteValC, byteValD, Environment.NewLine);
}
break;
case "struct":
ThermoParam objPar = new ThermoParam();
List<ThermoParam> ElencoParametri = new List<ThermoParam>();
IFormatter formatter = new BinaryFormatter();
// procedo 20 byte alla volta...
for (int i = 0; i < memByteRead.Length / 20; i++)
{
objPar = SerDeserExtensions.Deserializer<ThermoParam>(memByteRead.Skip(20 * i).Take(20).ToArray());
ElencoParametri.Add(objPar);
}
foreach (var item in ElencoParametri)
{
contenuto += $"Id: {item.Id}{Environment.NewLine}";
contenuto += $"SetpointHMI: {item.SetpointHMI}{Environment.NewLine}";
contenuto += $"SetpointPLC: {item.SetpointPLC}{Environment.NewLine}";
contenuto += $"ValMin: {item.ValMin}{Environment.NewLine}";
contenuto += $"ValMax: {item.ValMax}{Environment.NewLine}";
contenuto += $"UnitMeasure: {item.UnitMeasure}{Environment.NewLine}";
contenuto += $"---------{Environment.NewLine}";
}
break;
case "byte":
default:
for (int i = 0; i < memByteRead.Length; i++)
{
byteVal = Convert.ToString(memByteRead[i], 2).PadLeft(8, '0');
contenuto += string.Format("B{0:000}: {1} | {2}{3}", i, byteVal, memByteRead[i], Environment.NewLine);
}
break;
}
string outText = "";
// a video
outText += string.Format("{0}--------------------------------------------------------------------------------------{0}", Environment.NewLine);
outText += string.Format("- {0}{1}", title, Environment.NewLine);
outText += string.Format("- {0}{1}", titolo, Environment.NewLine);
outText += string.Format("--------------------------------------------------------------------------------------{0}", Environment.NewLine);
outText += string.Format("{0}{1}", content, Environment.NewLine);
outText += string.Format("{0}{1}", contenuto, Environment.NewLine);
outText += string.Format("--------------------------------------------------------------------------------------{0}{0}", Environment.NewLine);
// aggiorno visualizzazione
txtOut.Text += outText;
txtOut.Text = outText;
// loggo!
lg.Info(outText);
}
@@ -778,6 +853,11 @@ namespace Siemens_S7_Test
setParamPlc();
eseguiLetturaStruct();
}
private void cmbOutType_SelectedIndexChanged(object sender, EventArgs e)
{
showOut("", "");
}
}
}
+39 -20
View File
@@ -1,12 +1,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
namespace Siemens_S7_Test
{
public struct ThermoParam
[Serializable]
public class ThermoParam
{
public ushort Id;
public UInt32 SetpointHMI;
@@ -16,25 +20,40 @@ namespace Siemens_S7_Test
public ushort UnitMeasure;
}
public class ParamsList
//public T Deserialize<T>(byte[] param)
//{
// using (MemoryStream ms = new MemoryStream(param))
// {
// IFormatter br = new BinaryFormatter();
// return (T)br.Deserialize(ms);
// }
//}
public static class SerDeserExtensions
{
public ThermoParam par_000 { get; set; }
public ThermoParam par_001 { get; set; }
public ThermoParam par_002 { get; set; }
//public List<ThermoParam> Elenco { get; set; }
//public ParamsList()
//{
// Elenco = new List<ThermoParam>();
// ThermoParam currParam = new ThermoParam();
// // inizializzo subito coi valori...
// for (ushort i = 0; i < 2; i++)
// {
// currParam = new ThermoParam()
// {
// Id = i
// };
// Elenco.Add(currParam);
// }
//}
public static byte[] Serializer(this object _object)
{
byte[] bytes;
using (var _MemoryStream = new MemoryStream())
{
IFormatter _BinaryFormatter = new BinaryFormatter();
_BinaryFormatter.Serialize(_MemoryStream, _object);
bytes = _MemoryStream.ToArray();
}
return bytes;
}
public static T Deserializer<T>(this byte[] _byteArray)
{
T ReturnValue;
using (var _MemoryStream = new MemoryStream(_byteArray))
{
IFormatter _BinaryFormatter = new BinaryFormatter();
ReturnValue = (T)_BinaryFormatter.Deserialize(_MemoryStream);
}
return ReturnValue;
}
}
}