Articole similare

Comunicatie pe port serial in Python sub Windows

python-logo-bigeclipse-logopydev-logopyserial-logo

Ce ai nevoie

Configurare PySerial, PyDev pentru Python si primul program in Eclipse

Dezarhiveaza pyserial-2.6.tar.gz si ruleaza in linie de comanda python setup.py install dupa ce ai adaugat python la Windows Path, apoi urmareste pasii descrisi aici http://www.vogella.com/articles/Python/article.html pentru primul program in Eclipse.

Exemple

Scriere la COM1 @“9600,8,N,1”, no timeout

import serial
com = serial.Serial('COM1', 9600)                # open first serial port
print com.portstr                                # print the current port
com.write("www.bobtech.ro")                      # write a string
com.close()                                      # close port

Citeste de la COM1 @“19200,8,N,1”, 10ms timeout

import serial
com = serial.Serial('COM1', baudrate=19200, bytesize=8, parity='N', stopbits=1, timeout=10)
x = com.read()                                   # read one byte
s = com.read(10)                                 # read up to ten bytes (timeout)
line = com.readline()                            # read a '\n' terminated line
com.close()