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
9
votes
2 answers

Python: Writing to and Reading from serial port

I've read the documentation, but can't seem to find a straight answer on this. I have a list of all COM Ports in use by Modems connected to the computer. From this list, I try to open it, send it a command, and if it says anything back, add it to…
RageCage
  • 722
  • 2
  • 6
  • 19
8
votes
5 answers

PySerial not talking to Arduino

Python version: 2.6.6 PySerial version: 2.5 Arduino board: Duemilanove 328 I have written some code to simulate some hardware I'm working with and uploaded it to the Arduino board. This code works. I know this, because I get the expected response…
Matt Ellen
  • 11,268
  • 4
  • 68
  • 90
8
votes
2 answers

Unable to send/receive data via HC-12/UART in Python

I've written some code to communicate between two Raspberry Pi's, using identical HC-12 433Mhz transceivers. I was able to successfully echo between the two Pi's using a direct serial connection and echo/cat, however am unable to replicate this…
Woodman
  • 1,502
  • 2
  • 12
  • 20
8
votes
6 answers

ImportError: cannot import name 'Serial' from 'serial' (unknown location)

Whenever i execute the code below it gives me following Error: ImportError: cannot import name 'Serial' from 'serial' (unknown location) Code: from serial import Serial arduinodata = Serial('com4',9600) print("Enter n to ON LED and f to OFF…
Kashif Iftikhar
  • 284
  • 1
  • 9
  • 28
8
votes
2 answers

Connect to serial from a PyQt GUI

I write a program to that send and recive data from serial, but I have a problem, I want to create a function "connect()" or a class, and when I press a button, the function is executed, but if I create this function in "MainWindow" class, variable…
Vesa95
  • 607
  • 1
  • 7
  • 26
8
votes
3 answers

Finding a specific serial COM port in pySerial (Windows)

I have a script built (Windows 7, Python 2.7) to list the serial ports but I'm looking for a device with a specific name. My script: import serial.tools.list_ports ports = list(serial.tools.list_ports.comports()) for p in ports: print(p) This…
coolestDisplayName
  • 161
  • 1
  • 2
  • 9
8
votes
5 answers

How can I fix "[Error 6] The handle is invalid." with PySerial

I'm trying to connect to my phone from my Windows 7 PC using PySerial with the following code: import wmi import serial c = wmi.WMI() modem = c.query("SELECT * FROM Win32_POTSModem").pop() ser = serial.Serial(modem.AttachedTo,…
alnorth29
  • 3,525
  • 2
  • 34
  • 50
8
votes
1 answer

Pyserial: How to know if a serial port is free before open it

I use python with Pyserial to use the serial port, the code like this: import serial portName = 'COM5' ser = serial.Serial(port=portName) # Use the serial port... But, the problem is, if the port is already open (by another application for…
Alain
  • 380
  • 1
  • 5
  • 15
8
votes
2 answers

Listing serial ports in Mac OS X and Python 3

I'm having trouble listing available serial ports and I really need help debugging this. In Python 2.7.5 the COM-ports are listed correctly while PySerial returns an empty list in Python 3.3.5. I found one other lonely soul with the same problems on…
tfeldmann
  • 3,108
  • 1
  • 23
  • 34
8
votes
1 answer

Using pySerial with Python 3.3

I've seen many code samples using the serial port and people say they are working codes too. The thing is, when I try the code it doesn't work. import serial ser = serial.Serial( port=0, baudrate=9600 # parity=serial.PARITY_ODD, #…
P_Rein
  • 500
  • 1
  • 6
  • 16
8
votes
2 answers

PySerial - Full-duplex communication

Is it possible to achieve full-duplex communication using PySerial? Specifically, would it be possible to monitor the port continuously for input and write whenever needed? I imagine it should be possible using threads (and serial interfaces are…
stephenfin
  • 1,447
  • 3
  • 20
  • 41
7
votes
3 answers

How to send a value from Arduino to Python and then use that value

I am in the process of building a robot that is remote controlled using Python to send control messages via the Internet through a simple GUI. I have gotten part of my code working pretty well, the GUI and control systems, but I am stuck. I am…
7
votes
2 answers

Pyserial: "module 'serial' has no attribute 'tools'"

I have some Devices connected to my Notebook via a RS485 to USB Converter and want to detect them in a python programm. I'm running this Code with PyCharm Community Edition on a Windows 7 Notebook, I've installed pyserial with pip. import serial x…
mieckhar
  • 91
  • 1
  • 2
  • 4
7
votes
2 answers

Using (DR)STRACE to compare Windows program execution

I'm posing a question here directly in relation to this issue on github for node-serialport. In a nutshell something that used to work fine in v4.x of the library no longer works in v6.x of the library. I think it must have something to do with how…
vicatcu
  • 5,407
  • 7
  • 41
  • 65
7
votes
3 answers

Python3 Two-Way Serial Communication: Reading In Data

I am trying to establish a two-way communication via Python3. There is a laser range finder plugged into one of my USB ports and I'd like to send/receive commands to that. I have a sheet of commands which can be sent and what they would return, so…
Schütze
  • 1,044
  • 5
  • 28
  • 48