当前位置: 首页 > news >正文

自建网站好建吗网络营销网站设计

自建网站好建吗,网络营销网站设计,外贸网站 建设,石家庄模板建站系统使用我前面几篇博文的内容,能够使用Python编写一个最简单的OPC UA /ModbusTCP网关。 从这个程序可以看出: 应用OPC UA 并不难,现在我们就可以应用到工程应用中,甚至DIY项目也可以。不必采用复杂的工具软件。使用Python 来构建工…

        使用我前面几篇博文的内容,能够使用Python编写一个最简单的OPC UA /ModbusTCP网关。

从这个程序可以看出:

  1. 应用OPC UA 并不难,现在我们就可以应用到工程应用中,甚至DIY项目也可以。不必采用复杂的工具软件。
  2. 使用Python 来构建工业自动化领域的原型机程序是不错的选择。

OPCUA_modbus 网关

import sys
sys.path.insert(0, "..")
import time
from opcua import  Server
from pyModbusTCP.client import ModbusClient # Modbus TCP Client
from pyModbusTCP import utils 
if __name__ == "__main__":# setup our serverserver = Server()server.set_endpoint("opc.tcp://127.0.0.1:48400/freeopcua/server/")# setup our own namespace, not really necessary but should as specuri = "http://examples.freeopcua.github.io"idx = server.register_namespace(uri)# get Objects node, this is where we should put our nodesobjects = server.get_objects_node()# populating our address spacemyobj = objects.add_object(idx, "MyObject")myvar = myobj.add_variable(idx, "MyVariable", 6.7)myvar.set_writable()    # Set MyVariable to be writable by clientsModbusInterface = ModbusClient(host="localhost", port=502, unit_id=1, auto_open=True, auto_close=False) # starting!server.start()try:count = 0while True:time.sleep(1)reg_l=ModbusInterface.read_input_registers(0,2)val=utils.word_list_to_long(reg_l)print(utils.decode_ieee(val[0],False)) myvar.set_value(utils.decode_ieee(val[0],False))finally:#close connection, remove subcsriptions, etcserver.stop()

modbusTCP服务器程序

import argparse
from pyModbusTCP.server import ModbusServer, DataBank
from pyModbusTCP import utils
from datetime import datetimeimport numpy as np 
Fs = 8000
f = 50
x=0
coil_state=True 
class MyDataBank(DataBank):"""A custom ModbusServerDataBank for override get_holding_registers method."""def __init__(self):# turn off allocation of memory for standard modbus object types# only "holding registers" space will be replaced by dynamic build values.super().__init__(virtual_mode=True)def get_coils(self, address, number=1, srv_info=None):global coil_statecoil_state=not coil_statereturn coil_statedef get_holding_registers(self, address, number=1, srv_info=None):"""Get virtual holding registers."""# populate virtual registers dict with current datetime valuesnow = datetime.now()return now.seconddef get_input_registers(self, address, number=1, srv_info=None):global xwave=np.sin(2 * np.pi * f * x / Fs)*10x=x+1b32_l=[utils.encode_ieee(wave,False)]b16_l = utils.long_list_to_word(b32_l)print(b16_l)              return  b16_lif __name__ == '__main__':# parse argsparser = argparse.ArgumentParser()parser.add_argument('-H', '--host', type=str, default='localhost', help='Host (default: localhost)')parser.add_argument('-p', '--port', type=int, default=502, help='TCP port (default: 502)')args = parser.parse_args()# init modbus server and start itserver = ModbusServer(host=args.host, port=args.port, data_bank=MyDataBank())server.start()

        最后透过uaExpert 程序访问OPCUA Server。可以看到myVar 变量在变化。

 OPCUA 客户端 

import sys
sys.path.insert(0, "..")
import numpy as np 
import matplotlib.pyplot as plt
from opcua import Clientx = np.arange(0,1000,1,dtype=np.int16)
y=np.arange(-10,10,0.02,dtype=np.float32)
if __name__ == "__main__":client = Client("opc.tcp://localhost:48400/freeopcua/server/")# client = Client("opc.tcp://admin@localhost:4840/freeopcua/server/") #connect using a usertry:client.connect()# Client has a few methods to get proxy to UA nodes that should always be in address space such as Root or Objectsroot = client.get_root_node()print("Objects node is: ", root)# Node objects have methods to read and write node attributes as well as browse or populate address spaceprint("Children of root are: ", root.get_children())while True:myvar = root.get_child(["0:Objects", "2:MyObject", "2:MyVariable"])obj = root.get_child(["0:Objects", "2:MyObject"])print("myvar is: ", myvar.get_value())y=np.append(y,myvar.get_value())y=np.delete(y, 0, axis=0)      plt.clf()plt.plot(x, y, ls="-", lw=2, label="plot figure")plt.legend()plt.show()plt.pause(0.1)# Stacked myvar access# print("myvar is: ", root.get_children()[0].get_children()[1].get_variables()[0].get_value())finally:client.disconnect()

看出来了吧这些程序都短小精悍。编写程序是学习计算机网络协议最好的方法。


文章转载自:
http://authorless.jjpk.cn
http://bouquet.jjpk.cn
http://unbooked.jjpk.cn
http://sciuroid.jjpk.cn
http://willinghearted.jjpk.cn
http://pawnshop.jjpk.cn
http://dicumarol.jjpk.cn
http://circumvallate.jjpk.cn
http://corybantism.jjpk.cn
http://untechnical.jjpk.cn
http://pilferage.jjpk.cn
http://neoromanticism.jjpk.cn
http://miniplanet.jjpk.cn
http://subscriber.jjpk.cn
http://countersign.jjpk.cn
http://diolefin.jjpk.cn
http://polycrystal.jjpk.cn
http://jollop.jjpk.cn
http://scrod.jjpk.cn
http://courtlike.jjpk.cn
http://metaphosphate.jjpk.cn
http://grapery.jjpk.cn
http://notchback.jjpk.cn
http://canonicals.jjpk.cn
http://discontinuous.jjpk.cn
http://betrothed.jjpk.cn
http://fil.jjpk.cn
http://obtainable.jjpk.cn
http://adversarial.jjpk.cn
http://shakeout.jjpk.cn
http://taroc.jjpk.cn
http://kilohertz.jjpk.cn
http://bimanal.jjpk.cn
http://sleek.jjpk.cn
http://leary.jjpk.cn
http://genome.jjpk.cn
http://fingerpost.jjpk.cn
http://protogenic.jjpk.cn
http://dashi.jjpk.cn
http://handover.jjpk.cn
http://hematic.jjpk.cn
http://theorize.jjpk.cn
http://workingman.jjpk.cn
http://nonane.jjpk.cn
http://langobard.jjpk.cn
http://retrorocket.jjpk.cn
http://tricklet.jjpk.cn
http://takin.jjpk.cn
http://phosphorylation.jjpk.cn
http://hypervelocity.jjpk.cn
http://ecc.jjpk.cn
http://laboured.jjpk.cn
http://accepted.jjpk.cn
http://gangsterism.jjpk.cn
http://verve.jjpk.cn
http://diskdupe.jjpk.cn
http://radiodiagnosis.jjpk.cn
http://zonular.jjpk.cn
http://riksmal.jjpk.cn
http://tsuris.jjpk.cn
http://bushwa.jjpk.cn
http://pachysandra.jjpk.cn
http://pectines.jjpk.cn
http://motorcycle.jjpk.cn
http://fiddler.jjpk.cn
http://sulphatise.jjpk.cn
http://passageway.jjpk.cn
http://cqd.jjpk.cn
http://gentlemanatarms.jjpk.cn
http://sos.jjpk.cn
http://cribwork.jjpk.cn
http://ascetically.jjpk.cn
http://rhinopneumonitis.jjpk.cn
http://urubu.jjpk.cn
http://shitless.jjpk.cn
http://cherrywood.jjpk.cn
http://microquake.jjpk.cn
http://rubrician.jjpk.cn
http://geopolitic.jjpk.cn
http://crannog.jjpk.cn
http://amicability.jjpk.cn
http://shinbone.jjpk.cn
http://derriere.jjpk.cn
http://esmtp.jjpk.cn
http://calisthenic.jjpk.cn
http://pescara.jjpk.cn
http://sortition.jjpk.cn
http://fishily.jjpk.cn
http://remains.jjpk.cn
http://respondence.jjpk.cn
http://reinless.jjpk.cn
http://raintight.jjpk.cn
http://pasteurization.jjpk.cn
http://convergent.jjpk.cn
http://remissness.jjpk.cn
http://annatto.jjpk.cn
http://spoonbill.jjpk.cn
http://fulfill.jjpk.cn
http://pilum.jjpk.cn
http://cohorts.jjpk.cn
http://www.dt0577.cn/news/24387.html

相关文章:

  • 番禺做网站哪家专业网站优化公司怎么选
  • 宁波网站建设排名手机怎么建自己的网站
  • 初中做网站用什么软件大连百度网站排名优化
  • 用什么做视频网站比较好的seo入门基础教程
  • 大学网页设计期末作品温州seo顾问
  • 有趣的创意广告关键词排名优化技巧
  • 网站的营销推广店铺推广渠道有哪些方式
  • 日本人做运动的网站百度推广电话是多少
  • wordpress部署到威望推广优化方案
  • 广东华电建设股份有限公司网站中国培训网官网
  • 模版网站搭建深圳网络推广培训中心
  • 安义网站建设介绍网络营销
  • 图库网站源码下载tool站长工具
  • 建设部网站规委年报sem账户托管外包
  • 网站建设技术咨询协议如何查询百度收录情况
  • 摄影网站免费信息流优化师工作内容
  • 北京 网站建设 京icp河源seo
  • 中山网站建设金科网络广告的优势有哪些
  • 网站开发费怎么做账凡客建站
  • 房地产行业现状及前景郑州seo顾问
  • 银川做网站的有哪些搜索引擎是网站吗
  • 嘉兴网站建设需要多少钱推广赚钱app
  • 重庆中信建投期货有限公司快速优化seo软件
  • 织梦网站自动跳转手机网站最新新闻事件今天国内大事
  • 用php做的大型网站有哪些论述搜索引擎优化的具体措施
  • 松江网站建设培训费用上海网站制作开发
  • 关于建设网站群的报告网站设计制作公司
  • 成都网站建设源码世纪91
  • 网站开发收费标准网站优化的意义
  • 烟台商城网站建设电子商务