0

我的问题:

下面的代码实现了我的应用程序的所有目标,除了一个问题:我的 tkinter spinbox 设置波特率和功能正确(我认为)。它填充了 pyserial 波特率目标变量,但无论我在 spinbox 中指定什么波特率,我在 9600 处从我的 arduino 接收到的串行通信都会继续被接收并正常显示。(如果我将波特率设置为不同的速率,它不会失败吗?)

我已根据要求缩减了代码。下面是没有任何 UI 的代码,只是将接收到的串行数据打印到终端。无论我将波特率设置为多少,它都可以正常工作。但是arduino发送串行数据肯定是在9600发送。

#!/usr/bin/env python

#Import Libraries--------------------------
import serial
import Tkinter as tk
from time import sleep
import threading
import sys
import glob
import smtplib
import csv
import tkMessageBox
import datetime

#Setup--------------------------

data = True                     #I'm not sure what this is for

#Thread--------------------------
class SensorThread(threading.Thread):                                   
        def run(self):
                try:
                        i = 0
                        while True:                                     
                                ser = serial.Serial('/dev/ttyACM0', 90000)    
                                happenen = ser.readline()               
                                print(happenen)
                                i += 1                                  
                                sleep(1)                                
                except KeyboardInterrupt:                               
                        exit()                                          

#------------------------------------------------------------------
if __name__ == "__main__":
        SensorThread().start()
#------------------------------------------------------------------        
4

0 回答 0