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
14
votes
3 answers

Python PySerial.How to know if a port is already open?

I'm trying to write an App that uses serial ports in a Linux PC, using python and PySerial. But in this PC there are other Apps using serial ports. How can I know if a port is already open by other App before trying to use it? thanks
nicolango
  • 141
  • 1
  • 1
  • 4
14
votes
5 answers

pySerial 2.6: specify end-of-line in readline()

I am sending commands to Eddie using pySerial. I need to specify a carriage-return in my readline, but pySerial 2.6 got rid of it... Is there a workaround? Here are the Eddie command set is listed on the second and third pages of this PDF. Here is a…
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
13
votes
4 answers

pySerial works fine in Python interpreter, but not standalone

Good morning! Recently I bought an Arduino board to make sort of "light control" in my room. Here is the code of the firmware I wrote: int control = 0; int pin = 0; void setup() { Serial.begin(9600); for(pin = 0; pin <= 13; pin++) pinMode(pin,…
Ivan Galinskiy
  • 135
  • 1
  • 8
13
votes
5 answers

How can I use COM and USB ports within Cygwin?

I want to send/receive data from my Arduino board with a Python script. I would like to do it using Python and its pySerial module which seems to fit my needs. So I installed Python and pySerial within cygwin (windows XP behind). The Python script…
user349188
  • 149
  • 1
  • 1
  • 7
12
votes
2 answers

Pyserial does not play well with virtual port

Motivation I want to start leraning how to use the python library Pyserial. It seems like a really nice library that works for a lot of people. I want to use it for an upcoming project in which I have to automate serial…
12
votes
3 answers

How can I improve PySerial read speed

I'm currently building a machine that uses an Arduino Mega2560 as its main controller. The Arduino is connected to over serial, gets a command, executes it and spits out a bunch of measurement data every 1ms. I have a Raspberry Pi running Python to…
ktmf
  • 378
  • 1
  • 2
  • 8
12
votes
8 answers

using serial port in python3 asyncio

i'm trying and, so far, failing to use python asyncio to access a serial port. i'd really appreciate any tips on using the new python async framework on a simple fd. Cheers! James
time4tea
  • 2,169
  • 3
  • 16
  • 21
12
votes
4 answers

Wait on Arduino auto-reset using pySerial

I'm trying to read lines from an Arduino board with a very simple code (for the sake of showcasing the problem) on Linux. Python code: # arduino.py import serial arduino = serial.Serial('/dev/ttyACM0') with arduino: while True: …
astrojuanlu
  • 6,744
  • 8
  • 45
  • 105
12
votes
6 answers

How to check if device is connected Pyserial

I am connecting with my Arduino through a USB port and sending data to it by using PySerial module. At first I can check if the device is connected by using this code: try: ser = serial.Serial("COM3", 9600) except…
Asmastas Maz
  • 357
  • 3
  • 7
  • 17
12
votes
2 answers

How do I recover from a serialException using pySerial

I have an application that reads and transmits data to a device connected via USB. I'm using pySerial to facilitate this communication. Everything works fine until the USB cable is unplugged from the PC and an exception is thrown. Once the cable…
Stephen
  • 663
  • 5
  • 13
  • 24
11
votes
7 answers

pyserial, ImportError: No module named serial

I know this question have been asked several times, but none of the solutions I saw solved my problem. I have been trying to use the serial library from Sublime Text 2 in my mac. import serial Everytime I call this library, I get this message: …
Andrea Diaz
  • 1,168
  • 4
  • 13
  • 29
11
votes
2 answers

How can I send a byte array to a serial port using Python?

I am working on an application which requires the sending of a byte array to a serial port, using the pyserial module. I have been successfully running code to do this in canopy: import serial ser = serial.Serial('/dev/ttyACM0', 9600,…
W. Stine
  • 111
  • 1
  • 1
  • 3
10
votes
3 answers

pyserial - possible to write to serial port from thread a, do blocking reads from thread b?

I tried googling this, couldn't find an answer, searched here, couldn't find an answer. Has anyone looked into whether it's thread safe to write to a Serial() object (pyserial) from thread a and do blocking reads from thread b? I know how to use…
Matthew Lund
  • 3,742
  • 8
  • 31
  • 41
10
votes
2 answers

pyserial with multiprocessing gives me a ctype error

Hi I'm trying to write a module that lets me read and send data via pyserial. I have to be able to read the data in parallel to my main script. With the help of a stackoverflow user, I have a basic and working skeleton of the program, but when I…
user169808
  • 503
  • 1
  • 6
  • 27
10
votes
2 answers

Files within Docker bind mount directory not updating

I am using docker bind mount to map the host /dev/serial/ folder generated by Ubuntu (which contains identifying symlinks to serial devices such as /dev/ttyUSB0). The full docker container run command I am using is docker run -d --restart always…
Jetkov
  • 103
  • 1
  • 1
  • 6