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

python串口示波器(将串口数据接收与绘图分开)

import serial
import matplotlib.pyplot as plt
import numpy as np
import threading
import queue
import time# 创建队列用于线程间数据传递
data_queue = queue.Queue()# 配置串口
ser = serial.Serial('COM3', 115200)# 数据读取线程
def read_from_serial(ser, data_queue):while True:try:value = float(ser.readline().decode().strip())data_queue.put(value)  # 将读取到的数据放入队列except Exception as e:print(f"Error reading serial: {e}")# 启动数据读取线程
read_thread = threading.Thread(target=read_from_serial, args=(ser, data_queue))
read_thread.daemon = True
read_thread.start()# 绘图设置
plt.ion()
fig, ax = plt.subplots()
line, = ax.plot([], [])
ax.set_ylim(0, 10)  # 根据实际情况调整
ax.set_xlim(0, 100)# 数据缓冲区
data = [

http://www.mrgr.cn/news/41206.html

相关文章:

  • s5pv210 -- 集合
  • 六.应用层
  • 命令行操作的基本指令【Linux】学完使用操作命令行就像喝汤一样快
  • 计算机网络:计算机网络体系结构 —— OSI 模型 与 TCP/IP 模型
  • PayPal轮询系统
  • 2024年9月30日--10月6日(ue5肉鸽结束)
  • python之数据类型详解
  • 开放式耳机的优缺点?哪个品牌专业?好用的开放式蓝牙耳机分享
  • 只出现一次的数字|||(考察点为位操作符)
  • 遗传算法与深度学习实战(15)——差分进化详解与实现
  • 仅需10G显存,使用 Unsloth 微调 Qwen2 并使用 Ollama 推理
  • RAC被修改权限及相关问题
  • Prometheus监控MySQL主从数据库
  • linux 端口 进程
  • LC记录二:丑数专题,一文秒解丑数3题
  • 操作符详解与表达式求值
  • java OOP基础:类与对象(万字长文)
  • 什么是基尼指数
  • SpringBoot与校园健康信息管理的融合
  • wordpress源码资源站整站打包32GB数据,含6.7W条资源数据