将Jupyter Notebook(.ipynb)文件转换为Python(.py)文件的3种方法_python_脚本之家
python
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import sys
import serial
import threading
from datetime import datetime
input_flag = 0
class UART(object):
def __init__(self,port,baud):
# print("初始化")
self.err = 0
try:
self.serial = serial.Serial(port,baud)
print("串口连接成功")
except:
print("串口连接失败")
self.err = -1;
def uart_rev_wait(self):
print("开始接收")
# 串口接收
while(True):
try:
rev_data = self.serial.readline()
# text = "当前时间"
now = datetime.now()
formatted_str = now.strftime('%Y-%m-%d %H:%M:%S')
data = formatted_str +"------"+ "串口数据:"+ rev_data.decode();
# print("DEV_NUM:"+port)
print(data)
except:
print("接收数据失败")
def uart_rev_start(self):
print("创建接收线程")
thread = threading.Thread(target=self.uart_rev_wait,daemon = True)
thread.start()
if __name__ == '__main__':
# print("主线程")
uart0 = UART("COM27",115200)
if(0==uart0.err):
print("init UART success")
uart0.uart_rev_start()
while(True):
# print("主线程runing")
if(input_flag == 1):
break;
print("exit")
# In[ ]: