【Python】シリアル通信

【OS X】sudo easy_install -U pyserial

【Linux】apt-get instal python-serial

import serial
import pytz

def initSerial():

  com = serial.Serial( 
    port='/dev/ttyAMA0', 
    baudrate=9600,
    parity = serial.PARITY_NONE,
    bytesize = serial.EIGHTBITS,
    stopbits = serial.STOPBITS_ONE,
    timeout = None )
  return com


com = initSerial()
f = open('log.txt')
line = f.readline()

while line:
    com.write(line)
    line = f.readline()

Leave a Reply