Python中文
首页
教程
问答
标签
搜索
登录
注册
如何让python空闲/GUI与mbed板通信?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我需要一个pythongui与mbed(LPC1768)板通信。我可以将一个字符串从mbed板发送到python的IDLE,但是当我尝试将一个值发送回mbed板时,它并没有按预期工作。你知道吗</p> <p>我已经编写了一个非常基本的程序,从mbed板读取一个字符串,然后在Python的IDLE上打印出来。然后程序应要求用户输入一个值,该值应发送到mbed板。你知道吗</p> <p>此值应设置LED闪烁之间的时间。你知道吗</p> <p>python代码</p> <pre><code>import serial ser = serial.Serial('COM8', 9600) try: ser.open() except: print("Port already open") out= ser.readline() #while(1): print(out) time=input("Enter a time: " ) print (time) ser.write(time.encode()) ser.close() </code></pre> <p>以及mbed c++代码</p> <pre><code>#include "mbed.h" //DigitalOut myled(LED1); DigitalOut one(LED1); DigitalOut two(LED2); DigitalOut three(LED3); DigitalOut four(LED4); Serial pc(USBTX, USBRX); float c = 0.2; int main() { while(1) { pc.printf("Hello World!\n"); one = 1; wait(c); two=1; one = 0; wait(c); two=0; c = float(pc.getc()); three=1; wait(c); three=0; four=1; wait(c); four=0; } } </code></pre> <p>程序等待在IDLE中输入值并发送到mbed板,然后开始使用发送给它的值,但突然停止工作,我不知道为什么。你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>你需要走这条线:</p> <pre><code>c = float(pc.getc()); </code></pre> <p>从你的圈子里出来。你知道吗</p> <p>您的程序停止工作的原因是,在您再次发送某些内容之前,该行一直保持。如果你只发送一次,它将永远等待。你知道吗</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在乒乓球比赛中预测球的轨迹,对于AI球拍预测?
3 回答
如何在乒乓球游戏中阻止球
1 回答
如何在乘法和模中不乘空间?
6 回答
如何在乘法和除以2个不同的数字之间进行交换?
6 回答
如何在也是数据一部分的单个字符上拆分大字符串
7 回答
如何在乾草堆中找到針,有更好的解決方案嗎?
4 回答
如何在事件wxWidgets中传递自定义数据
6 回答
如何在事件中使用lambda i=i?
9 回答
如何在事件中心只接收最近的数据
6 回答
如何在事件发生之前保持云函数运行?
5 回答
如何在事件发生后使页面重定向到同一页面
9 回答
如何在事件回调之间保持python生成器的状态
2 回答
如何在事件处理程序(pythonsocket、sphinx)中保留docstring
2 回答
如何在事件处理程序中更改wxRichTextCtrl的光标位置?
5 回答
如何在事件处理程序中访问外部对象?
8 回答
如何在事件循环中将协程打包为正常函数?
8 回答
如何在事件循环之外运行协同程序?
3 回答
如何在事件循环结束时为并发未来的所有线程调用类方法?
10 回答
如何在事件文件中只保留一份摘要?
1 回答
如何在事件模板中添加事件
9 回答