欢迎来到传世资源网!
加载中...
正在加载,请耐心等待...
本站为收藏、学习站,如有侵权,请联系管理员删除!

C# OPC通信成功

介绍 评论 失效链接反馈

本人实测通信成功,欢迎下载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

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