找传奇、传世资源到传世资源站!

C# OPC通信成功

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

本人实测通信成功,欢迎下载from clipboardusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace TestOPC{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } OPC_Interface _opcItf; private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox1.Text) && string.IsNullOrEmpty(textBox2.Text)) { MessageBox.Show("必填项不能为空"); return; } try { _opcItf = new OPC_Interface(textBox1.Text, textBox2.Text); _opcItf.OpenServer(); MessageBox.Show("连接成功"); } catch (Exception exp) { MessageBox.Show("连接失败" exp.Message); } } private void Form1_Load(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { try { _opcItf.Close(); MessageBox.Show("已断开"); } catch (Exception exp) { MessageBox.Show("断开异常:" exp.Message); } } private void button3_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox3.Text)) { MessageBox.Show("必填项不能为空"); return; } try { textBox4.Text = _opcItf.Read(textBox3.Text).ToString(); MessageBox.Show("获取值正常返回"); } catch (Exception exp) { MessageBox.Show("获取值异常" exp.Message); } } private void button4_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox3.Text) && string.IsNullOrEmpty(textBox4.Text)) { MessageBox.Show("必填项不能为空"); return; } try { _opcItf.Write(textBox3.Text,textBox4.Text); MessageBox.Show("设置值正常"); } catch (Exception exp) { MessageBox.Show("设置值异常" exp.Message); } } private void timer1_Tick(object sender, EventArgs e) //增加定时器定时自动读取 { if (string.IsNullOrEmpty(textBox3.Text)) { MessageBox.Show("必填项不能为空"); return; } try { textBox4.Text = _opcItf.Read(textBox3.Text).ToString(); MessageBox.Show("获取值正常返回"); } catch (Exception exp) { MessageBox.Show("获取值异常" exp.Message); } } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复