import serial
import time
ser = serial.Serial('com4',115200,timeout=1)
while 1:
time.sleep(10)
print ser.readline()
我不想使用串行模块,而只能在我的代码中使用标准的Python模块。
任何快速建议我该怎么做?
pyserial用纯Python写成;您可以将
serial
文件夹复制到您的项目中,并且它可以无需安装任何内容即可工作。
在内而已,您可以在不包括整个库的情况下看到有关如何在平台上实现类似功能的源代码。Import系列 导入pyautogui
开放的串行端口
ARDUINO= serial.Serial('com7',9600)#com端口可能会根据您的系统而有所不同if command == "button_pressed":
pyautogui.press('enter') # Simulate pressing the 'Enter' key on laptop
print("Enter key pressed!")