Você está na página 1de 14

Relatório Final - PINE9 – Rodrigo de Souza Garcia – VP3001121

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#.

Usando a nova linguagem obtive os seguintes resultados:


Para o uso deste software devem ser seguidos os seguintes passos:

1. Baixe os softwares: Visual Studio e OPC UA Server Simulator, o primeiro sendo da


Microsoft e o segundo da Integration Objects
2. Abra o programa OPC UA Server Simulator
3. Ao completar ambas as instalações abra a pasta OPCUA PINE9, nela abra a pasta
OPC_UA_PINE9_FINAL, clique no projeto de mesmo nome. OBS: caso não abra com o
Visual Studio clique com o botão direito no arquivo -> abrir com -> e selecione
Microsoft Visual Studio 2022
4. Em seguida aperte F5
5. Quando a programa abrir aguarde 1 minuto
6. Adicione os dados uma aba por vez, em seguida aperte no botão correspondente ao
lado para escrever os dados no servidor em seguida no botão correspondente da
variável inserida aperte para ler
7. O ultimo dado “Status” funciona com 0 e 1 para indicar desligado ou ligado
Servidor para deposito e leitura dos dados
É usado o seguinte endereço "opc.tcp://localhost:62640/"
Configurado aqui:
Seguindo os passos o usuário terá algo semelhante a isso

O código é dividido em duas partes:

- Form1 que vai encaminhar os valores para o servidor e em seguida recuperar os


valores de la
- Form1.Designer.cs que vai ser o design do programa

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();
}

private void Form1_Load(object sender, EventArgs e)


{

private void Button1_Click(object sender, EventArgs e)


{
string opcUrl = "opc.tcp://localhost:62640";
var tagName = "ns=2;s=Tag7";

var client = new OpcClient(opcUrl);


client.Connect();

double torque;

torque = Convert.ToDouble(textBox1.Text);

client.WriteNode(tagName, torque);

client.Disconnect();
}

private void TorqueButon2_Click(object sender, EventArgs e)


{
string opcUrl = "opc.tcp://localhost:62640/";
var tagName = "ns=2;s=Tag7";

var client = new OpcClient(opcUrl);


client.Connect();

var torque = client.ReadNode(tagName);

textBox2.Text = torque.ToString();

client.Disconnect();
}

private void Velocidade_buton1_Click(object sender, EventArgs e)


{

string opcUrl = "opc.tcp://localhost:62640";


var tagName = "ns=2;s=Tag7";

var client = new OpcClient(opcUrl);


client.Connect();

double velocidade;

velocidade = Convert.ToDouble(textBox3.Text);

client.WriteNode(tagName, velocidade);

client.Disconnect();

private void Velocidade_buton2_Click(object sender, EventArgs e)


{

string opcUrl = "opc.tcp://localhost:62640/";


var tagName = "ns=2;s=Tag7";

var client = new OpcClient(opcUrl);


client.Connect();

var velocidade = client.ReadNode(tagName);

textBox4.Text = velocidade.ToString();

client.Disconnect();

private void Producao_buton1_Click(object sender, EventArgs e)


{
string opcUrl = "opc.tcp://localhost:62640";
var tagName = "ns=2;s=Tag7";

var client = new OpcClient(opcUrl);


client.Connect();

double producao;
producao = Convert.ToDouble(textBox5.Text);

client.WriteNode(tagName, producao);

client.Disconnect();

private void Producao_buton2_Click(object sender, EventArgs e)


{
string opcUrl = "opc.tcp://localhost:62640/";
var tagName = "ns=2;s=Tag7";

var client = new OpcClient(opcUrl);


client.Connect();

var producao = client.ReadNode(tagName);

textBox6.Text = producao.ToString();

client.Disconnect();
}

private void Pressao_buton1_Click(object sender, EventArgs e)


{
string opcUrl = "opc.tcp://localhost:62640";
var tagName = "ns=2;s=Tag7";

var client = new OpcClient(opcUrl);


client.Connect();

double pressao;

pressao = Convert.ToDouble(textBox7.Text);

client.WriteNode(tagName, pressao);

client.Disconnect();
}

private void Pressao_buton2_Click(object sender, EventArgs e)


{
string opcUrl = "opc.tcp://localhost:62640/";
var tagName = "ns=2;s=Tag7";

var client = new OpcClient(opcUrl);


client.Connect();

var pressao = client.ReadNode(tagName);

textBox8.Text = pressao.ToString();

client.Disconnect();
}

private void Status_buton1_Click(object sender, EventArgs e)


{
string opcUrl = "opc.tcp://localhost:62640";
var tagName = "ns=2;s=Tag7";

var client = new OpcClient(opcUrl);


client.Connect();
double status;

status = Convert.ToDouble(textBox9.Text);

client.WriteNode(tagName, status);

client.Disconnect();
}

private void Status_buton2_Click(object sender, EventArgs e)


{
string opcUrl = "opc.tcp://localhost:62640/";
var tagName = "ns=2;s=Tag7";

var client = new OpcClient(opcUrl);


client.Connect();

var status = client.ReadNode(tagName);

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);
}

#region Windows Form Designer generated code

/// <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

private TextBox textBox1;


private TextBox textBox2;
private Button TorqueButon1;
private Button TorqueButon2;
private TextBox textBox3;
private TextBox textBox4;
private TextBox textBox5;
private TextBox textBox6;
private TextBox textBox7;
private TextBox textBox8;
private TextBox textBox9;
private TextBox textBox10;
private Button Velocidade_buton1;
private Button Velocidade_buton2;
private Button Producao_buton1;
private Button Producao_buton2;
private Button Pressao_buton1;
private Button Pressao_buton2;
private Button Status_buton1;
private Button Status_buton2;
}
}

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.

Você também pode gostar