PROGRAM MAIN VAR
int1:INT := 30000;
str1:STRING := 'this is a test string';
END_VAR
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TwinCAT.Ads;
namespace Read_Write
{
public partial class Form1 : Form
{
internal System.Windows.Forms.TextBox tText;
internal System.Windows.Forms.TextBox tint1;
private int hText;
private int hint1;
private TcAdsClient adsClient;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
adsClient = new TcAdsClient();
try
{
adsClient.Connect(851);
//PLC Variablen
hText = adsClient.CreateVariableHandle("MAIN.str1");
hint1 = adsClient.CreateVariableHandle("MAIN.int1");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
adsClient.Dispose();
}
//READ Button
private void button1_Click(object sender, EventArgs e)
{
try
{
tText.Text = adsClient.ReadAny(hText, typeof(String), new int[] { 80 }).ToString();
tint1.Text = adsClient.ReadAny(hint1, typeof(int)).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Write_Click(object sender, EventArgs e)
{
try
{
adsClient.WriteAny(hint1, int.Parse(tint1.Text));
adsClient.WriteAny(hText, tText.Text, new int[] { 80 });
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
using TwinCAT.Ads;
namespace ReadWriteADS
{
public partial class Form1 : Form
{
private int hText;
private int hint1;
private TcAdsClient adsClient;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
adsClient = new TcAdsClient();
try
{
adsClient.Connect(851);
//PLC Variablen
hText = adsClient.CreateVariableHandle("MAIN.str1");
hint1 = adsClient.CreateVariableHandle("MAIN.int1");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
adsClient.Dispose();
}
//READ Button
private void button1_Click_1(object sender, EventArgs e)
{
try
{
textBox1.Text = adsClient.ReadAny(hText, typeof(String), new int[] { 80 }).ToString();
textBox2.Text = adsClient.ReadAny(hint1, typeof(int)).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
adsClient.WriteAny(hint1, int.Parse(textBox2.Text));
adsClient.WriteAny(hText, textBox1.Text, new int[] { 80 });
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
PROGRAM MAIN
VAR
int1:INT ;
str1:STRING ;
END_VAR
int1:= 30000;
str1:= 'this is a test string';
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
using TwinCAT.Ads;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private int hText;
private int hint1;
private TcAdsClient adsClient;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
adsClient = new TcAdsClient();
try
{
adsClient.Connect(851);
//PLC Variablen
hText = adsClient.CreateVariableHandle("MAIN.str1");
hint1 = adsClient.CreateVariableHandle("MAIN.int1");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
adsClient.Dispose();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
textBox1.Text = adsClient.ReadAny(hText, typeof(String), new int[] { 80 }).ToString();
textBox2.Text = adsClient.ReadAny(hint1, typeof(int)).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
adsClient.WriteAny(hint1, int.Parse(textBox2.Text));
adsClient.WriteAny(hText, textBox1.Text, new int[] { 80 });
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
{attribute 'pack_mode' := '1'}
PROGRAM MAIN
VAR
int1:INT ;
str1:STRING ;
END_VAR
int1:= 30000;
str1:= 'this is a test string';
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?