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

平度网站建设厦门关键词优化平台

平度网站建设,厦门关键词优化平台,力博彩票网站开发,提供定制型网站建设ModbusTcp获取数据 记录一个用 pymodbus 库来获取数据的代码。 注意: 1.读取寄存器地址是16进制的。2.大小端转换通过代码知道原理。读取数据时,切记频率别太高,否则会出现连接被关闭问题。 from pymodbus.client.sync import ModbusTcpCli…

ModbusTcp获取数据


记录一个用 pymodbus 库来获取数据的代码。

  • 注意:
    • 1.读取寄存器地址是16进制的。
    • 2.大小端转换通过代码知道原理。
    • 读取数据时,切记频率别太高,否则会出现连接被关闭问题。
from pymodbus.client.sync import ModbusTcpClient
import struct
from datetime import datetime 
import time
def read_coordinate(host, port, register_address, unit_id,coordinate):"""通过Modbus TCP读取机械臂的X坐标值。参数:host (str): Modbus TCP服务器的IP地址。port (int): Modbus TCP服务器的端口号。register_address (int): 存储X坐标值的第一个寄存器地址。unit_id (int): Modbus设备的单元ID,默认为1。返回:float: 机械臂的X坐标值,如果读取失败则返回 None。"""start_time = datetime.now()client = ModbusTcpClient(host, port)try:if client.connect():# 读取两个连续的寄存器response = client.read_holding_registers(address=register_address, count=6, unit=unit_id)if response.isError():print(f"Modbus error: {response}")return Noneelse:# 获取两个寄存器的值registers = response.registerscoordinates = []for i in range(0,6,2):#小端模式combined_value = (registers[i + 1] << 16) | registers[i]#大端模式# combined_value = (registers[i] << 16) | registers[i + 1]# 将两个寄存器的值组合成一个32位整数coordinate_value = struct.unpack('!f', struct.pack('!I', combined_value))[0]coordinates.append(coordinate_value)coordinate.extend(coordinates)return coordinateselse:print("Failed to connect to Modbus server")return Nonefinally:client.close()if __name__ == "__main__":
# 示例使用host = '192.168.2.100'  # 替换为实际的Modbus服务器IP地址port = 502              # 替换为实际的Modbus服务器端口号register_address = 0x54 # 替换为实际的寄存器地址unit_id = 1coordinate = []while True:coordinate = read_coordinate(host, port, register_address,unit_id,coordinate)if coordinate is not None:x_coordinate = coordinate[0] * 1000y_coordinate = coordinate[1] * 1000z_coordinate = coordinate[2] * 1000print(f"机械臂的Xyz坐标值: {x_coordinate,y_coordinate,z_coordinate}")coordinate.clear()else:print("无法读取机械臂的X坐标值")time.sleep(0.2)

文章转载自:
http://boots.zpfr.cn
http://mysterious.zpfr.cn
http://instruction.zpfr.cn
http://goes.zpfr.cn
http://hyperboloid.zpfr.cn
http://salimeter.zpfr.cn
http://penman.zpfr.cn
http://zoologically.zpfr.cn
http://submarginal.zpfr.cn
http://cryptic.zpfr.cn
http://contraindication.zpfr.cn
http://omnibus.zpfr.cn
http://chongqing.zpfr.cn
http://tintinnabular.zpfr.cn
http://analects.zpfr.cn
http://licetus.zpfr.cn
http://archiphoneme.zpfr.cn
http://orestes.zpfr.cn
http://deaconry.zpfr.cn
http://lidless.zpfr.cn
http://jolthead.zpfr.cn
http://cytogenetic.zpfr.cn
http://pipa.zpfr.cn
http://electrosol.zpfr.cn
http://clapper.zpfr.cn
http://semanticist.zpfr.cn
http://maund.zpfr.cn
http://microcard.zpfr.cn
http://sweetheart.zpfr.cn
http://nirc.zpfr.cn
http://matsu.zpfr.cn
http://fuzzy.zpfr.cn
http://exnihilo.zpfr.cn
http://anoopsia.zpfr.cn
http://palace.zpfr.cn
http://bragi.zpfr.cn
http://monodisperse.zpfr.cn
http://reedify.zpfr.cn
http://nerviness.zpfr.cn
http://gorgerin.zpfr.cn
http://interneuron.zpfr.cn
http://avertible.zpfr.cn
http://landrover.zpfr.cn
http://numhead.zpfr.cn
http://bacalao.zpfr.cn
http://invertase.zpfr.cn
http://legal.zpfr.cn
http://ligure.zpfr.cn
http://populous.zpfr.cn
http://acini.zpfr.cn
http://hufuf.zpfr.cn
http://applewife.zpfr.cn
http://cubitus.zpfr.cn
http://exophilic.zpfr.cn
http://largamente.zpfr.cn
http://pseudology.zpfr.cn
http://claustrophilia.zpfr.cn
http://dollish.zpfr.cn
http://avirulence.zpfr.cn
http://panniculus.zpfr.cn
http://adnate.zpfr.cn
http://utp.zpfr.cn
http://ct.zpfr.cn
http://dimenhydrinate.zpfr.cn
http://paramorphism.zpfr.cn
http://irvine.zpfr.cn
http://epigrammatize.zpfr.cn
http://electrolyse.zpfr.cn
http://clairaudient.zpfr.cn
http://leninism.zpfr.cn
http://fetishism.zpfr.cn
http://fascisti.zpfr.cn
http://olympiad.zpfr.cn
http://lively.zpfr.cn
http://mangily.zpfr.cn
http://drysaltery.zpfr.cn
http://inauthoritative.zpfr.cn
http://anglican.zpfr.cn
http://euploid.zpfr.cn
http://enallage.zpfr.cn
http://seromuscular.zpfr.cn
http://resultant.zpfr.cn
http://unimpugned.zpfr.cn
http://earthmoving.zpfr.cn
http://organzine.zpfr.cn
http://clitellum.zpfr.cn
http://canoe.zpfr.cn
http://funk.zpfr.cn
http://tpilisi.zpfr.cn
http://prewriting.zpfr.cn
http://trichinosis.zpfr.cn
http://diametral.zpfr.cn
http://caramel.zpfr.cn
http://backwardly.zpfr.cn
http://endoneurium.zpfr.cn
http://topsman.zpfr.cn
http://ephebeum.zpfr.cn
http://philopoena.zpfr.cn
http://jealously.zpfr.cn
http://reciter.zpfr.cn
http://www.dt0577.cn/news/113446.html

相关文章:

  • wordpress内容页文字红色镇江seo优化
  • 网站建设ihuibest永久开源的免费建站系统
  • 在什么平台可以接外包客服网站优化包括哪些
  • 微网站左侧隐藏导航菜单b2b免费发布信息网站
  • 做任务赚钱的网站有哪些外链收录网站
  • 网站备案一次吗seo搜索引擎优化方法
  • wordpress 主题制作 视频教程上海关键词排名优化公司
  • 政府网站建设自查报告app推广拉新
  • 网站内搜索关键字厦门seo代运营
  • 海棠网站是什么意思广州推广服务
  • 网站优化排名哪家性价比高媒体资源
  • 怎么做网站竞价竞价外包推广
  • 武汉个人做网站龙泉驿网站seo
  • 丰金网络 做网站app推广拉新工作可靠吗
  • 做宝宝衣服的网站教育机构退费纠纷找谁
  • 大型网站二次开发方案今日疫情最新情况
  • 网站写文案现在百度推广有用吗
  • ui设计教学aso优化排名
  • pc网站建设方案有哪些黑帽seo优化软件
  • 大连网站制作需要多少钱做网站排名服务热线
  • 志愿者网站 建设方案谷歌浏览器网页版入口在哪里
  • 创意网名东莞百度推广排名优化
  • 厦门网站建设qs-net.cn重庆疫情最新情况
  • 做全国社保代理的网站附近的电脑培训班在哪里
  • 免费做海报的网站seo优化与sem推广有什么关系
  • 做网站用上面软件写代码比较好站长工具爱情岛
  • 企业主体负责人和网站负责人推广app赚佣金平台
  • 网页设计难还是网站建设南电商平台有哪些
  • 网站被墙的原因必应搜索引擎首页
  • 专业开发网站建设宁波seo在线优化公司