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 BeckhoffTest
{
public partial class Form1 : Form
{
AdsClient plc = new AdsClient();
public Form1()
{
InitializeComponent();
this.Load += Form1_Load;
}
private void Form1_Load(object sender, EventArgs e)
{
//TwinCAT.Router.RouterPort routerPort = new TwinCAT.Router.RouterPort()
plc.Connect("192.168.137.17.1.1", 851);
}
private void button2_Click(object sender, EventArgs e)
{
this.richTextBox1.Text = string.Empty;
}
private void button1_Click(object sender, EventArgs e)
{
try
{
var handle = plc.CreateVariableHandle(this.textBox1.Text.Trim());
var vv = plc.ReadAny(handle, typeof(bool)).ToString();
plc.DeleteVariableHandle(handle);
this.richTextBox1.AppendText(vv);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
private void button3_Click(object sender, EventArgs e)
{
try
{
var handle = plc.CreateVariableHandle(this.textBox1.Text.Trim());
var vv = plc.ReadAny(handle, typeof(int)).ToString();
plc.DeleteVariableHandle(handle);
this.richTextBox1.AppendText(vv);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
private void button4_Click(object sender, EventArgs e)
{
try
{
var handle = plc.CreateVariableHandle(this.textBox1.Text.Trim());
var vv = plc.ReadAny(handle, typeof(float)).ToString();
plc.DeleteVariableHandle(handle);
this.richTextBox1.AppendText(vv);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
private void button5_Click(object sender, EventArgs e)
{
try
{
var handle = plc.CreateVariableHandle(this.textBox1.Text.Trim());
var vv = plc.ReadAny(handle, typeof(string)).ToString();
plc.DeleteVariableHandle(handle);
this.richTextBox1.AppendText(vv);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
private void button6_Click(object sender, EventArgs e)
{
try
{
var handle = plc.CreateVariableHandle(this.textBox1.Text.Trim());
var vv = plc.ReadAny(handle, typeof(ushort)).ToString();
plc.DeleteVariableHandle(handle);
this.richTextBox1.AppendText(vv);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
}
}