Questions tagged [pyserial]

pySerial is a Python module that encapsulates the access for the serial port. It provides backends for different platforms and Python implementations.

pySerial encapsulates the access for the serial port. It provides backends for Python running on Windows, Linux, BSD (possibly any POSIX compliant system), Jython and IronPython (.NET and Mono). The module named serial automatically selects the appropriate backend.

This is an example extracted from the introduction of the documentation:

>>> import serial
>>> ser = serial.Serial(0)  # open first serial port
>>> print(ser.portstr)      # check which port was really used
>>> ser.write("hello")      # write a string
>>> ser.close()             # close port

References:

2268 questions
10
votes
1 answer

What is inter_byte_timeout (interCharTimeout) in pyserial?

Previously interCharTimeout, since version 3.0 inter_byte_timeout. API: http://pyserial.readthedocs.org/en/latest/pyserial_api.html#serial.Serial.inter_byte_timeout I suspect that the following is the difference between the regular timeout and…
Mads Skjern
  • 5,648
  • 6
  • 36
  • 40
10
votes
2 answers

Handle exception in pyserial during disconnection

I have code which read data from serial port. try: dataIn = self.port.read(100) except serial.SerialException: #do some work return None If I disconnect device I catch exception which I can't handle someway. Traceback (most recent call…
Yuriy
  • 377
  • 1
  • 2
  • 10
10
votes
2 answers

Communicate with Firewire ports in python

I'm in an unfortunate position where I've been handed a legacy system with a firewire camera connected to an old Windows XP machine. Basically I'm trying to get this all into opencv so I can at least have a nice interface into this old…
Slater Victoroff
  • 21,376
  • 21
  • 85
  • 144
10
votes
5 answers

Serial Receiving from Arduino to Raspberry Pi with PySerial stops after a while

I'm working on a project in which I have to receive some 25 character data at a time in order to process it in Raspberry Pi. Here is the example code that generates some data I want to receive from Arduino: char i =0; char a =0; char b=0; void…
mozcelikors
  • 2,582
  • 8
  • 43
  • 77
10
votes
1 answer

Serial import python

I"m trying to use pyserial. When I do the following script. import serial ser= serial.serial("COM5", 9600) ser.write("Hello worldn") x = ser.readline() print(x) Error code: c:\Python27>python com.py Traceback (most recent call last): File…
jeffpkamp
  • 2,732
  • 2
  • 27
  • 51
10
votes
1 answer

Python not reading correct values from arduino serial output

I'm trying to read potentiometer values from an arduino using python. But my serial read values are strange. Python Code: import serial ser = serial.Serial('COM12') print ( "connected to: " + ser.portstr ) count = 1 while…
user2614726
  • 131
  • 1
  • 4
10
votes
4 answers

How to expand input buffer size of pyserial

I want to communicate with the phone via serial port. After writing some command to phone, I used ser.read(ser.inWaiting()) to get its return value, but I always got total 1020 bytes of characters, and actually, the desired returns is supposed to be…
Ired
  • 101
  • 1
  • 1
  • 3
10
votes
1 answer

ValueError: invalid literal for int() with base 16: '\x0e\xa3' Python

I get bytes from the serial port which represents the voltage on my PIC board. But I can't convert these bytes(strings) to decimal because I get the error message above. Here is the function(in fact, it's associated with tkinter button) def…
safsaf88
  • 115
  • 1
  • 1
  • 8
9
votes
9 answers

pyserial for Python 2.7.2

I'm new to Python. According to the internets I was looking for the module pyserial after receiving this error: ImportError: No module named serial I first tried to install pywin32, it went well. But it seems not to contain pyserial. :-( Then I…
powtac
  • 40,542
  • 28
  • 115
  • 170
9
votes
7 answers

PySerial [Error 5] Access is Denied

I am trying to write a program in Python that will loop to keep checking the serial port (COM4) and print out a message when the character "1" is read from the serial port. I want to send "1" over the serial port from an Arduino gadget upon the push…
TomKo
  • 129
  • 1
  • 1
  • 8
9
votes
2 answers

Python serial communication

I'm working on an Arduino project, and I am interfacing it with a Python script due to memory limitations. On the Python side I have a 2 dimensional matrix containing respective x, y values for coordinates, and in this list is 26000 coordinate…
danem
  • 1,495
  • 5
  • 19
  • 35
9
votes
2 answers

How to add bytes to bytearray in Python 3.7?

I am new the Python 3.7 and I am trying to read bytes from a serial port using the following code. I am using pySerial module and the read() function returns bytes. self.uart = serial.Serial() self.uart.port = '/dev/tty/USB0' self.uart.baudrate…
salocinx
  • 3,715
  • 8
  • 61
  • 110
9
votes
2 answers

Python Convert String to Byte

I am trying to do some serial input and output operations, and one of those is to send an 8x8 array to an external device (Arduino). The pySerial library requires that the information that I send be a byte. However, in my python code, the 8x8 matrix…
Andrew Lalis
  • 894
  • 3
  • 15
  • 26
9
votes
1 answer

Python PySerial read-line timeout

I'm using pyserial to communicate with a embedded devise. ser = serial.Serial(PORT, BAUD, timeout = TOUT) ser.write(CMD) z = ser.readline(eol='\n') So we send CMD to the device and it replies with an string of varing length ending in a '\n' if the…
Ketil
  • 93
  • 1
  • 1
  • 3
9
votes
1 answer

Sending ASCII Command using PySerial

I am trying to send the followings ASCII command: close1 using PySerial, below is my attempt: import serial #Using pyserial Library to establish connection #Global Variables ser = 0 #Initialize Serial Port def serial_connection(): COMPORT =…
Jon220
  • 161
  • 1
  • 1
  • 8