diff --git a/Test-S7/TestMainForm.Designer.cs b/Test-S7/TestMainForm.Designer.cs index a16dbd78..6a557dd6 100644 --- a/Test-S7/TestMainForm.Designer.cs +++ b/Test-S7/TestMainForm.Designer.cs @@ -76,7 +76,7 @@ // // txtIP // - this.txtIP.Location = new System.Drawing.Point(85, 24); + this.txtIP.Location = new System.Drawing.Point(85, 23); this.txtIP.Name = "txtIP"; this.txtIP.Size = new System.Drawing.Size(109, 22); this.txtIP.TabIndex = 0; @@ -86,7 +86,7 @@ // lblIP // this.lblIP.AutoSize = true; - this.lblIP.Location = new System.Drawing.Point(16, 27); + this.lblIP.Location = new System.Drawing.Point(16, 26); this.lblIP.Name = "lblIP"; this.lblIP.Size = new System.Drawing.Size(63, 17); this.lblIP.TabIndex = 1; @@ -120,7 +120,7 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(9, 24); + this.label2.Location = new System.Drawing.Point(9, 23); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(80, 17); this.label2.TabIndex = 5; @@ -128,9 +128,9 @@ // // txtMemArea // - this.txtMemArea.Location = new System.Drawing.Point(143, 21); + this.txtMemArea.Location = new System.Drawing.Point(156, 20); this.txtMemArea.Name = "txtMemArea"; - this.txtMemArea.Size = new System.Drawing.Size(130, 22); + this.txtMemArea.Size = new System.Drawing.Size(117, 22); this.txtMemArea.TabIndex = 4; this.txtMemArea.Text = "DB700.DBD0"; this.txtMemArea.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; @@ -147,9 +147,9 @@ // // txtMemSize // - this.txtMemSize.Location = new System.Drawing.Point(143, 78); + this.txtMemSize.Location = new System.Drawing.Point(156, 78); this.txtMemSize.Name = "txtMemSize"; - this.txtMemSize.Size = new System.Drawing.Size(130, 22); + this.txtMemSize.Size = new System.Drawing.Size(117, 22); this.txtMemSize.TabIndex = 6; this.txtMemSize.Text = "208"; this.txtMemSize.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; @@ -176,7 +176,7 @@ // // btnReadByte // - this.btnReadByte.Location = new System.Drawing.Point(172, 47); + this.btnReadByte.Location = new System.Drawing.Point(173, 47); this.btnReadByte.Name = "btnReadByte"; this.btnReadByte.Size = new System.Drawing.Size(101, 25); this.btnReadByte.TabIndex = 9; @@ -189,10 +189,10 @@ this.textBox1.BackColor = System.Drawing.SystemColors.Menu; 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(6, 44); + this.textBox1.Location = new System.Drawing.Point(12, 44); this.textBox1.Multiline = true; this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(133, 33); + this.textBox1.Size = new System.Drawing.Size(127, 33); this.textBox1.TabIndex = 8; this.textBox1.Text = "Indicare tipo memoria e size del tipo"; // @@ -284,7 +284,7 @@ // // txtRack // - this.txtRack.Location = new System.Drawing.Point(254, 24); + this.txtRack.Location = new System.Drawing.Point(254, 23); this.txtRack.Name = "txtRack"; this.txtRack.Size = new System.Drawing.Size(41, 22); this.txtRack.TabIndex = 5; @@ -294,7 +294,7 @@ // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(208, 27); + this.label4.Location = new System.Drawing.Point(208, 26); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(40, 17); this.label4.TabIndex = 4; @@ -438,7 +438,7 @@ this.txtWriteAddr1.Name = "txtWriteAddr1"; this.txtWriteAddr1.Size = new System.Drawing.Size(123, 22); this.txtWriteAddr1.TabIndex = 6; - this.txtWriteAddr1.Text = "DB700.DBW160"; + this.txtWriteAddr1.Text = "DB700.DBD160"; this.txtWriteAddr1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; // // label7 @@ -452,7 +452,7 @@ // // btnReadWord // - this.btnReadWord.Location = new System.Drawing.Point(279, 20); + this.btnReadWord.Location = new System.Drawing.Point(279, 19); this.btnReadWord.Name = "btnReadWord"; this.btnReadWord.Size = new System.Drawing.Size(101, 25); this.btnReadWord.TabIndex = 10; diff --git a/Test-S7/TestMainForm.cs b/Test-S7/TestMainForm.cs index 7d967499..bb379fa5 100644 --- a/Test-S7/TestMainForm.cs +++ b/Test-S7/TestMainForm.cs @@ -158,8 +158,8 @@ namespace Test_S7 string byteValB = ""; for (int i = 0; i < memByteRead.Length / 2; i++) { - byteValA = Convert.ToString(memByteRead[i], 2).PadLeft(8, '0'); - byteValB = Convert.ToString(memByteRead[i + 1], 2).PadLeft(8, '0'); + 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); } @@ -190,10 +190,10 @@ namespace Test_S7 string byteValD = ""; for (int i = 0; i < memByteRead.Length / 4; i++) { - byteValA = Convert.ToString(memByteRead[i], 2).PadLeft(8, '0'); - byteValB = Convert.ToString(memByteRead[i + 1], 2).PadLeft(8, '0'); - byteValC = Convert.ToString(memByteRead[i + 2], 2).PadLeft(8, '0'); - byteValD = Convert.ToString(memByteRead[i + 3], 2).PadLeft(8, '0'); + 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); } @@ -324,6 +324,37 @@ namespace Test_S7 lg.Info(outText); } + /// + /// Esecuzione SCRITTURA DWORD! + /// + private void eseguiScritturaDWord() + { + sw.Restart(); + if (testCncConn()) + { + // decodifico memoria... + memAddress memoria = new memAddress(txtWriteAddr1.Text); + uint num2write = 0; + uint.TryParse(txtWriteVal1.Text, out num2write); + byte[] DB_Byte = new byte[4]; + S7.Net.Types.DWord.ToByteArray(num2write).CopyTo(DB_Byte, 0); + //byte[] DB_Byte = BitConverter.GetBytes(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); + } + /// /// Scrivo memoria tipo NUM /// @@ -331,25 +362,8 @@ namespace Test_S7 /// private void btnNumWrite_Click(object sender, EventArgs e) { - if (testCncConn()) - { - // decodifico memoria... - memAddress memoria = new memAddress(txtWriteAddr1.Text); - int num2write = 0; - int.TryParse(txtWriteVal1.Text, out num2write); - byte[] outVal = BitConverter.GetBytes(num2write); - currPLC.WriteBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, outVal); - 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 < outVal.Length; i++) - { - byteVal = Convert.ToString(outVal[i], 2).PadLeft(8, '0'); - contenuto += string.Format("B{0:000}: {1} | {2}{3}", i, byteVal, outVal[i], Environment.NewLine); - } - showOut(titolo, contenuto); - } + setParamPlc(); + eseguiScritturaDWord(); } /// /// Scrivo memoria tipo STRING