Escolar Documentos
Profissional Documentos
Cultura Documentos
Conforme foi discutido em sala de aula melhorias foram implementadas, foram enfrentados
alguns problemas de linguagem de programação então realizei a mudança de Python para
Visual Studio/C#.
Código de Form1:
using Opc.UaFx.Client;
using System.Net.Sockets;
namespace OPC_UA_PINE9_FINAL
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double torque;
torque = Convert.ToDouble(textBox1.Text);
client.WriteNode(tagName, torque);
client.Disconnect();
}
textBox2.Text = torque.ToString();
client.Disconnect();
}
double velocidade;
velocidade = Convert.ToDouble(textBox3.Text);
client.WriteNode(tagName, velocidade);
client.Disconnect();
textBox4.Text = velocidade.ToString();
client.Disconnect();
double producao;
producao = Convert.ToDouble(textBox5.Text);
client.WriteNode(tagName, producao);
client.Disconnect();
textBox6.Text = producao.ToString();
client.Disconnect();
}
double pressao;
pressao = Convert.ToDouble(textBox7.Text);
client.WriteNode(tagName, pressao);
client.Disconnect();
}
textBox8.Text = pressao.ToString();
client.Disconnect();
}
status = Convert.ToDouble(textBox9.Text);
client.WriteNode(tagName, status);
client.Disconnect();
}
textBox10.Text = status.ToString();
client.Disconnect();
}
}
}
Código Form1.Designer.cs
namespace OPC_UA_PINE9_FINAL
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed;
otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
textBox1 = new TextBox();
textBox2 = new TextBox();
TorqueButon1 = new Button();
TorqueButon2 = new Button();
textBox3 = new TextBox();
textBox4 = new TextBox();
textBox5 = new TextBox();
textBox6 = new TextBox();
textBox7 = new TextBox();
textBox8 = new TextBox();
textBox9 = new TextBox();
textBox10 = new TextBox();
Velocidade_buton1 = new Button();
Velocidade_buton2 = new Button();
Producao_buton1 = new Button();
Producao_buton2 = new Button();
Pressao_buton1 = new Button();
Pressao_buton2 = new Button();
Status_buton1 = new Button();
Status_buton2 = new Button();
SuspendLayout();
//
// textBox1
//
textBox1.Location = new Point(12, 12);
textBox1.Name = "textBox1";
textBox1.Size = new Size(156, 23);
textBox1.TabIndex = 0;
//
// textBox2
//
textBox2.Location = new Point(445, 12);
textBox2.Name = "textBox2";
textBox2.Size = new Size(156, 23);
textBox2.TabIndex = 1;
//
// TorqueButon1
//
TorqueButon1.Location = new Point(174, 11);
TorqueButon1.Name = "TorqueButon1";
TorqueButon1.Size = new Size(103, 23);
TorqueButon1.TabIndex = 2;
TorqueButon1.Text = "Torque_Escrever";
TorqueButon1.UseVisualStyleBackColor = true;
TorqueButon1.Click += Button1_Click;
//
// TorqueButon2
//
TorqueButon2.Location = new Point(336, 12);
TorqueButon2.Name = "TorqueButon2";
TorqueButon2.Size = new Size(103, 23);
TorqueButon2.TabIndex = 0;
TorqueButon2.Text = "Torque_Ler";
TorqueButon2.Click += TorqueButon2_Click;
//
// textBox3
//
textBox3.Location = new Point(12, 53);
textBox3.Name = "textBox3";
textBox3.Size = new Size(156, 23);
textBox3.TabIndex = 3;
//
// textBox4
//
textBox4.Location = new Point(445, 53);
textBox4.Name = "textBox4";
textBox4.Size = new Size(156, 23);
textBox4.TabIndex = 4;
//
// textBox5
//
textBox5.Location = new Point(12, 96);
textBox5.Name = "textBox5";
textBox5.Size = new Size(156, 23);
textBox5.TabIndex = 5;
//
// textBox6
//
textBox6.Location = new Point(445, 96);
textBox6.Name = "textBox6";
textBox6.Size = new Size(156, 23);
textBox6.TabIndex = 6;
//
// textBox7
//
textBox7.Location = new Point(12, 139);
textBox7.Name = "textBox7";
textBox7.Size = new Size(156, 23);
textBox7.TabIndex = 7;
//
// textBox8
//
textBox8.Location = new Point(445, 139);
textBox8.Name = "textBox8";
textBox8.Size = new Size(156, 23);
textBox8.TabIndex = 8;
//
// textBox9
//
textBox9.Location = new Point(12, 177);
textBox9.Name = "textBox9";
textBox9.Size = new Size(156, 23);
textBox9.TabIndex = 9;
//
// textBox10
//
textBox10.Location = new Point(445, 177);
textBox10.Name = "textBox10";
textBox10.Size = new Size(156, 23);
textBox10.TabIndex = 10;
//
// Velocidade_buton1
//
Velocidade_buton1.Location = new Point(174, 53);
Velocidade_buton1.Name = "Velocidade_buton1";
Velocidade_buton1.Size = new Size(103, 23);
Velocidade_buton1.TabIndex = 11;
Velocidade_buton1.Text = "Velocid_Escrever";
Velocidade_buton1.UseVisualStyleBackColor = true;
Velocidade_buton1.Click += Velocidade_buton1_Click;
//
// Velocidade_buton2
//
Velocidade_buton2.Location = new Point(336, 53);
Velocidade_buton2.Name = "Velocidade_buton2";
Velocidade_buton2.Size = new Size(103, 23);
Velocidade_buton2.TabIndex = 12;
Velocidade_buton2.Text = "Velocid_Ler";
Velocidade_buton2.UseVisualStyleBackColor = true;
Velocidade_buton2.Click += Velocidade_buton2_Click;
//
// Producao_buton1
//
Producao_buton1.Location = new Point(174, 96);
Producao_buton1.Name = "Producao_buton1";
Producao_buton1.Size = new Size(103, 23);
Producao_buton1.TabIndex = 13;
Producao_buton1.Text = "Prod_Escrever";
Producao_buton1.UseVisualStyleBackColor = true;
Producao_buton1.Click += Producao_buton1_Click;
//
// Producao_buton2
//
Producao_buton2.Location = new Point(336, 96);
Producao_buton2.Name = "Producao_buton2";
Producao_buton2.Size = new Size(103, 23);
Producao_buton2.TabIndex = 14;
Producao_buton2.Text = "Prod_Ler";
Producao_buton2.UseVisualStyleBackColor = true;
Producao_buton2.Click += Producao_buton2_Click;
//
// Pressao_buton1
//
Pressao_buton1.Location = new Point(174, 139);
Pressao_buton1.Name = "Pressao_buton1";
Pressao_buton1.Size = new Size(103, 23);
Pressao_buton1.TabIndex = 15;
Pressao_buton1.Text = "Pressão_Escrever";
Pressao_buton1.UseVisualStyleBackColor = true;
Pressao_buton1.Click += Pressao_buton1_Click;
//
// Pressao_buton2
//
Pressao_buton2.Location = new Point(336, 138);
Pressao_buton2.Name = "Pressao_buton2";
Pressao_buton2.Size = new Size(103, 23);
Pressao_buton2.TabIndex = 16;
Pressao_buton2.Text = "Pressão_Ler";
Pressao_buton2.UseVisualStyleBackColor = true;
Pressao_buton2.Click += Pressao_buton2_Click;
//
// Status_buton1
//
Status_buton1.Location = new Point(174, 176);
Status_buton1.Name = "Status_buton1";
Status_buton1.Size = new Size(103, 23);
Status_buton1.TabIndex = 17;
Status_buton1.Text = "Status_Escrever";
Status_buton1.UseVisualStyleBackColor = true;
Status_buton1.Click += Status_buton1_Click;
//
// Status_buton2
//
Status_buton2.Location = new Point(336, 177);
Status_buton2.Name = "Status_buton2";
Status_buton2.Size = new Size(103, 23);
Status_buton2.TabIndex = 18;
Status_buton2.Text = "Status_Ler";
Status_buton2.UseVisualStyleBackColor = true;
Status_buton2.Click += Status_buton2_Click;
//
// Form1
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(611, 225);
Controls.Add(Status_buton2);
Controls.Add(Status_buton1);
Controls.Add(Pressao_buton2);
Controls.Add(Pressao_buton1);
Controls.Add(Producao_buton2);
Controls.Add(Producao_buton1);
Controls.Add(Velocidade_buton2);
Controls.Add(Velocidade_buton1);
Controls.Add(textBox10);
Controls.Add(textBox9);
Controls.Add(textBox8);
Controls.Add(textBox7);
Controls.Add(textBox6);
Controls.Add(textBox5);
Controls.Add(textBox4);
Controls.Add(textBox3);
Controls.Add(TorqueButon2);
Controls.Add(TorqueButon1);
Controls.Add(textBox2);
Controls.Add(textBox1);
Name = "Form1";
Text = "Controle da Parafusadeira - PINE9";
Load += Form1_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
Para o uso devido do OPC UA deve ser instalado no código as seguintes extensões:
O usuário pode instalar através do próprio Visual Studio pela aba Projeto e em seguida
gerenciar pacote do Nu Get, uma nova aba vai ser aberta e assim pode instalar os
pacotes necessários.