python for serial communication(1)

Upload: pham-ngoc-hoa

Post on 03-Jun-2018

231 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Python for Serial Communication(1)

    1/21

    Python for Serial CommunicationPython for Serial Communication

    PyCon APAC 2011, SingaporePyCon APAC 2011, Singapore

    Eka A. KurniawanEka A. Kurniawan@ekaakurniawan@ekaakurniawan

  • 8/12/2019 Python for Serial Communication(1)

    2/21

    Outline

    Serial Communication Architecture

    Drier !n"tallation

    pySerial #o$ule

    Demo on Con"ole

    %&! 'ool Deelopment

    Demo on %&!

  • 8/12/2019 Python for Serial Communication(1)

    3/21

    Serial CommunicationArchitecture

    FPGA

    USB

    toUART

    &A('

    Connection

    &S) Ca*le

    Buffer

    &S) to &A('

    Drier

    User

    +P%A )oar$ aptop

    (e-ue"t

    Data +low Point o /iew

  • 8/12/2019 Python for Serial Communication(1)

    4/21

    Driver Installation

    Silicon a*" CP210 &S) to &A(' )ri$ge /CP Drier"

  • 8/12/2019 Python for Serial Communication(1)

    5/21

  • 8/12/2019 Python for Serial Communication(1)

    6/21

    ySerial !o"ule

    pySerial mo$ule encap"ulate" the acce"" or the "erial port. !tproi$e" *acken$" or Python running on in$ow", inu, )SD3po""i*ly any P4S!5 compliant "y"tem6, 7ython an$ !ronPython3.8E' an$ #ono6. 'he mo$ule name$ 9"erial: automatically "elect"the appropriate *acken$. ; Chri" iechti

    )eneit"6 romhttp

  • 8/12/2019 Python for Serial Communication(1)

    8/21

    ySerial !o"uleBasic Functions

    !mporting pySerial #o$ule

    import serial

    Serial Cla""

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

    open an$ i"4pen +unction"

    ser.open()

    ser.isOpen()

    write +unction

    ser.rite('!')

  • 8/12/2019 Python for Serial Communication(1)

    9/21

    ySerial !o"uleBasic Functions

    inaiting +unction

    ser.in"aitin#()

    rea$ +unction

    ser.read($%%)

    ser.read(ser.in"aitin#())

    clo"e +unction

    ser.&lose()

    pySerial AP!

    http

  • 8/12/2019 Python for Serial Communication(1)

    10/21

    Demo on Console

  • 8/12/2019 Python for Serial Communication(1)

    11/21

  • 8/12/2019 Python for Serial Communication(1)

    12/21

    Ti #$ Chec%in& for 'ew Data

    4pen Connection

    i" *uer emptyBDi"play Data

    %et Data

    i" u"er inputB Sen$ Data

    8o

    e"

    e"

    8o

    Polling #etho$

    A$antage< Ea"y toDeelop

    Di"a$antage"