python检测光电感烟火灾探测报警器
发布日期:2021-06-27 21:40:14 浏览次数:3 分类:技术文章

本文共 1282 字,大约阅读时间需要 4 分钟。

python检测光电感烟火灾探测报警器

import serial  # 引入库import threading  # python 定时器import platform  # 系统import modbus_tk.modbus_rtu as rtuimport modbus_tk.defines as csttry:    sys = platform.system()    if sys == "Windows":        ser = serial.Serial(port='COM6', baudrate=9600, bytesize=8, parity="N", stopbits=1, timeout=0.1)        # 设置电脑端为主机(Master)        master = rtu.RtuMaster(ser)        master.set_timeout(1.0)        master.set_verbose(True)    elif sys == "Linux":        ser = serial.Serial(port='/dev/ttyUSB1', baudrate=9600, bytesize=8, parity="N", stopbits=1, timeout=0.1)        # 设置电脑端为主机(Master)        master = rtu.RtuMaster(ser)        master.set_timeout(1.0)        master.set_verbose(True)    else:        print("系统错误")except Exception as e:    print("串口系统错误")def fun_timer():    read_values = master.execute(1, cst.HOLDING_REGISTERS, 0x01, 12)      # 烟感设备地址 1    # print(read_values)  # (0, 0, 0, 0, 0, 0, 259, 0, 0, 0, 0, 0)    # print(read_values[2])  # (0, 0, 1, 0, 0, 0, 259, 0, 0, 0, 0, 0)    # 报警器状态说明:    # 报警器状态代码: 0 或 1    # 报警器状态: 0 代表 正常没有烟雾 1 代表有烟报警    if read_values[2] == 0:        print('检测没有烟雾正常')    else:        print('检测到烟雾并报警')    global timer    timer = threading.Timer(1, fun_timer)    timer.start()timer = threading.Timer(1, fun_timer)timer.start()

转载地址:https://blog.csdn.net/weixin_45523107/article/details/116452603 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:python 安装 aliyunsdkiotclient 模块报错问题决方案
下一篇:python面试,内附答案

发表评论

最新留言

不错!
[***.144.177.141]2024年04月25日 10时52分21秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

spring boot 与 Ant Design of Vue 实现删除组织(二十六) 2019-04-27
spring boot 与 Ant Design of Vue 实现获取用户列表(二十七) 2019-04-27
spring boot 与 Ant Design of Vue 实现新增用户(二十八) 2019-04-27
spring boot 与 Ant Design of Vue 实现修改用户(二十九) 2019-04-27
spring boot 与 Ant Design of Vue 实现删除用户(三十) 2019-04-27
spring boot 与 Ant Design of Vue 鉴权体系登录的实现(三十一) 2019-04-27
spring boot 与 Ant Design of Vue 鉴权体系获取用户信息的实现(三十二) 2019-04-27
Druid连接池实现自定义场景的多数据库的连接 2019-04-27
CentOs7命令行(静默)的方式安装oracle数据库 2019-04-27
基于VMware安装CentOs7的镜像 2019-04-27
PL/SQL数据库管理工具的使用 2019-04-27
史上最简单的spring-boot集成websocket的实现方式 2019-04-27
带你玩转属于自己的spring-boot-starter系列(一) 2019-04-27
带你玩转属于自己自己的spring-boot-starter系列(二) 2019-04-27
带你玩转属于自己的spring-boot-starter系列(三) 2019-04-27
基于SnowFlake算法如何让分库分表中不同的ID落在同一个库的算法的实现 2019-04-27
基于springboot的ShardingSphere5.X的分库分表的解决方案之分库解决方案(二) 2019-04-27
基于springboot的ShardingSphere5.X的分库分表的解决方案之分表解决方案(一) 2019-04-27
基于springboot的ShardingSphere5.X的分库分表的解决方案之关联查询解决方案(三) 2019-04-27
基于springboot的ShardingSphere5.X的分库分表的解决方案之基于seata的分布式事务的解决方案(十五) 2019-04-27