Python serial port

I want to communicate with my serial port in python. I installed pyserial and uspp for linux:

import serial ser = serial.Serial('/dev/pts/1', 19200, timeout=1) print ser.portstr #check which port was really used ser.write("hello") #write a string ser.close() # 

It produces the following error:

 Traceback (most recent call last): File "poi.py", line 5, in <module> ser.open() File "/usr/local/lib/python2.6/dist-packages/pyserial-2.5-py2.6.egg/serial/serialposix.py", line 276, in open raise SerialException("could not open port %s: %s" % (self._port, msg)) serial.serialutil.SerialException: could not open port /dev/tyUSB1: [Errno 2] No such file or directory: '/dev/tyUSB1' 
+4
source share
1 answer

if you work with linux, as a rule, serial ports are called /dev/tty* ; just replace * with s and the port number, for example /dev/ttyS1 . I work with arduino which communicates via usb-serial and /dev/ttyUSB0 .

+6
source

All Articles