工业数据采集:Python从OPC读、写设备实时数据so easy - 知乎 (zhihu.com)
Matrikon OPC使用教程连载
python 2.7 读写 opc数据
Python2.7 opc-DA 数据采集-OpenOPC使用说明
OpenOPC Gateway Service
The Gateway Service is an optional Windows service which handles all the Win32 COM/DCOM calls used by the OpenOPC library module. This offers the following potential advantages:
- Avoidance of DCOM security headaches and firewall issues when running the OPC client and OPC server on different nodes.
- The ability to write OPC client applications that can run on non-Windows platforms such as Linux, Unix, and Mac OS X.
Installing the service
C:\OpenOPC\bin> OpenOPCService.exe -install Installing service OpenOpcService Service installed
Starting the service
C:\OpenOPC\bin> net start zzzOpenOpcService
Stopping the service
C:\OpenOPC\bin> net stop zzzOpenOpcService
FreeOpcUa:开源C ++和Python OPC-UA服务器以及客户端库和工具
PYTHON工业互联网监控项目实战4—PYTHON OPCUA
OPC UA设备接入实践树
莓派安装freeopcua server
代码:
openopc_client.py(phpstudy_pro, KEPServerEX6, MatrikonOPC Explorer)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# openopc 官方文档地址
#http://openopc.sourceforge.net/api.html
# 导入包
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('Kepware.KEPServerEX.V6', 'localhost')
taglist=['mysqltest.test.test_id', 'mysqltest.test.test_name']
# # 读取一系列数据
opc_datas = opc.read(taglist)
print opc_datas
opc.close()
D:\Python27\Scripts\examples\server-minimal.py
import sys
sys.path.insert(0, "..")
import time
import random
from opcua import ua, Server
if __name__ == "__main__":
# setup our server
server = Server()
server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
# setup our own namespace, not really necessary but should as spec
uri = "http://examples.freeopcua.github.io"
idx = server.register_namespace(uri)
# get Objects node, this is where we should put our nodes
objects = server.get_objects_node()
myobj = objects.add_object(idx, "Tank4C9")
status = myobj.add_variable(idx, "Status", 0)
overheadFlow = myobj.add_variable(idx, "OverheadFlow", 0)
buttomsFlow = myobj.add_variable(idx, "ButtomsFlow", 0)
power = myobj.add_variable(idx, "Power", 0)
#myVar.set_writable() # Set MyVariable to be writable by clients
# starting!
server.start()
try:
count = 0
while True:
time.sleep(5)
count = count + 1
print(count%4)
if count%4>0:
status.set_value(1)
else:
status.set_value(0)
a= random.randint(100,500)
print("OverheadFlow:"+str(a))
overheadFlow.set_value(a)
buttomsFlow.set_value(random.randint(50,500))
power.set_value(random.randint(1000,5000))
finally:
#close connection, remove subcsriptions, etc
server.stop()
PYTHON3 + OPENOPC读取OPC服务器方法_工业自动化工作者-CSDN博客_python 读取opc
用OPC采集mysql的配置
1.先安装mysql
2.在安装ODBC驱动 mysql-connector-odbc**
3.在控制面板或window搜索框 找到ODBC数据源管理器
选择"系统DSN" -> 添加 ->mysql odbc *** driver->配置mysql连接信息 [配置数据源名称 TESTER]
4.打开KeepServerEX
1、新建 一个channel
Input Name-> [driver] Advanced Simulator ->next-> [DataSource] TESTER [User Name] root [password] ****** (mysql 用户密码)
2. 新建一个Decvie
Input Name -> [decvice mode] Mysql -> 选择表名称->Next..Next->Ok
这样就联通了
DDE OPC服务器 (OPC Server) (matrikonopc.cn)
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)
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)] )
OPC测试常用的OPCClient和OPCServer软件推荐
原文链接:http://sns.ca800.com/space.php?uid=45972&do=blog&id=2310
各位在进行OPC通讯时,常会遇到两种情况:
1)使用一个OPCClient在同一台计算机上连接远程计算机上的多个OPCServer时,发现某个OPCServer是通畅的,但其他的OPCServer却无论如何都不通。不知该如何定位问题了?
2)多个厂家的OPCClient连接同一计算机上的OPCServer,发现有的OPCClient通了,有的不通,有的能获取数据,有的不能获取数据。
基于以上情况,将一直以来常用的OPCClient和OPCServer推荐几款,以备大家不时之需。
不是最好,但可能是恰好!
1. OPC DA Client推荐
推荐的理由(此标准仅仅代表个人意见):
1) 单文件;携带方便,无需安装,绿色环保。
2) 遵循OPC标准,稳定。
3) 功能无需多,但适用功能有一个或多个。
推荐的第一位:OPCClient.exe
把它放在第一位并不是有多好,而是100KB的体积,单文件,也很符合OPC标准,所以是个超便携的OPCClient。
推荐的第二位:Matrikon公司的OPCClient.
很不错的一个OPCClient,标准,稳定,单文件,通讯过程的信息还比较丰富,我是比较喜欢用它在创建OPC组时定义同步方式或异步方式来验证远程计算机的OPC配置是否正确。缺点就是大了点,2M多。
推荐的第三位:Kepware公司的OPCClient
功能很强大,标准,稳定,日志信息很丰富,最推荐的功能是支持对OPCServer中点名的条件过滤,支持点表的导入导出,支持自动导入OPCServer的所有点,根据点表识别好点坏点,按照列排序,用它可以弥补很多国产组态软件不能在线遍历OPCServer点表的功能、不能过滤OPCServer点的功能、不能识别OPCServer中好点坏点的功能等。缺点就是非单文件。
其实还有其他很多的很好的OPCClient软件,欢迎各位推荐分享。
2. OPC DA Server推荐:
推荐的理由(此标准仅仅代表个人意见):
1) 依然单文件;携带方便,无需安装,绿色环保。
2) 依然遵循OPC标准,稳定。
3) 能模拟常见的大多数应用场景和数据,如各种曲线(三角函数曲线等),各种数据类型,各种故障类型,这一条大多数情况下与第一点是冲突的,所以基本上是常备几种OPCServer
推荐的第一位:Knight.OPCServer
简单,还是简单,单文件运行起来啥都有了,148KB,很适合做简单的测试。
推荐的第二位:Matrikon公司的OPCServer Simulator
简单,单文件注册后,各种数据类型,各种点类型(只读点,只写点,读写点)都有了,更好的一点是,如果想做大规模的测试,10万点,那么只需要在它的Random.下添加任意名称即可,OPCServer会自动给你建出对应的测点,还是随机数变化。
推荐的第三位:Kepware公司的OPCServer
本来不想推荐,因为这是一个商业软件,需要花费金钱购买License的,但Kepware公司的OPCServer需要花钱的不是OPCServer本身,而是采集驱动。不过Kepware公司的OPCServer提供了不花钱的仿真驱动,用来测试上正是杀人越货的好东西啊,推荐理由的第三条就是说它老兄了。 缺点就是太庞大,不简单,学习成本较高。但为了能满足OPC这类产品的各种测试,它真的是最佳选择。由于它是商业软件,我就不提供下载地址了,各位去它的官方网站可以下载,做好的几万点的测试工程需要的找我要。