这是代码
import serial;
import struct;
import pyautogui;
pyautogui.FAILSAFE = False;
i=0;
sig=[0.1];
ser=serial.Serial('COM8',9600,);
ser.flush();
Lclick=0;
while (1):
sig[0]=(struct.unpack("<f",ser.read(4))[0]);
#print ('\n');
if (sig[0]>2.2) and Lclick==0:
pyautogui.mouseDown();
Lclick=1;
elif (sig[0]<1.9 and Lclick==1):
Lclick=0;
pyautogui.mouseUp();
ser.close();
我正在从 COM8 蓝牙串口读取柔性传感器电压。当我执行此代码时,它会单击一次,然后显示以下错误。
Traceback (most recent call last):
File "E:/sem4/embd/Project/Mclick.py", line 27, in <module>
pyautogui.mouseUp();
File "C:\Python34\lib\site-packages\pyautogui\__init__.py", line 315, in mouseUp
platformModule._mouseUp(x, y, 'left')
File "C:\Python34\lib\site-packages\pyautogui\_pyautogui_win.py", line 415, in _mouseUp
_sendMouseEvent(MOUSEEVENTF_LEFTUP, x, y)
File "C:\Python34\lib\site-packages\pyautogui\_pyautogui_win.py", line 480, in _sendMouseEvent
raise ctypes.WinError()
OSError: [WinError 997] Overlapped I/O operation is in progress.
令人惊讶的是,当打印状态未注释时,代码工作正常。我可以控制鼠标点击。我不明白它是如何做到的,以及为什么在评论 print 语句时它会给出错误。有人能帮我吗?