python 2.7 读写 opc数据
运行环境 python2.7+window server2008+keep server
1、安装OpenOPC
a> 下载 OpenOPC-1.3.1.win32-py2.7 (1).exe 并安装
b> pip安装依赖包 Pywin32 + Pyro
c> 将OpenOPC安装目录下src文件夹下的OpenOPC.py复制到python安装目录下的Lib\site-packages目录下
d> 修改环境变量
OPC_MODE = open
2、连接opc服务器
# 导入包
import OpenOPC # 生成OpenOPC实例(Open mode)
# In Open mode a connection is made to the OpenOPC Gateway Service running on the specified node. This mode is available to both Windows and non-Windows clients.
opc = OpenOPC.open_client('localhost)
# 显示可连接的opc服务器
print opc.servers()
# If the OPC server is running on a different node, you can include the optional host parameter...
opc.connect('Matrikon.OPC.Simulation', 'localhost')
3、读取opc服务器数据
taglist=['Channel_4.Device_6.Word_1','Channel_4.Device_6.Word_2',
'Channel_2.Device_3.Tag_1','Channel_2.Device_3.Tag_2',
'Channel_2.Device_3.Tag_3','Channel_4.Device_5.Tag_1',
'Channel_3.Device_4.Word_1','Channel_3.Device_4.Word_2',]
# 读取一系列数据
opc_datas = opc.read(taglist)
datas = [i[1] for i in opc_data]
# 读取一个点
opc_data = opc.read(taglist[0])
data = opc_data[1]
4、写入opc服务器
# 写入一个点
# 方式1
opc.write( ('Triangle Waves.Real8', 100.0) )
# 方式2
opc['Triangle Waves.Real8'] = 100.0 # 写入多个点
opc.write( [('Triangle Waves.Real4', 10.0), ('Random.String', 20.0)] )
5、其他
# 列出可获取的opc目录
>>> opc.list()
['Simulation Items', 'Configured Aliases']
>>> opc.list('Simulation Items')
['Bucket Brigade', 'Random', 'Read Error', 'Saw-toothed Waves', 'Square Waves', 'Triangle Waves', 'Write Error', 'Write Only']
# 模糊查询
>>> opc.list('Simulation Items.Random.*Real*')
['Random.ArrayOfReal8', 'Random.Real4', 'Random.Real8'] # opc服务器信息
>>> opc.info()
[('Host', 'localhost'), ('Server', 'Matrikon.OPC.Simulation'), ('State', 'Running'), ('Version', '1.1 (Build 307)'), ('Browser', 'Hierarchical'), ('Start Time', '06/24/07 13:50:54'), ('Current Time', '06/24/07 18:30:11'), ('Vendor', 'Matrikon Consulting Inc (780) 448-1010 http://www.matrikon.com')] # 关闭opc连接
opc.close()
网盘下载链接: https://pan.baidu.com/s/17r1WllxDMzpijajGG3RUvw 提取码: wq6q
python 2.7 读写 opc数据的更多相关文章
- python通过ssh读写远程数据
1.适用场景 需要读取(写)多台远程机器下的一个或多个文件,如果要通过 os.system('scp ......')来完成就必须配置免密登陆,比较麻烦 2.准备工作, 安装依赖 pip instal ...
- python操作txt文件中数据教程[1]-使用python读写txt文件
python操作txt文件中数据教程[1]-使用python读写txt文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 原始txt文件 程序实现后结果 程序实现 filename = '. ...
- Python之读写文本数据
知识点不多 一:普通操作 # rt 模式的 open() 函数读取文本文件 # wt 模式的 open() 函数清除覆盖掉原文件,write新文件 # at 模式的 open() 函数添加write ...
- Python中,添加写入数据到已经存在的Excel的xls文件,即打开excel文件,写入新数据
背景 Python中,想要打开已经存在的excel的xls文件,然后在最后新的一行的数据. 折腾过程 1.找到了参考资料: writing to existing workbook using xlw ...
- Python使用openpyxl读写excel文件
Python使用openpyxl读写excel文件 这是一个第三方库,可以处理xlsx格式的Excel文件.pip install openpyxl安装.如果使用Aanconda,应该自带了. 读取E ...
- Python Socket请求网站获取数据
Python Socket请求网站获取数据 ---阻塞 I/O ->收快递,快递如果不到,就干不了其他的活 ---非阻塞I/0 ->收快递,不断的去问,有没有送到,有没有送到,. ...
- 【转】Python之文件读写
[转]Python之文件读写 本节内容: I/O操作概述 文件读写实现原理与操作步骤 文件打开模式 Python文件操作步骤示例 Python文件读取相关方法 文件读写与字符编码 一.I/O操作概述 ...
- python操作txt文件中数据教程[4]-python去掉txt文件行尾换行
python操作txt文件中数据教程[4]-python去掉txt文件行尾换行 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文章 python操作txt文件中数据教程[1]-使用pyt ...
- python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件
python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 python操作txt文件中 ...
随机推荐
- HTMLTESTRunner自动化测试报告增加截图功能
我们都知道HTMLTESTRunner自动化测试报告,是Unittest单元测试框架报告,那么在做ui测试的时候就有点不适用了. 我们需要出错截图功能. 以下是我改的,增加了截图功能,先展示界面,再展 ...
- python装饰器扩展之functools.wraps
我们知道函数被装饰器,装饰后,所有的属性,以及内置函数就失效了. 原因是函数类型变成了warpper类型 示例1:不带wraps装饰器示例 def warfunc(func): def warpper ...
- 手动创建Oracle实例
手工建库步骤 Step 1: Specify an Instance Identifier (SID)(指定一个实例的标识符SID)Step 2: Ensure That the Required E ...
- EF性能检测工具MiniProfilerEF6的使用
一.在VS项目中分别安装包MiniProfiler.MiniProfiler.EF6.MiniProfiler.MVC4 二.在Global.asax文件的Application_BeginReque ...
- SSIS Hekaton In-Memory OLTP 【翻译一篇外国文章】
来自:http://www.itprotoday.com/microsoft-sql-server/important-new-features-sql-server-2014 Microsoft's ...
- Git 命令及git服务器
Linux 服务器上安装git yum -y install git git config --global user.name "name" git config --glo ...
- redis php操作命令
redis的五种存储类型的具体用法 String 类型操作 string是redis最基本的类型,而且string类型是二进制安全的.意思是redis的string可以包含任何数据.比如jpg图片或者 ...
- CentOS7──xxx is not in the sudoers file
提示"xxx is not in the sudoers file. This incident will be reported.其中 ”XXX“是你的用户名,也就是你的用户名没有权限使用 ...
- keytool 错误: java.lang.Exception: 密钥库文件不存在: keystore
通过Android Studio编译器获取SHA1 第一步.打开Android Studio的Terminal工具 第二步.输入命令:keytool -v -list -keystore keysto ...
- ajax的网上解析
/* 用XMLHTTPRequest来进行ajax异步数据交交互*/ 主要有几个步骤: //1.创建XMLHTTPRequest对象 //最复杂的一步 if (window.XMLHttpReques ...