update test scrittura + lettura Word / DWord
This commit is contained in:
Generated
+138
-98
@@ -37,7 +37,7 @@
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.txtMemSize = new System.Windows.Forms.TextBox();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.btnRead = 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();
|
||||
this.txtOut = new System.Windows.Forms.TextBox();
|
||||
@@ -51,19 +51,22 @@
|
||||
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
|
||||
this.tslConn = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.tslRTime = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar();
|
||||
this.tslRTime = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.groupBox4 = new System.Windows.Forms.GroupBox();
|
||||
this.txtWriteAddr1 = new System.Windows.Forms.TextBox();
|
||||
this.label7 = new System.Windows.Forms.Label();
|
||||
this.btnStrWrite = new System.Windows.Forms.Button();
|
||||
this.btnNumWrite = 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();
|
||||
this.label8 = new System.Windows.Forms.Label();
|
||||
this.label9 = new System.Windows.Forms.Label();
|
||||
this.txtWriteVal2 = new System.Windows.Forms.TextBox();
|
||||
this.btnNumWrite = new System.Windows.Forms.Button();
|
||||
this.btnStrWrite = new System.Windows.Forms.Button();
|
||||
this.label10 = new System.Windows.Forms.Label();
|
||||
this.txtWriteAddr2 = new System.Windows.Forms.TextBox();
|
||||
this.label10 = new System.Windows.Forms.Label();
|
||||
this.txtWriteAddr1 = new System.Windows.Forms.TextBox();
|
||||
this.label7 = new System.Windows.Forms.Label();
|
||||
this.btnReadWord = new System.Windows.Forms.Button();
|
||||
this.btnReadString = new System.Windows.Forms.Button();
|
||||
this.btnReadDWord = new System.Windows.Forms.Button();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
this.groupBox3.SuspendLayout();
|
||||
@@ -127,7 +130,7 @@
|
||||
//
|
||||
this.txtMemArea.Location = new System.Drawing.Point(143, 21);
|
||||
this.txtMemArea.Name = "txtMemArea";
|
||||
this.txtMemArea.Size = new System.Drawing.Size(98, 22);
|
||||
this.txtMemArea.Size = new System.Drawing.Size(130, 22);
|
||||
this.txtMemArea.TabIndex = 4;
|
||||
this.txtMemArea.Text = "DB700.DBD0";
|
||||
this.txtMemArea.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
||||
@@ -146,7 +149,7 @@
|
||||
//
|
||||
this.txtMemSize.Location = new System.Drawing.Point(143, 78);
|
||||
this.txtMemSize.Name = "txtMemSize";
|
||||
this.txtMemSize.Size = new System.Drawing.Size(98, 22);
|
||||
this.txtMemSize.Size = new System.Drawing.Size(130, 22);
|
||||
this.txtMemSize.TabIndex = 6;
|
||||
this.txtMemSize.Text = "208";
|
||||
this.txtMemSize.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
||||
@@ -155,7 +158,10 @@
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.groupBox1.Controls.Add(this.btnRead);
|
||||
this.groupBox1.Controls.Add(this.btnReadString);
|
||||
this.groupBox1.Controls.Add(this.btnReadDWord);
|
||||
this.groupBox1.Controls.Add(this.btnReadWord);
|
||||
this.groupBox1.Controls.Add(this.btnReadByte);
|
||||
this.groupBox1.Controls.Add(this.textBox1);
|
||||
this.groupBox1.Controls.Add(this.txtMemArea);
|
||||
this.groupBox1.Controls.Add(this.txtMemSize);
|
||||
@@ -168,15 +174,15 @@
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Memoria: READ param";
|
||||
//
|
||||
// btnRead
|
||||
// btnReadByte
|
||||
//
|
||||
this.btnRead.Location = new System.Drawing.Point(279, 21);
|
||||
this.btnRead.Name = "btnRead";
|
||||
this.btnRead.Size = new System.Drawing.Size(101, 78);
|
||||
this.btnRead.TabIndex = 9;
|
||||
this.btnRead.Text = "READ";
|
||||
this.btnRead.UseVisualStyleBackColor = true;
|
||||
this.btnRead.Click += new System.EventHandler(this.btnRead_Click);
|
||||
this.btnReadByte.Location = new System.Drawing.Point(172, 47);
|
||||
this.btnReadByte.Name = "btnReadByte";
|
||||
this.btnReadByte.Size = new System.Drawing.Size(101, 25);
|
||||
this.btnReadByte.TabIndex = 9;
|
||||
this.btnReadByte.Text = "READ Byte";
|
||||
this.btnReadByte.UseVisualStyleBackColor = true;
|
||||
this.btnReadByte.Click += new System.EventHandler(this.btnReadByte_Click);
|
||||
//
|
||||
// textBox1
|
||||
//
|
||||
@@ -186,9 +192,9 @@
|
||||
this.textBox1.Location = new System.Drawing.Point(6, 44);
|
||||
this.textBox1.Multiline = true;
|
||||
this.textBox1.Name = "textBox1";
|
||||
this.textBox1.Size = new System.Drawing.Size(234, 33);
|
||||
this.textBox1.Size = new System.Drawing.Size(133, 33);
|
||||
this.textBox1.TabIndex = 8;
|
||||
this.textBox1.Text = "Indicare tipo memoria (es DBD) e size del tipo";
|
||||
this.textBox1.Text = "Indicare tipo memoria e size del tipo";
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
@@ -320,17 +326,17 @@
|
||||
this.toolStripStatusLabel1.Size = new System.Drawing.Size(13, 20);
|
||||
this.toolStripStatusLabel1.Text = "|";
|
||||
//
|
||||
// toolStripProgressBar1
|
||||
//
|
||||
this.toolStripProgressBar1.Name = "toolStripProgressBar1";
|
||||
this.toolStripProgressBar1.Size = new System.Drawing.Size(100, 19);
|
||||
//
|
||||
// tslRTime
|
||||
//
|
||||
this.tslRTime.Name = "tslRTime";
|
||||
this.tslRTime.Size = new System.Drawing.Size(37, 20);
|
||||
this.tslRTime.Text = "...ms";
|
||||
//
|
||||
// toolStripProgressBar1
|
||||
//
|
||||
this.toolStripProgressBar1.Name = "toolStripProgressBar1";
|
||||
this.toolStripProgressBar1.Size = new System.Drawing.Size(100, 19);
|
||||
//
|
||||
// groupBox4
|
||||
//
|
||||
this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
@@ -352,13 +358,87 @@
|
||||
this.groupBox4.TabStop = false;
|
||||
this.groupBox4.Text = "Memoria: WRITE param";
|
||||
//
|
||||
// btnStrWrite
|
||||
//
|
||||
this.btnStrWrite.Location = new System.Drawing.Point(799, 24);
|
||||
this.btnStrWrite.Name = "btnStrWrite";
|
||||
this.btnStrWrite.Size = new System.Drawing.Size(35, 23);
|
||||
this.btnStrWrite.TabIndex = 10;
|
||||
this.btnStrWrite.Text = "W";
|
||||
this.btnStrWrite.UseVisualStyleBackColor = true;
|
||||
this.btnStrWrite.Click += new System.EventHandler(this.btnStrWrite_Click);
|
||||
//
|
||||
// btnNumWrite
|
||||
//
|
||||
this.btnNumWrite.Location = new System.Drawing.Point(322, 24);
|
||||
this.btnNumWrite.Name = "btnNumWrite";
|
||||
this.btnNumWrite.Size = new System.Drawing.Size(38, 23);
|
||||
this.btnNumWrite.TabIndex = 10;
|
||||
this.btnNumWrite.Text = "W";
|
||||
this.btnNumWrite.UseVisualStyleBackColor = true;
|
||||
this.btnNumWrite.Click += new System.EventHandler(this.btnNumWrite_Click);
|
||||
//
|
||||
// txtWriteVal2
|
||||
//
|
||||
this.txtWriteVal2.Location = new System.Drawing.Point(612, 24);
|
||||
this.txtWriteVal2.Name = "txtWriteVal2";
|
||||
this.txtWriteVal2.Size = new System.Drawing.Size(187, 22);
|
||||
this.txtWriteVal2.TabIndex = 8;
|
||||
this.txtWriteVal2.Text = "PROVA";
|
||||
this.txtWriteVal2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
||||
//
|
||||
// label9
|
||||
//
|
||||
this.label9.AutoSize = true;
|
||||
this.label9.Location = new System.Drawing.Point(570, 27);
|
||||
this.label9.Name = "label9";
|
||||
this.label9.Size = new System.Drawing.Size(36, 17);
|
||||
this.label9.TabIndex = 9;
|
||||
this.label9.Text = "STR";
|
||||
//
|
||||
// txtWriteVal1
|
||||
//
|
||||
this.txtWriteVal1.Location = new System.Drawing.Point(237, 24);
|
||||
this.txtWriteVal1.Name = "txtWriteVal1";
|
||||
this.txtWriteVal1.Size = new System.Drawing.Size(85, 22);
|
||||
this.txtWriteVal1.TabIndex = 8;
|
||||
this.txtWriteVal1.Text = "987654321";
|
||||
this.txtWriteVal1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
||||
//
|
||||
// label8
|
||||
//
|
||||
this.label8.AutoSize = true;
|
||||
this.label8.Location = new System.Drawing.Point(197, 27);
|
||||
this.label8.Name = "label8";
|
||||
this.label8.Size = new System.Drawing.Size(39, 17);
|
||||
this.label8.TabIndex = 9;
|
||||
this.label8.Text = "NUM";
|
||||
//
|
||||
// txtWriteAddr2
|
||||
//
|
||||
this.txtWriteAddr2.Location = new System.Drawing.Point(448, 24);
|
||||
this.txtWriteAddr2.Name = "txtWriteAddr2";
|
||||
this.txtWriteAddr2.Size = new System.Drawing.Size(116, 22);
|
||||
this.txtWriteAddr2.TabIndex = 6;
|
||||
this.txtWriteAddr2.Text = "DB700.DBB44";
|
||||
this.txtWriteAddr2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
||||
//
|
||||
// label10
|
||||
//
|
||||
this.label10.AutoSize = true;
|
||||
this.label10.Location = new System.Drawing.Point(390, 27);
|
||||
this.label10.Name = "label10";
|
||||
this.label10.Size = new System.Drawing.Size(59, 17);
|
||||
this.label10.TabIndex = 7;
|
||||
this.label10.Text = "ADDR 2";
|
||||
//
|
||||
// txtWriteAddr1
|
||||
//
|
||||
this.txtWriteAddr1.Location = new System.Drawing.Point(71, 24);
|
||||
this.txtWriteAddr1.Name = "txtWriteAddr1";
|
||||
this.txtWriteAddr1.Size = new System.Drawing.Size(98, 22);
|
||||
this.txtWriteAddr1.Size = new System.Drawing.Size(123, 22);
|
||||
this.txtWriteAddr1.TabIndex = 6;
|
||||
this.txtWriteAddr1.Text = "DB700.DBD66";
|
||||
this.txtWriteAddr1.Text = "DB700.DBW160";
|
||||
this.txtWriteAddr1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
||||
//
|
||||
// label7
|
||||
@@ -370,79 +450,36 @@
|
||||
this.label7.TabIndex = 7;
|
||||
this.label7.Text = "ADDR 1";
|
||||
//
|
||||
// txtWriteVal1
|
||||
// btnReadWord
|
||||
//
|
||||
this.txtWriteVal1.Location = new System.Drawing.Point(220, 24);
|
||||
this.txtWriteVal1.Name = "txtWriteVal1";
|
||||
this.txtWriteVal1.Size = new System.Drawing.Size(85, 22);
|
||||
this.txtWriteVal1.TabIndex = 8;
|
||||
this.txtWriteVal1.Text = "987654321";
|
||||
this.txtWriteVal1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
||||
this.btnReadWord.Location = new System.Drawing.Point(279, 20);
|
||||
this.btnReadWord.Name = "btnReadWord";
|
||||
this.btnReadWord.Size = new System.Drawing.Size(101, 25);
|
||||
this.btnReadWord.TabIndex = 10;
|
||||
this.btnReadWord.Text = "READ Word";
|
||||
this.btnReadWord.UseVisualStyleBackColor = true;
|
||||
this.btnReadWord.Click += new System.EventHandler(this.btnReadWord_Click);
|
||||
//
|
||||
// label8
|
||||
// btnReadString
|
||||
//
|
||||
this.label8.AutoSize = true;
|
||||
this.label8.Location = new System.Drawing.Point(175, 27);
|
||||
this.label8.Name = "label8";
|
||||
this.label8.Size = new System.Drawing.Size(39, 17);
|
||||
this.label8.TabIndex = 9;
|
||||
this.label8.Text = "NUM";
|
||||
this.btnReadString.Location = new System.Drawing.Point(279, 75);
|
||||
this.btnReadString.Name = "btnReadString";
|
||||
this.btnReadString.Size = new System.Drawing.Size(101, 25);
|
||||
this.btnReadString.TabIndex = 11;
|
||||
this.btnReadString.Text = "READ String";
|
||||
this.btnReadString.UseVisualStyleBackColor = true;
|
||||
this.btnReadString.Click += new System.EventHandler(this.btnReadString_Click);
|
||||
//
|
||||
// label9
|
||||
// btnReadDWord
|
||||
//
|
||||
this.label9.AutoSize = true;
|
||||
this.label9.Location = new System.Drawing.Point(570, 27);
|
||||
this.label9.Name = "label9";
|
||||
this.label9.Size = new System.Drawing.Size(36, 17);
|
||||
this.label9.TabIndex = 9;
|
||||
this.label9.Text = "STR";
|
||||
//
|
||||
// txtWriteVal2
|
||||
//
|
||||
this.txtWriteVal2.Location = new System.Drawing.Point(612, 24);
|
||||
this.txtWriteVal2.Name = "txtWriteVal2";
|
||||
this.txtWriteVal2.Size = new System.Drawing.Size(187, 22);
|
||||
this.txtWriteVal2.TabIndex = 8;
|
||||
this.txtWriteVal2.Text = "PROVA";
|
||||
this.txtWriteVal2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
||||
//
|
||||
// btnNumWrite
|
||||
//
|
||||
this.btnNumWrite.Location = new System.Drawing.Point(305, 24);
|
||||
this.btnNumWrite.Name = "btnNumWrite";
|
||||
this.btnNumWrite.Size = new System.Drawing.Size(38, 23);
|
||||
this.btnNumWrite.TabIndex = 10;
|
||||
this.btnNumWrite.Text = "W";
|
||||
this.btnNumWrite.UseVisualStyleBackColor = true;
|
||||
this.btnNumWrite.Click += new System.EventHandler(this.btnNumWrite_Click);
|
||||
//
|
||||
// btnStrWrite
|
||||
//
|
||||
this.btnStrWrite.Location = new System.Drawing.Point(799, 24);
|
||||
this.btnStrWrite.Name = "btnStrWrite";
|
||||
this.btnStrWrite.Size = new System.Drawing.Size(35, 23);
|
||||
this.btnStrWrite.TabIndex = 10;
|
||||
this.btnStrWrite.Text = "W";
|
||||
this.btnStrWrite.UseVisualStyleBackColor = true;
|
||||
this.btnStrWrite.Click += new System.EventHandler(this.btnStrWrite_Click);
|
||||
//
|
||||
// label10
|
||||
//
|
||||
this.label10.AutoSize = true;
|
||||
this.label10.Location = new System.Drawing.Point(401, 27);
|
||||
this.label10.Name = "label10";
|
||||
this.label10.Size = new System.Drawing.Size(59, 17);
|
||||
this.label10.TabIndex = 7;
|
||||
this.label10.Text = "ADDR 2";
|
||||
//
|
||||
// txtWriteAddr2
|
||||
//
|
||||
this.txtWriteAddr2.Location = new System.Drawing.Point(466, 24);
|
||||
this.txtWriteAddr2.Name = "txtWriteAddr2";
|
||||
this.txtWriteAddr2.Size = new System.Drawing.Size(98, 22);
|
||||
this.txtWriteAddr2.TabIndex = 6;
|
||||
this.txtWriteAddr2.Text = "DB700.DBB44";
|
||||
this.txtWriteAddr2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
|
||||
this.btnReadDWord.Location = new System.Drawing.Point(279, 47);
|
||||
this.btnReadDWord.Name = "btnReadDWord";
|
||||
this.btnReadDWord.Size = new System.Drawing.Size(101, 25);
|
||||
this.btnReadDWord.TabIndex = 10;
|
||||
this.btnReadDWord.Text = "READ DW";
|
||||
this.btnReadDWord.TextImageRelation = System.Windows.Forms.TextImageRelation.TextAboveImage;
|
||||
this.btnReadDWord.UseVisualStyleBackColor = true;
|
||||
this.btnReadDWord.Click += new System.EventHandler(this.btnReadDWord_Click);
|
||||
//
|
||||
// TestMainForm
|
||||
//
|
||||
@@ -492,7 +529,7 @@
|
||||
private System.Windows.Forms.TextBox textBox2;
|
||||
private System.Windows.Forms.Label label6;
|
||||
private System.Windows.Forms.TextBox textBox1;
|
||||
private System.Windows.Forms.Button btnRead;
|
||||
private System.Windows.Forms.Button btnReadByte;
|
||||
private System.Windows.Forms.StatusStrip statusStrip1;
|
||||
private System.Windows.Forms.ToolStripStatusLabel tslConn;
|
||||
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
|
||||
@@ -509,6 +546,9 @@
|
||||
private System.Windows.Forms.Label label7;
|
||||
private System.Windows.Forms.TextBox txtWriteAddr2;
|
||||
private System.Windows.Forms.Label label10;
|
||||
private System.Windows.Forms.Button btnReadString;
|
||||
private System.Windows.Forms.Button btnReadWord;
|
||||
private System.Windows.Forms.Button btnReadDWord;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+169
-74
@@ -112,10 +112,129 @@ namespace Test_S7
|
||||
showOut(titolo, contenuto);
|
||||
}
|
||||
}
|
||||
|
||||
private void eseguiLettura()
|
||||
/// <summary>
|
||||
/// Esecuzione lettura!
|
||||
/// </summary>
|
||||
private void eseguiLetturaByte()
|
||||
{
|
||||
sw.Restart();
|
||||
if (testCncConn())
|
||||
{
|
||||
// decodifico memoria...
|
||||
memAddress memoria = new memAddress(txtMemArea.Text);
|
||||
int numByte = 1;
|
||||
int.TryParse(txtMemSize.Text, out numByte);
|
||||
Byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte);
|
||||
titolo = string.Format("READ BLOCK MEM BYTE: {0} --> {1} byte", txtMemArea.Text, numByte);
|
||||
contenuto = "";
|
||||
string byteVal = "";
|
||||
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);
|
||||
}
|
||||
showOut(titolo, contenuto);
|
||||
}
|
||||
sw.Stop();
|
||||
tslRTime.Text = string.Format("{0}", sw.Elapsed);
|
||||
}
|
||||
/// <summary>
|
||||
/// Esecuzione lettura WORD!
|
||||
/// </summary>
|
||||
private void eseguiLetturaWord()
|
||||
{
|
||||
sw.Restart();
|
||||
if (testCncConn())
|
||||
{
|
||||
// decodifico memoria...
|
||||
memAddress memoria = new memAddress(txtMemArea.Text);
|
||||
int numByte = 1;
|
||||
int.TryParse(txtMemSize.Text, out numByte);
|
||||
Byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte);
|
||||
titolo = string.Format("READ BLOCK MEM WORD: {0} --> {1} byte", txtMemArea.Text, numByte);
|
||||
contenuto = "";
|
||||
ushort shortVal = 0;
|
||||
string byteValA = "";
|
||||
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');
|
||||
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);
|
||||
}
|
||||
showOut(titolo, contenuto);
|
||||
}
|
||||
sw.Stop();
|
||||
tslRTime.Text = string.Format("{0}", sw.Elapsed);
|
||||
}
|
||||
/// <summary>
|
||||
/// Esecuzione lettura DWORD!
|
||||
/// </summary>
|
||||
private void eseguiLetturaDWord()
|
||||
{
|
||||
sw.Restart();
|
||||
if (testCncConn())
|
||||
{
|
||||
// decodifico memoria...
|
||||
memAddress memoria = new memAddress(txtMemArea.Text);
|
||||
int numByte = 1;
|
||||
int.TryParse(txtMemSize.Text, out numByte);
|
||||
Byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte);
|
||||
titolo = string.Format("READ BLOCK MEM WORD: {0} --> {1} byte", txtMemArea.Text, numByte);
|
||||
contenuto = "";
|
||||
uint intVal = 0;
|
||||
string byteValA = "";
|
||||
string byteValB = "";
|
||||
string byteValC = "";
|
||||
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');
|
||||
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);
|
||||
}
|
||||
showOut(titolo, contenuto);
|
||||
}
|
||||
sw.Stop();
|
||||
tslRTime.Text = string.Format("{0}", sw.Elapsed);
|
||||
}
|
||||
/// <summary>
|
||||
/// Esecuzione lettura tipo STRING!
|
||||
/// </summary>
|
||||
private void eseguiLetturaString()
|
||||
{
|
||||
sw.Restart();
|
||||
if (testCncConn())
|
||||
{
|
||||
// decodifico memoria...
|
||||
memAddress memoria = new memAddress(txtMemArea.Text);
|
||||
int numByte = 1;
|
||||
int.TryParse(txtMemSize.Text, out numByte);
|
||||
Byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte);
|
||||
titolo = string.Format("READ BLOCK MEM STRING: {0} --> {1} byte", txtMemArea.Text, numByte);
|
||||
contenuto = "";
|
||||
string byteVal = "";
|
||||
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);
|
||||
}
|
||||
showOut(titolo, contenuto);
|
||||
}
|
||||
sw.Stop();
|
||||
tslRTime.Text = string.Format("{0}", sw.Elapsed);
|
||||
}
|
||||
/// <summary>
|
||||
/// Test connessione CNC
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool testCncConn()
|
||||
{
|
||||
bool answ = false;
|
||||
IPStatus pingStatus = testPing();
|
||||
// se passa il ping faccio il resto...
|
||||
if (pingStatus != IPStatus.Success)
|
||||
@@ -126,53 +245,6 @@ namespace Test_S7
|
||||
}
|
||||
else
|
||||
{
|
||||
#if false
|
||||
//using (var plc = new Plc(parametri.tipoCpu, parametri.ipAdrr, parametri.rack, parametri.slot))
|
||||
//using (var plc = currPLC)
|
||||
//{
|
||||
var plc = currPLC;
|
||||
if (!plc.IsConnected) plc.Open();
|
||||
if (!plc.IsAvailable)
|
||||
{
|
||||
|
||||
titolo = "Errore Disponibilità";
|
||||
contenuto = string.Format("{0} | {1}", plc.LastErrorCode, plc.LastErrorString);
|
||||
plc.ClearLastError();
|
||||
showOut(titolo, contenuto);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!plc.IsConnected)
|
||||
{
|
||||
titolo = "Errore connessione";
|
||||
contenuto = string.Format("{0} | {1}", plc.LastErrorCode, plc.LastErrorString);
|
||||
plc.ClearLastError();
|
||||
showOut(titolo, contenuto);
|
||||
tslConn.Text = "NO Connection";
|
||||
}
|
||||
else
|
||||
{
|
||||
tslConn.Text = "Connection OK";
|
||||
|
||||
|
||||
// decodifico memoria...
|
||||
memAddress memoria = new memAddress(txtMemArea.Text);
|
||||
int numByte = 1;
|
||||
int.TryParse(txtMemSize.Text, out numByte);
|
||||
Byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte);
|
||||
titolo = string.Format("READ BLOCK MEM: {0} --> {1} byte", txtMemArea.Text, numByte);
|
||||
contenuto = "";
|
||||
string byteVal = "";
|
||||
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);
|
||||
}
|
||||
showOut(titolo, contenuto);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if (!currPLC.IsConnected) currPLC.Open();
|
||||
if (!currPLC.IsAvailable)
|
||||
{
|
||||
@@ -195,28 +267,13 @@ namespace Test_S7
|
||||
else
|
||||
{
|
||||
tslConn.Text = "Connection OK";
|
||||
|
||||
|
||||
// decodifico memoria...
|
||||
memAddress memoria = new memAddress(txtMemArea.Text);
|
||||
int numByte = 1;
|
||||
int.TryParse(txtMemSize.Text, out numByte);
|
||||
Byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte);
|
||||
titolo = string.Format("READ BLOCK MEM: {0} --> {1} byte", txtMemArea.Text, numByte);
|
||||
contenuto = "";
|
||||
string byteVal = "";
|
||||
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);
|
||||
}
|
||||
showOut(titolo, contenuto);
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
sw.Stop();
|
||||
tslRTime.Text = string.Format("{0}", sw.Elapsed);
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// test ping all'indirizzo impostato nei parametri
|
||||
/// </summary>
|
||||
@@ -267,12 +324,6 @@ namespace Test_S7
|
||||
lg.Info(outText);
|
||||
}
|
||||
|
||||
private void btnRead_Click(object sender, EventArgs e)
|
||||
{
|
||||
setParamPlc();
|
||||
eseguiLettura();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scrivo memoria tipo NUM
|
||||
/// </summary>
|
||||
@@ -280,7 +331,25 @@ namespace Test_S7
|
||||
/// <param name="e"></param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Scrivo memoria tipo STRING
|
||||
@@ -289,7 +358,10 @@ namespace Test_S7
|
||||
/// <param name="e"></param>
|
||||
private void btnStrWrite_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (testCncConn())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void txtIP_TextChanged(object sender, EventArgs e)
|
||||
@@ -321,6 +393,29 @@ namespace Test_S7
|
||||
{
|
||||
needRefresh = true;
|
||||
}
|
||||
|
||||
private void btnReadByte_Click(object sender, EventArgs e)
|
||||
{
|
||||
setParamPlc();
|
||||
eseguiLetturaByte();
|
||||
}
|
||||
|
||||
private void btnReadWord_Click(object sender, EventArgs e)
|
||||
{
|
||||
setParamPlc();
|
||||
eseguiLetturaWord();
|
||||
}
|
||||
|
||||
private void btnReadString_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void btnReadDWord_Click(object sender, EventArgs e)
|
||||
{
|
||||
setParamPlc();
|
||||
eseguiLetturaDWord();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user