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文件中 ...
随机推荐
- 使用Apache JMeter对SQL Server、Mysql、Oracle压力测试(二)
接着第一篇的写: 第三步,测试SQL Server数据库的性能: a.加载JDBC SQL Server驱动.添加线程组和设置线程属性和第二步一样,就不再赘述了: b.设置JDBC Connectio ...
- notify.min.js
/*! * @wcjiang/notify v2.0.11 * JS achieve the browser title flashing , scrolling, voice prompts , c ...
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multipartResolver': Failed to introspect bean class [org.springframework.web.multipart.commons.CommonsMultipartR
在用spring mvc 做文件上传的时候出现了这个问题(能看到这篇文章就说明你已经有了那两个包了) 错误:org.springframework.beans.factory.BeanCreation ...
- Unity如何退出游戏
使用 Application.Quit(),但在 editor 模式下使用 Application.Quit()是没用的,要用 EditorApplication.isPlaying = false. ...
- codeforces-2
B.chocolates #include<iostream> #include<algorithm> #include<string.h> long long b ...
- 煎蛋ooxx
pipeline.py class Jiandanline(FilesPipeline): def get_media_requests(self, item, info): for file_url ...
- c++算法实现(一) - 递归和初始化
递归 写递归函数经常出错,提醒自己两个规则: 1. 一般来说递归函数中不应该出现for.while之类的循环语句, 因为递归就是循环的另外一种实现: 2. 注意基线条件,具体参考<算法图解> ...
- Go语言文件操作
打开和关闭文件 os.Open()函数能够打开一个文件,返回一个*File和一个err. file.close()方法能够关闭文件. //打开和关闭文件 func main() { file,err ...
- Emote木马分析
前言:网上找的样本是EXE的,没有邮件样本,所以只做了exe分析. 一.Emote木马相关信息 文件: C:\Users\Desktop\Samp.exe 大小: 249856 bytes 文件版本: ...
- hdu2054 通过率低是有理由的
这虽然是一道水题,但却巨坑,他题面上不说数据范围,也没有说数据类型,事实就是数据范围巨大,整型实型都有,所以必须用字符串去写,但是又涉及到小数,所以还要删除小数后面多余的0,比如1==1.0000,这 ...