From d21cb0510ccb055db155cb0e36259d6f996c79b7 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Thu, 28 Dec 2017 14:09:58 +0100 Subject: [PATCH] Modifiche per test VAUMARD in Jetco --- Test-S7/TestMainForm.Designer.cs | 138 +++++++++++++++++++------------ Test-S7/TestMainForm.cs | 97 +++++++++++++++++++--- 2 files changed, 167 insertions(+), 68 deletions(-) diff --git a/Test-S7/TestMainForm.Designer.cs b/Test-S7/TestMainForm.Designer.cs index 0c54fb65..29fc683d 100644 --- a/Test-S7/TestMainForm.Designer.cs +++ b/Test-S7/TestMainForm.Designer.cs @@ -40,6 +40,7 @@ this.btnReadString = new System.Windows.Forms.Button(); this.btnReadDWord = new System.Windows.Forms.Button(); this.btnReadWord = new System.Windows.Forms.Button(); + this.btnReadReal = new System.Windows.Forms.Button(); this.btnReadByte = new System.Windows.Forms.Button(); this.textBox1 = new System.Windows.Forms.TextBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); @@ -58,7 +59,7 @@ this.tslRTime = new System.Windows.Forms.ToolStripStatusLabel(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.btnStrWrite = new System.Windows.Forms.Button(); - this.btnNumWrite = new System.Windows.Forms.Button(); + this.btnNumWriteW = new System.Windows.Forms.Button(); this.txtWriteVal2 = new System.Windows.Forms.TextBox(); this.label9 = new System.Windows.Forms.Label(); this.txtWriteVal1 = new System.Windows.Forms.TextBox(); @@ -67,7 +68,8 @@ this.label10 = new System.Windows.Forms.Label(); this.txtWriteAddr1 = new System.Windows.Forms.TextBox(); this.label7 = new System.Windows.Forms.Label(); - this.btnReadReal = new System.Windows.Forms.Button(); + this.btnNumWriteDW = new System.Windows.Forms.Button(); + this.btnNumWriteB = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); @@ -78,11 +80,11 @@ // txtIP // this.txtIP.Location = new System.Drawing.Point(64, 19); - this.txtIP.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.txtIP.Margin = new System.Windows.Forms.Padding(2); this.txtIP.Name = "txtIP"; this.txtIP.Size = new System.Drawing.Size(83, 20); this.txtIP.TabIndex = 0; - this.txtIP.Text = "192.168.1.21"; + this.txtIP.Text = "192.168.1.208"; this.txtIP.TextChanged += new System.EventHandler(this.txtIP_TextChanged); // // lblIP @@ -105,7 +107,7 @@ "S71200", "S71500"}); this.cbCpuType.Location = new System.Drawing.Point(64, 50); - this.cbCpuType.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.cbCpuType.Margin = new System.Windows.Forms.Padding(2); this.cbCpuType.Name = "cbCpuType"; this.cbCpuType.Size = new System.Drawing.Size(83, 21); this.cbCpuType.TabIndex = 2; @@ -135,11 +137,11 @@ // txtMemArea // this.txtMemArea.Location = new System.Drawing.Point(117, 16); - this.txtMemArea.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.txtMemArea.Margin = new System.Windows.Forms.Padding(2); this.txtMemArea.Name = "txtMemArea"; this.txtMemArea.Size = new System.Drawing.Size(89, 20); this.txtMemArea.TabIndex = 4; - this.txtMemArea.Text = "DB700.DBD0"; + this.txtMemArea.Text = "DB700.DBB0"; this.txtMemArea.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; this.txtMemArea.TextChanged += new System.EventHandler(this.txtMemArea_TextChanged); // @@ -156,7 +158,7 @@ // txtMemSize // this.txtMemSize.Location = new System.Drawing.Point(117, 63); - this.txtMemSize.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.txtMemSize.Margin = new System.Windows.Forms.Padding(2); this.txtMemSize.Name = "txtMemSize"; this.txtMemSize.Size = new System.Drawing.Size(89, 20); this.txtMemSize.TabIndex = 6; @@ -178,9 +180,9 @@ this.groupBox1.Controls.Add(this.label3); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Location = new System.Drawing.Point(351, 10); - this.groupBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.groupBox1.Margin = new System.Windows.Forms.Padding(2); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.groupBox1.Padding = new System.Windows.Forms.Padding(2); this.groupBox1.Size = new System.Drawing.Size(290, 85); this.groupBox1.TabIndex = 8; this.groupBox1.TabStop = false; @@ -189,7 +191,7 @@ // btnReadString // this.btnReadString.Location = new System.Drawing.Point(209, 61); - this.btnReadString.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.btnReadString.Margin = new System.Windows.Forms.Padding(2); this.btnReadString.Name = "btnReadString"; this.btnReadString.Size = new System.Drawing.Size(76, 20); this.btnReadString.TabIndex = 11; @@ -200,7 +202,7 @@ // btnReadDWord // this.btnReadDWord.Location = new System.Drawing.Point(209, 38); - this.btnReadDWord.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.btnReadDWord.Margin = new System.Windows.Forms.Padding(2); this.btnReadDWord.Name = "btnReadDWord"; this.btnReadDWord.Size = new System.Drawing.Size(76, 20); this.btnReadDWord.TabIndex = 10; @@ -212,7 +214,7 @@ // btnReadWord // this.btnReadWord.Location = new System.Drawing.Point(209, 15); - this.btnReadWord.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.btnReadWord.Margin = new System.Windows.Forms.Padding(2); this.btnReadWord.Name = "btnReadWord"; this.btnReadWord.Size = new System.Drawing.Size(76, 20); this.btnReadWord.TabIndex = 10; @@ -220,10 +222,21 @@ this.btnReadWord.UseVisualStyleBackColor = true; this.btnReadWord.Click += new System.EventHandler(this.btnReadWord_Click); // + // btnReadReal + // + this.btnReadReal.Location = new System.Drawing.Point(176, 39); + this.btnReadReal.Margin = new System.Windows.Forms.Padding(2); + this.btnReadReal.Name = "btnReadReal"; + this.btnReadReal.Size = new System.Drawing.Size(30, 20); + this.btnReadReal.TabIndex = 9; + this.btnReadReal.Text = "REAL"; + this.btnReadReal.UseVisualStyleBackColor = true; + this.btnReadReal.Click += new System.EventHandler(this.btnReadReal_Click); + // // btnReadByte // this.btnReadByte.Location = new System.Drawing.Point(117, 38); - this.btnReadByte.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.btnReadByte.Margin = new System.Windows.Forms.Padding(2); this.btnReadByte.Name = "btnReadByte"; this.btnReadByte.Size = new System.Drawing.Size(55, 20); this.btnReadByte.TabIndex = 9; @@ -237,7 +250,7 @@ this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None; this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.textBox1.Location = new System.Drawing.Point(9, 36); - this.textBox1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.textBox1.Margin = new System.Windows.Forms.Padding(2); this.textBox1.Multiline = true; this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(95, 27); @@ -252,9 +265,9 @@ this.groupBox2.AutoSize = true; this.groupBox2.Controls.Add(this.txtOut); this.groupBox2.Location = new System.Drawing.Point(9, 154); - this.groupBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.groupBox2.Margin = new System.Windows.Forms.Padding(2); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.groupBox2.Padding = new System.Windows.Forms.Padding(2); this.groupBox2.Size = new System.Drawing.Size(632, 327); this.groupBox2.TabIndex = 9; this.groupBox2.TabStop = false; @@ -267,7 +280,7 @@ this.txtOut.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.txtOut.ForeColor = System.Drawing.Color.Yellow; this.txtOut.Location = new System.Drawing.Point(2, 15); - this.txtOut.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.txtOut.Margin = new System.Windows.Forms.Padding(2); this.txtOut.Multiline = true; this.txtOut.Name = "txtOut"; this.txtOut.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; @@ -288,9 +301,9 @@ this.groupBox3.Controls.Add(this.lblIP); this.groupBox3.Controls.Add(this.label1); this.groupBox3.Location = new System.Drawing.Point(9, 10); - this.groupBox3.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.groupBox3.Margin = new System.Windows.Forms.Padding(2); this.groupBox3.Name = "groupBox3"; - this.groupBox3.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.groupBox3.Padding = new System.Windows.Forms.Padding(2); this.groupBox3.Size = new System.Drawing.Size(336, 85); this.groupBox3.TabIndex = 10; this.groupBox3.TabStop = false; @@ -302,7 +315,7 @@ 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(226, 31); - this.textBox2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.textBox2.Margin = new System.Windows.Forms.Padding(2); this.textBox2.Multiline = true; this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(105, 44); @@ -322,7 +335,7 @@ // txtSlot // this.txtSlot.Location = new System.Drawing.Point(190, 50); - this.txtSlot.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.txtSlot.Margin = new System.Windows.Forms.Padding(2); this.txtSlot.Name = "txtSlot"; this.txtSlot.Size = new System.Drawing.Size(32, 20); this.txtSlot.TabIndex = 5; @@ -342,7 +355,7 @@ // txtRack // this.txtRack.Location = new System.Drawing.Point(190, 19); - this.txtRack.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.txtRack.Margin = new System.Windows.Forms.Padding(2); this.txtRack.Name = "txtRack"; this.txtRack.Size = new System.Drawing.Size(32, 20); this.txtRack.TabIndex = 5; @@ -402,7 +415,9 @@ this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox4.Controls.Add(this.btnStrWrite); - this.groupBox4.Controls.Add(this.btnNumWrite); + this.groupBox4.Controls.Add(this.btnNumWriteB); + this.groupBox4.Controls.Add(this.btnNumWriteDW); + this.groupBox4.Controls.Add(this.btnNumWriteW); this.groupBox4.Controls.Add(this.txtWriteVal2); this.groupBox4.Controls.Add(this.label9); this.groupBox4.Controls.Add(this.txtWriteVal1); @@ -412,9 +427,9 @@ this.groupBox4.Controls.Add(this.txtWriteAddr1); this.groupBox4.Controls.Add(this.label7); this.groupBox4.Location = new System.Drawing.Point(9, 95); - this.groupBox4.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.groupBox4.Margin = new System.Windows.Forms.Padding(2); this.groupBox4.Name = "groupBox4"; - this.groupBox4.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.groupBox4.Padding = new System.Windows.Forms.Padding(2); this.groupBox4.Size = new System.Drawing.Size(632, 58); this.groupBox4.TabIndex = 12; this.groupBox4.TabStop = false; @@ -423,29 +438,29 @@ // btnStrWrite // this.btnStrWrite.Location = new System.Drawing.Point(599, 20); - this.btnStrWrite.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.btnStrWrite.Margin = new System.Windows.Forms.Padding(2); this.btnStrWrite.Name = "btnStrWrite"; - this.btnStrWrite.Size = new System.Drawing.Size(26, 19); + this.btnStrWrite.Size = new System.Drawing.Size(31, 19); this.btnStrWrite.TabIndex = 10; - this.btnStrWrite.Text = "W"; + this.btnStrWrite.Text = "SW"; this.btnStrWrite.UseVisualStyleBackColor = true; this.btnStrWrite.Click += new System.EventHandler(this.btnStrWrite_Click); // - // btnNumWrite + // btnNumWriteW // - this.btnNumWrite.Location = new System.Drawing.Point(242, 20); - this.btnNumWrite.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); - this.btnNumWrite.Name = "btnNumWrite"; - this.btnNumWrite.Size = new System.Drawing.Size(28, 19); - this.btnNumWrite.TabIndex = 10; - this.btnNumWrite.Text = "W"; - this.btnNumWrite.UseVisualStyleBackColor = true; - this.btnNumWrite.Click += new System.EventHandler(this.btnNumWrite_Click); + this.btnNumWriteW.Location = new System.Drawing.Point(247, 19); + this.btnNumWriteW.Margin = new System.Windows.Forms.Padding(2); + this.btnNumWriteW.Name = "btnNumWriteW"; + this.btnNumWriteW.Size = new System.Drawing.Size(36, 19); + this.btnNumWriteW.TabIndex = 10; + this.btnNumWriteW.Text = "W"; + this.btnNumWriteW.UseVisualStyleBackColor = true; + this.btnNumWriteW.Click += new System.EventHandler(this.btnNumWriteW_Click); // // txtWriteVal2 // this.txtWriteVal2.Location = new System.Drawing.Point(459, 20); - this.txtWriteVal2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.txtWriteVal2.Margin = new System.Windows.Forms.Padding(2); this.txtWriteVal2.Name = "txtWriteVal2"; this.txtWriteVal2.Size = new System.Drawing.Size(141, 20); this.txtWriteVal2.TabIndex = 8; @@ -465,7 +480,7 @@ // txtWriteVal1 // this.txtWriteVal1.Location = new System.Drawing.Point(178, 20); - this.txtWriteVal1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.txtWriteVal1.Margin = new System.Windows.Forms.Padding(2); this.txtWriteVal1.Name = "txtWriteVal1"; this.txtWriteVal1.Size = new System.Drawing.Size(65, 20); this.txtWriteVal1.TabIndex = 8; @@ -485,11 +500,11 @@ // txtWriteAddr2 // this.txtWriteAddr2.Location = new System.Drawing.Point(336, 20); - this.txtWriteAddr2.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.txtWriteAddr2.Margin = new System.Windows.Forms.Padding(2); this.txtWriteAddr2.Name = "txtWriteAddr2"; this.txtWriteAddr2.Size = new System.Drawing.Size(88, 20); this.txtWriteAddr2.TabIndex = 6; - this.txtWriteAddr2.Text = "DB700.DBB0"; + this.txtWriteAddr2.Text = "DB701.DBB0"; this.txtWriteAddr2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; // // label10 @@ -505,11 +520,11 @@ // txtWriteAddr1 // this.txtWriteAddr1.Location = new System.Drawing.Point(53, 20); - this.txtWriteAddr1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.txtWriteAddr1.Margin = new System.Windows.Forms.Padding(2); this.txtWriteAddr1.Name = "txtWriteAddr1"; this.txtWriteAddr1.Size = new System.Drawing.Size(93, 20); this.txtWriteAddr1.TabIndex = 6; - this.txtWriteAddr1.Text = "DB700.DBD160"; + this.txtWriteAddr1.Text = "DB701.DBB0"; this.txtWriteAddr1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; // // label7 @@ -522,16 +537,27 @@ this.label7.TabIndex = 7; this.label7.Text = "ADDR 1"; // - // btnReadReal + // btnNumWriteDW // - this.btnReadReal.Location = new System.Drawing.Point(176, 39); - this.btnReadReal.Margin = new System.Windows.Forms.Padding(2); - this.btnReadReal.Name = "btnReadReal"; - this.btnReadReal.Size = new System.Drawing.Size(30, 20); - this.btnReadReal.TabIndex = 9; - this.btnReadReal.Text = "REAL"; - this.btnReadReal.UseVisualStyleBackColor = true; - this.btnReadReal.Click += new System.EventHandler(this.btnReadReal_Click); + this.btnNumWriteDW.Location = new System.Drawing.Point(247, 36); + this.btnNumWriteDW.Margin = new System.Windows.Forms.Padding(2); + this.btnNumWriteDW.Name = "btnNumWriteDW"; + this.btnNumWriteDW.Size = new System.Drawing.Size(36, 19); + this.btnNumWriteDW.TabIndex = 10; + this.btnNumWriteDW.Text = "DW"; + this.btnNumWriteDW.UseVisualStyleBackColor = true; + this.btnNumWriteDW.Click += new System.EventHandler(this.btnNumWriteDW_Click); + // + // btnNumWriteB + // + this.btnNumWriteB.Location = new System.Drawing.Point(247, 4); + this.btnNumWriteB.Margin = new System.Windows.Forms.Padding(2); + this.btnNumWriteB.Name = "btnNumWriteB"; + this.btnNumWriteB.Size = new System.Drawing.Size(36, 19); + this.btnNumWriteB.TabIndex = 10; + this.btnNumWriteB.Text = "B"; + this.btnNumWriteB.UseVisualStyleBackColor = true; + this.btnNumWriteB.Click += new System.EventHandler(this.btnNumWriteB_Click); // // TestMainForm // @@ -543,7 +569,7 @@ this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); - this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Margin = new System.Windows.Forms.Padding(2); this.Name = "TestMainForm"; this.Text = "SIEMENS S7 TEST"; this.groupBox1.ResumeLayout(false); @@ -590,7 +616,7 @@ private System.Windows.Forms.ToolStripStatusLabel tslRTime; private System.Windows.Forms.GroupBox groupBox4; private System.Windows.Forms.Button btnStrWrite; - private System.Windows.Forms.Button btnNumWrite; + private System.Windows.Forms.Button btnNumWriteW; private System.Windows.Forms.TextBox txtWriteVal2; private System.Windows.Forms.Label label9; private System.Windows.Forms.TextBox txtWriteVal1; @@ -603,6 +629,8 @@ private System.Windows.Forms.Button btnReadWord; private System.Windows.Forms.Button btnReadDWord; private System.Windows.Forms.Button btnReadReal; + private System.Windows.Forms.Button btnNumWriteB; + private System.Windows.Forms.Button btnNumWriteDW; } } diff --git a/Test-S7/TestMainForm.cs b/Test-S7/TestMainForm.cs index ef45eb2d..cdf6711a 100644 --- a/Test-S7/TestMainForm.cs +++ b/Test-S7/TestMainForm.cs @@ -299,7 +299,7 @@ namespace Test_S7 numByte = memByteRead[1]; // poi prendo la stringa... string outVal = ""; - for (int i = 2; i < numByte+2; i++) + for (int i = 2; i < numByte + 2; i++) { outVal += Char.ConvertFromUtf32(memByteRead[i]); } @@ -405,6 +405,66 @@ namespace Test_S7 lg.Info(outText); } + /// + /// Esecuzione SCRITTURA Byte! + /// + private void eseguiScritturaByte() + { + sw.Restart(); + if (testCncConn()) + { + // decodifico memoria... + memAddress memoria = new memAddress(txtWriteAddr1.Text); + byte num2write = 0; + string val2write = txtWriteVal2.Text; + byte.TryParse(txtWriteVal1.Text, out num2write); + byte[] DB_Byte = new byte[1]; + DB_Byte[0] = num2write; + currPLC.WriteBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, DB_Byte); + titolo = string.Format("WRITE BLOCK MEM: {0}", txtWriteAddr1.Text); + contenuto = ""; + contenuto += string.Format("DT: {0} | DbNum: {1} | indiceMem: {2} | num2write: {3}{4}{4}", DataType.DataBlock, memoria.DbNum, memoria.indiceMem, num2write, Environment.NewLine); + string byteVal = ""; + for (int i = 0; i < DB_Byte.Length; i++) + { + byteVal = Convert.ToString(DB_Byte[i], 2).PadLeft(8, '0'); + contenuto += string.Format("B{0:000}: {1} | {2}{3}", i, byteVal, DB_Byte[i], Environment.NewLine); + } + showOut(titolo, contenuto); + } + sw.Stop(); + tslRTime.Text = string.Format("{0}", sw.Elapsed); + } + /// + /// Esecuzione SCRITTURA WORD! + /// + private void eseguiScritturaWord() + { + sw.Restart(); + if (testCncConn()) + { + // decodifico memoria... + memAddress memoria = new memAddress(txtWriteAddr1.Text); + UInt16 num2write = 0; + string val2write = txtWriteVal2.Text; + UInt16.TryParse(txtWriteVal1.Text, out num2write); + byte[] DB_Byte = new byte[2]; + S7.Net.Types.Word.ToByteArray(num2write).CopyTo(DB_Byte, 0); + currPLC.WriteBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, DB_Byte); + titolo = string.Format("WRITE BLOCK MEM: {0}", txtWriteAddr1.Text); + contenuto = ""; + contenuto += string.Format("DT: {0} | DbNum: {1} | indiceMem: {2} | num2write: {3}{4}{4}", DataType.DataBlock, memoria.DbNum, memoria.indiceMem, num2write, Environment.NewLine); + string byteVal = ""; + for (int i = 0; i < DB_Byte.Length; i++) + { + byteVal = Convert.ToString(DB_Byte[i], 2).PadLeft(8, '0'); + contenuto += string.Format("B{0:000}: {1} | {2}{3}", i, byteVal, DB_Byte[i], Environment.NewLine); + } + showOut(titolo, contenuto); + } + sw.Stop(); + tslRTime.Text = string.Format("{0}", sw.Elapsed); + } /// /// Esecuzione SCRITTURA DWORD! /// @@ -453,7 +513,9 @@ namespace Test_S7 { val2write = val2write.Substring(0, 20); } - num2write = txtWriteVal2.Text.Length; + // scambio spazi con underscore... + val2write = val2write.Replace(' ', '_'); + num2write = val2write.Length; byte[] DB_Byte = new byte[maxStrChar + 2]; // primi 2 byte sono 20 (fix) e lung effettiva... DB_Byte[0] = 20; @@ -461,7 +523,7 @@ namespace Test_S7 // converto 1-1 i char in byte... for (int i = 0; i < num2write; i++) { - DB_Byte[2 + i] = (byte)(txtWriteVal2.Text[i]); + DB_Byte[2 + i] = (byte)(val2write[i]); } currPLC.WriteBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, DB_Byte); titolo = string.Format("WRITE BLOCK MEM: {0}", txtWriteAddr1.Text); @@ -473,16 +535,7 @@ namespace Test_S7 tslRTime.Text = string.Format("{0}", sw.Elapsed); } - /// - /// Scrivo memoria tipo NUM - /// - /// - /// - private void btnNumWrite_Click(object sender, EventArgs e) - { - setParamPlc(); - eseguiScritturaDWord(); - } + /// /// Scrivo memoria tipo STRING /// @@ -557,6 +610,24 @@ namespace Test_S7 setParamPlc(); eseguiLetturaReal(); } + + private void btnNumWriteB_Click(object sender, EventArgs e) + { + setParamPlc(); + eseguiScritturaByte(); + } + + private void btnNumWriteDW_Click(object sender, EventArgs e) + { + setParamPlc(); + eseguiScritturaDWord(); + } + + private void btnNumWriteW_Click(object sender, EventArgs e) + { + setParamPlc(); + eseguiScritturaWord(); + } } }