當前位置:編程學習大全網 - 網站源碼 - linux中python怎麽打開串口

linux中python怎麽打開串口

壹個Python實現的串口Echo

import serial

import sys

try:

?ser = serial.Serial('/dev/ttyUSB0', 9600)

except Exception, e:

?print 'open serial failed.'

?exit(1)

print 'A Serial Echo Is Running...'

while True:

?# echo

?s = ser.read()

?ser.write(s)

?# write to stdout and flush it

?sys.stdout.write(s)

?sys.stdout.flush()

  • 上一篇:html的復制源碼 怎麽多行呢?
  • 下一篇:電腦怎麽玩手遊的傳奇
  • copyright 2024編程學習大全網