0

我正在做一个项目,其中程序从 com 端口读取值并将其用于游戏。我正在使用 pyserial 从 com 端口读取数据。

它工作正常,但是当我尝试使用以下代码在 pygame 中打印此值时:

myfont = pygame.font.Font(None, 70)
score=pygame.Rect(1200,100,200,200)
.
.
.
screen.fill((0,0,0))
label = myfont.render(str(SCORE),1,(0,250,0))
screen.blit(label,(1200,100))
pygame.display.update(score)

它给了我以下错误

Unhandled exception in thread started by <function brainwave at  0x00000000036A65F8>
Traceback (most recent call last):
  File "E:\Project\game\Game.py", line 38, in brainwave
    object1.start()
  File "C:\Python27\lib\site-packages\NeuroPy\NeuroPy.py", line 76, in start
    self.srl=serial.Serial(self.__port,self.__baudRate)
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 31, in __init__
    SerialBase.__init__(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\serial\serialutil.py", line 180, in _  __init__
    self.open()
  File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 62, in open
    raise SerialException("could not open port %r: %r" % (self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM3':     WindowsError(121, 'The semaphore timeout period has expired.')

如果没有用于打印的代码(上面的代码),则值可以正常读取并且游戏可以正常工作,但是当我使用此代码时,我会收到此错误。此外,即使打印代码与从 com 端口读取值无关,即它正在打印其他值,我也会收到错误消息。这个打印代码和 pyserial 是否有某种关联?请帮我

ps:如果有其他方法可以在pygame中打印文本,请告诉我。

4

0 回答 0