日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

python网课观后感_Python OpenOPC的学习观后感

發(fā)布時間:2025/4/16 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python网课观后感_Python OpenOPC的学习观后感 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Python OpenOPC的學(xué)習(xí)觀感

最近由于公司項目讓我研究工業(yè)標(biāo)準(zhǔn)協(xié)議OPC,開始的設(shè)計是在Linux環(huán)境用C/C++進(jìn)行編寫。但是經(jīng)過幾天的努力也沒有發(fā)現(xiàn)可用的免費(fèi)開發(fā)包,網(wǎng)上的收費(fèi)開發(fā)包如:Softing公司的Toolkit和Matrikon公司的SDK是可以進(jìn)行Linux環(huán)境下的開發(fā)。由于公司為了節(jié)省成本,又轉(zhuǎn)向其他方向----需求免費(fèi)開源的開發(fā)工具。網(wǎng)上免費(fèi)開放的開發(fā)都是基于Windows下的VB、VC和C#,因為opc需要調(diào)用windows下的DCOM組件,由于這個原因成為了Linux環(huán)境下開發(fā)的主要障礙。最后我找到了OpenOPC:

OpenOPC for Python is a free, open source OPC (OLE for Process Control) toolkit designed for use with the popular Python programming language. The unique features that set

it apart from the many commercially available OPC toolkits include...

This project utilizes the de facto OPC-DA (Win32 COM-based) industrial automation standard.

If you are looking for an OPC XML-DA library for Python, then please visit thePyOPCproject.

下面我就介紹一下OpenOPC開發(fā)工具的使用,因為我發(fā)現(xiàn)網(wǎng)上這方面的資料太少了(當(dāng)然你也可以看OpenOPC的官網(wǎng)說明http://openopc.sourceforge.net/about.html,不過內(nèi)容很少)。

首先,我們來談?wù)凮penOPC-1.3.1.win32-py2.7.exe:

當(dāng)你安裝完畢OpenOPC-1.3.1.win32-py2.7.exe時,在你的安裝路徑可以看到如下目錄:

bin目錄下有兩個文件:opc.exe和OpenOPCService.exe,這兩個文件是src目錄下的opc.py和OpenOPCService.py生成的,他們是可以在命令提示符下直接運(yùn)行的,具體操作可以查看README.txt文件;

doc目錄下是OpenOPC的說明文件,通過它你可以了解到OpenOPC的具體使用方法,主要是測試工具opc.py或opc.exe文件的使用;

lib目錄下主要是OpenOPC所要調(diào)用的庫文件gbda_aut.dll;

src目錄下包括opc.py、OpenOPCService.py、OpenOPC.py、SystemHealth.py;

其次,我們來談?wù)劀y試OPC

server-----MatrikonOPCSimulation

點(diǎn)擊MatrikonOPCSimulation.exe文件對其進(jìn)行安裝,安裝完畢后需要將其服務(wù)器的名字設(shè)置到環(huán)境變量中:OPC_SERVER=matrikon.OPC.simulation

啟動MatrikonOPC

server of simulation軟件設(shè)置其屬性就OK了,具體操作請查看軟件文檔;

我們再來談?wù)凮penOPC的原理:

從測試demo---opc.py中我們可以看到它的啟動方式有兩種:docm和open。dcom方式是直接調(diào)用本機(jī)上的DCOM組件,而open方式是通過zzzopenopcservice(OpenOPC

Gateway Service on Windows)來調(diào)用windows上的DCOM組件,因此你在調(diào)用時要認(rèn)真區(qū)分;

zzzopenopcservice的啟動,詳情請查看OpenOPC/doc/OpenOPC.pdf文檔;

你還可以通過opc.py上的不同命令測試?yán)atrikonOPC

server of simulation上的數(shù)據(jù)信息;

最后,我們談?wù)凪ACSV系統(tǒng)OPC

Server通信軟件的使用和測試代碼的應(yīng)用實(shí)例:

安裝MACSV系統(tǒng)OPC

Server通信軟件,并將其服務(wù)器的名字設(shè)置到環(huán)境變量中:OPC_SERVER=Hollysys.MACSV5OPCServer;

啟動MACSV5OPCServer,設(shè)置其屬性;

測試代碼opctest1.py如下:

from sys import *

from getopt import *

from os import *

import signal

import sys

import os

import types

import datetime

import re, time, csv

import OpenOPC

import Pyro

opc_class='Matrikon.OPC.Automation;Graybox.OPC.DAWrapper;HSCOPC.Automation;RSI.OPCAutomation;OPC.Automation'

client_name='OpenOPC'

opc_server='Hollysys.MACSV5OPCServer'

opc_host='127.0.0.1'

taglist=['Server1.Group0.opc_01','Server1.Group0.opc_02','Server1.Group1.rule1','Server1.Group1.rule2','Server2.Group0.sg1','Server2.Group0.sg2','Server2.Group1.sg2','Server2.Group1.sg1']

class SigHandler:

def __init__(self):

self.signaled = 0

self.sn = None

def __call__(self, sn, sf):

self.sn = sn

self.signaled += 1

# Establish signal handler for keyboard interrupts

def signalhandle():

sh = SigHandler()

signal.signal(signal.SIGINT,sh)

if os.name == 'nt':

signal.signal(signal.SIGBREAK,sh)

signal.signal(signal.SIGTERM,sh)

return sh

def test01():

opc = OpenOPC.client(opc_class, client_name)

print "### create opc!"

opc.connect(opc_server, opc_host)

print "### connect opc server:", opc_server

test02(opc)

taglist_opc = opc.read(taglist)

info_opc = opc.info()

servers_opc = opc.servers(opc_host)

tags = []

data = opc.list(tags, flat=True)

list_opc = opc.list

list_data = list_opc(tags)

opc.close()

print "### close opc!"

for i in range(len(taglist_opc)):

(name, val, qual, time) = taglist_opc[i]

print 'name:', name

print 'val:', val

print 'qual:', qual

print 'time:', time

print

print "value:", str(list(taglist_opc))

print "info:", str(list(info_opc))

print "servers:", str(list(servers_opc))

print "data:", str(list(data))

print "list:", str(list(list_data))

def test02(opc):

count0 = 0

sh = signalhandle()

while not sh.signaled:

print "test02... ", count0

data_opc = opc.read(tags=['Server1.Group0.opc_01'],

#group='test',

#size=group_size,

#pause=tx_pause,

#source=data_source,

update=1000,

#timeout=timeout,

#sync=sync,

#include_error=include_err_msg)

)

print "[test02] data:", str(list(data_opc))

try:

time.sleep(1)

except IOError:

break

count0 += 1

def main():

test01()

if __name__ == '__main__':

main()

具體開發(fā)包和測試代碼可以到http://download.csdn.net/detail/cl185303590/8821585進(jìn)行下載。

總結(jié)

以上是生活随笔為你收集整理的python网课观后感_Python OpenOPC的学习观后感的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。