Python For Serial Communication PDF
Python For Serial Communication PDF
Eka A. Kurniawan
@ekaakurniawan
Outline
Serial Communication Architecture Dri er !n"tallation pySerial #o$ule Demo on Con"ole %&! 'ool De elopment Demo on %&!
FPGA
&A(' Connection
USB to UART
+P%A )oar$
&S) Ca*le
Buffer
(e-ue"t
User
,aptop
Driver Installation
FPGA
&A(' Connection
USB to UART
+P%A )oar$
&S) Ca*le
Buffer
(e-ue"t
User
,aptop
ySerial !o"ule
pySerial mo$ule encap"ulate" the acce"" .or the "erial port. !t pro i$e" *acken$" .or Python running on 1in$ow", ,inu2, )SD 3po""i*ly any P4S!5 compliant "y"tem6, 7ython an$ !ronPython 3.8E' an$ #ono6. 'he mo$ule name$ 9"erial: automatically "elect" the appropriate *acken$. ; Chri" ,iechti )ene.it"<
ySerial !o"ule
Installation
+rom Source %et the archi e 3py"erial;2.y.tar.g>6 .rom http<??pypi.python.org?pypi?py"erial. &npack it, go to py"erial;2.y $irectory an$ run<
python setup.py install
&*untu 10.10
ySerial !o"ule
Basic Functions
Serial Cla""
ser = serial.Serial('/dev/ttyUSB0', 9600)
write +unction
ser. rite('!')
ySerial !o"ule
Basic Functions
in1aiting +unction
ser.in"aitin#()
rea$ +unction
ser.read($%%) ser.read(ser.in"aitin#())
clo"e +unction
ser.&lose()
Demo on Console
&"ing PyAt SPPyAt 'ool 'ip 1< Checking .or 8ew Data 'ip 2< Detecting 8ew De ice
4pen Connection
8o
Di"play Data
Ce"
Sen$ Data
4pen Connection
8o
Sen$ Data
'hrea$ #etho$ A$ antage< 8o )locking Signal 'hrea$ Com*ine$ with (ea$ )locking Pro i$e" (e"ource E..iciency
ser.3ead(!)
4pen Connection
Co$e !mplementation .or 'hrea$ with (ea$ )locking #etho$ &"ing PyAt (ea$er 'hrea$ Keep" ,ooping on +ollowing Co$e
data = sel'.ser.read(!) n = sel'.ser.in"aitin#() i' n4 data = data 5 sel'.ser.read(n) sel'.emit(S-.)/0(1ne 6ata(*Strin#)1), data)
CP&1
CP&2
&S);to;Serial Communication
/dev/ttyUSB7
Demo on GUI
)in%s
Silicon ,a*" CP2100 &S) to &A(' )ri$ge /CP Dri er" Downloa$ing pySerial pySerial Documentation pySerial AP! PyAt (e.erence %ui$e SPPyAt 'ool ProDect Eome
S ecial Than%s