我正试图通过python将数据从MacBook发送到microbit连接的USB端口。我的python程序传输数据,然后通过查看microbit的背面,我看到在发送信息时,USB端口旁边有一个小灯闪烁,因此microbit正在接收信息,但我为microbit编写的程序不会显示已发送的信息。我也遵循了一个关于如何做到这一点的教程。出了点问题,我需要帮助
import serial
import Stock_Web as SW
import time
ser = serial.Serial()
ser.baudrate = 115200
ser.port = "/dev/cu.usbmodem14102"
ser.open()
while True:
i =+ 1
i = str(i)
print('this is time ' + i)
DowPerBytes = str(SW.DowPercent())
DowPerBytes = DowPerBytes.encode()
ser.write(DowPerBytes)
time.sleep(.5)
# data = microbitdata[2:]
# data = data.replace('')
这是我的自定义模块软件:
import requests
from bs4 import BeautifulSoup as soup
def DowPercent():
url = 'https://money.cnn.com/data/markets/'
result = requests.get(url)
src = result.content
Soup = soup(src, 'html.parser')
stock_per_raw = Soup.find('span', class_="ticker-name-change", attrs={"stream": "changePct_599362", "data-ticker-name": "Dow"})
return soup.get_text(stock_per_raw)
这是微位代码:
请在下面找到一个有效的解决方案
这是我使用的块的屏幕截图:
我使用运行固件V253的microbit在DebianLinux上运行了以下Python v3.7代码。由于microbit安装的端口在每次连接时都会发生变化,因此我编写了find_comport方法,使用micro:bit的VID和PID来识别端口。示例代码中的Stock_Web.py未更改。我可以看到,例如,0.1%在LED上滚动
屏幕输出:
相关问题 更多 >
编程相关推荐