Comments (6)
在C++中可能会设置串口中断回调函数,这样串口数据到达后就可以立马获得数据;
但是python中我使用了一个比较简单粗暴的方法,就是开了一个线程死循环读取串口,这样做的好处就是简单可靠,但是缺点就是因为是死循环,性能会有问题,CPU占用会过高,所以在这里延时了一下下释放一下CPU占用,至于为啥是0.009,是我看着CPU使用率以及不停地给串口发数据综合的情况下取的一个值2333333
如果你有什么更好的解决办法就更好了
from comtool.
其实也许可以用read函数阻塞等待更好
http://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.Serial.read
from comtool.
感谢回复,pyserial这个没有中断回调好坑...
使用read阻塞等待应该能减少while循环次数,但是这儿有一个疑问:如果不用线程,而是用QTimer做一个定时器,比如每隔100ms去读一下串口的数据,然后数据处理逻辑不变,这种使用定时器的方式和线程+while死循环比较,哪种方式更合理一点?
貌似官方示例都是线程+while死循环的方式,感觉使用定时器的方式在某些应用场景是可以的,比如某些要实时显示传感器数据的应用,这种应用数据发送频率应该是固定的
最近遇到的问题就是这种应用里遇到的,应用大概是这么样:硬件那边通过串口不停地发送数据,上位机这边要接收数据并实时显示曲线,现在上位机程序跑一会儿就死了...任务管理器中是程序无响应...控制台还不报任何错
from comtool.
是的,pyserial没有事件,都是死循环读取。
两种方式都可以的,看你具体的要求了,反正串口助手为了实时性死循环更好,你的程序没有响应可能引起的原因很多了,多半是你的UI显示的问题,这个得你自己多调试调试找问题了
from comtool.
嗯,非常感谢
特别诡异的是,接收数据线程不加time.sleep
,程序就能多跑一会儿...
from comtool.
加sleep界面会死掉多半就是你的sleep是在UI线程调用的了~~
from comtool.
Related Issues (20)
- [Enhancement] TCP/UDP支持多网卡或者绑定指定网卡 HOT 5
- 希望团队加个tab标签页变色的小功能 HOT 4
- 打开串口长时间运行后, 运行卡顿 HOT 5
- 请求支持ARM版本的MAC HOT 9
- RK3588开发板无法正常使用该软件,请求优化 HOT 3
- error in onReceived callback: release unlocked lock HOT 1
- ubuntu打不开 HOT 1
- 关于USB权限的问题 HOT 1
- 安装问题 HOT 3
- linux系统中安装问题 HOT 1
- 希望有一个文档简单描述下内部多个线程以及协议插件的相互交互逻辑 HOT 1
- 打开多个窗口会使config.json内容出错(以及tab页分离支持) HOT 6
- 非可视非空格/TAB字符应以转义形式显示 HOT 5
- 这里是不是多了一个分号 还是我python版本不兼容这种写法 HOT 2
- issues HOT 11
- 提示缺少main2、helpAbout、Combobox等module HOT 2
- linux端串口终端不能拷贝 HOT 1
- windows下该如何使用pip安装comtool? HOT 5
- 图表部分,能不能来一个简单的协议? HOT 3
- deepin linux 上不能打开 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from comtool.