pySerial¶
This module encapsulates the access for the serial port. It provides backends for Python running on Windows, OSX, Linux, BSD (possibly any POSIX compliant system) and IronPython. The module named “serial” automatically selects the appropriate backend.
It is released under a free software license, see LICENSE for more details.
Copyright (C) 2001-2020 Chris Liechti
Other pages (online)
- project page on GitHub
- Download Page with releases (PyPi)
- This page, when viewed online is at https://pyserial.readthedocs.io/en/latest/ or http://pythonhosted.org/pyserial/ .
Features¶
- Same class based interface on all supported platforms.
- Access to the port settings through Python properties.
- Support for different byte sizes, stop bits, parity and flow control with RTS/CTS and/or Xon/Xoff.
- Working with or without receive timeout.
- File like API with “read” and “write” (“readline” etc. also supported).
- The files in this package are 100% pure Python.
- The port is set up for binary transmission. No NULL byte stripping, CR-LF translation etc. (which are many times enabled for POSIX.) This makes this module universally useful.
- Compatible with io library
- RFC 2217 client (experimental), server provided in the examples.
Requirements¶
- Python 2.7 or Python 3.4 and newer
- If running on Windows: Windows 7 or newer
- If running on Jython: “Java Communications” (JavaComm) or compatible extension for Java
For older installations (older Python versions or older operating systems), see older versions below.
Installation¶
This installs a package that can be used from Python ( import serial ).
To install for all users on the system, administrator rights (root) may be required.
From PyPI¶
pySerial can be installed from PyPI:
python -m pip install pyserial
Using the python / python3 executable of the desired version (2.7/3.x).
Developers also may be interested to get the source archive, because it contains examples, tests and the this documentation.
From Conda¶
pySerial can be installed from Conda:
conda install pyserial or conda install -c conda-forge pyserial
Currently the default conda channel will provide version 3.4 whereas the conda-forge channel provides the current 3.x version.
From source (zip/tar.gz or checkout)¶
Download the archive from http://pypi.python.org/pypi/pyserial or https://github.com/pyserial/pyserial/releases. Unpack the archive, enter the pyserial-x.y directory and run:
python setup.py install
Using the python / python3 executable of the desired version (2.7/3.x).
Packages¶
There are also packaged versions for some Linux distributions:
- Debian/Ubuntu: “python-serial”, “python3-serial”
- Fedora / RHEL / CentOS / EPEL: “pyserial”
- Arch Linux: “python-pyserial”
- Gentoo: “dev-python/pyserial”
Note that some distributions may package an older version of pySerial. These packages are created and maintained by developers working on these distributions.
References¶
- Python: http://www.python.org/
- Jython: http://www.jython.org/
- IronPython: http://www.codeplex.com/IronPython
Older Versions¶
Older versions are still available on the current download page or the old download page. The last version of pySerial’s 2.x series was 2.7, compatible with Python 2.3 and newer and partially with early Python 3.x versions.
pySerial 1.21 is compatible with Python 2.0 on Windows, Linux and several un*x like systems, MacOSX and Jython.
On Windows, releases older than 2.5 will depend on pywin32 (previously known as win32all). WinXP is supported up to 3.0.1.
© Copyright 2001-2020, Chris Liechti Revision 7aeea354 .
Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: latest
Versions latest stable Downloads pdf html epub On Read the Docs Project Home Builds Free document hosting provided by Read the Docs.
Serial-порт: как с ним работать?
Очень часто при отладке различных программ на Arduino используется так называемый Serial-порт. Из него можно как считывать данные, так и отправлять команды на наше устройство.
Посмотрим, как работать с Serial, но не со стороны Arduino, а со стороны компьютера. Готовы? Поехали!
Вариант первый. Arduino IDE
Один из инструментов, входящих в состав Arduino IDE, носит гордое название — Монитор порта. Он может быть запущен только когда плата подключена к компьютеру. Есть возможность изменять скорость передачи данных, и символ окончания строки.


Если мы хотим работать только с текстом — рабочий вариант, но если при подключении открывается консоль(например в случае с Micropython), об удобстве можно забыть.
Вариант второй. Специализированное ПО
Поскольку интерфейс Serial-порта используется не только при разработке микроконтроллеров, но и в других областях IT были созданы специальные программы, для удобного взаимодействия или управления.
Одним из самых популярных решений для Windows — является программа PuTTY. Не смотря на то, что она заявлена как SSH клиент, её очень часто используют для подключения по COM-порту.


Для этого необходимо на основной вкладке среди способов подключения выбрать Serial , ввести имя порта, скорость и нажать на Open .
К сожалению данная программа доступна только для Windows. Пользователям MacOS — можно использовать CoolTerm(кстати, он доступен и для Windows и Linux)


или программу с простым названием Serial, правда за её использование после пробного периода придётся отдать 30$.


Вариант третий. Программирование
Но в том случае, когда у вас уже готовое устройство и вам необходимо им управлять, каждый раз отправлять команду — очень не удобно. Гораздо проще автоматизировать это, написав свою программу.
Для того, что бы написать программу для управления устройством через Serial-порт на Python, необходимо использовать библиотеку PySerial . Её можно установить через менеджер пакетов: pip install pyserial .
Для создания подключения и отправки сообщения необходим следующий код:
my_serial = serial.Serial('/dev/ttyS1', 115200) my_serial.write(b'command_1') my_serial.close()
Он откроет подключение на порту /dev/ttyS1 , со скоростью 115200 , затем отправит на устройство байтовую строчку b’command_1′ , а после этого закроет подключение.
Подробнее об использовании библиотеки можно прочитать в этой статье.
Данная статья является собственностью Amperkot.ru. При перепечатке данного материала активная ссылка на первоисточник, не закрытая для индексации поисковыми системами, обязательна.
Arduino Lesson 17. Email Sending Movement Detector

You will be redirected back to this guide once you sign in, and can then subscribe to this guide.
If you are using a Mac or Linux computer, the Python is already installed. If you are using Windows, then you will need to install it. In either case, you will also need to install the PySerial library to allow communication with the Arduino.
Install Python on Windows
To install Python on Windows, download the installer from http://www.python.org/getit/.
This project was built using Python 2.7.3
There are some reported problems with PySerial on Windows, using Python 3, so stick to Python 2.

Once Python is installed, you will find a new Program Group on your Start menu. However, we are going to make a change to Windows to allow you to use Python from the Command Prompt. You will need this to be able to install PySerial.
We are going to add something to the PATH environment variable.

To do this, you need to go to the Windows Control panel and find the System Properties control. Then click on the button labelled “Environment Variables” and in the window that pops-up select “Path” in the bottom section (System Variables). Click “Edit” and then at the end of the “Variable Value” without deleting any of the text already there, add the text: ;C:\Python27
Don’t forget the «;» before the new bit!
To test that it worked okay, start a new Command Prompt (DOS Prompt) and enter the command “python”. You should see something like this:

Install PySerial
Whatever your operating system, download the .tar.gz install package for PySerial 2.6 from https://pypi.python.org/pypi/pyserial
This will give you a file called: pyserial-2.6.tar.gz
If you are using windows you need to uncompress this into a folder. Unfortunately, it is not a normal zip file, so you may need to download a tool such as 7-zip (http://www.7-zip.org/).
If you are using a Mac or Linux computer, then open a Terminal session, ‘cd’ to wherever you downloaded pyserial-2.6.tar.gz and then issue the following command to unpack the installation folder.
$ tar -xzf pyserial-2.6.tar.gz
$ tar -xzf pyserial-2.6.tar.gz
The rest of the procedure is the same whatever your operating system. Use you Comamnd Prompt / Terminal session and “cd” into the pyserial-2.6 folder, then run the command:
sudo python setup.py install
sudo python setup.py install

This guide was first published on Feb 28, 2013. It was last updated on Feb 28, 2013.
This page (Installing Python and PySerial) was last updated on Feb 28, 2013.
Text editor powered by tinymce.
pyserial 3.5
История выпусков Уведомления о выпусках | Лента RSS
Эта версия
3.5b0 предварительный выпуск
Загрузка файлов
Загрузите файл для вашей платформы. Если вы не уверены, какой выбрать, узнайте больше об установке пакетов.
Source Distribution
Uploaded 23 нояб. 2020 г. source
Built Distribution
Uploaded 23 нояб. 2020 г. py2 py3
Хеши для pyserial-3.5.tar.gz
| Алгоритм | Хеш-дайджест | |
|---|---|---|
| SHA256 | 3c77e014170dfffbd816e6ffc205e9842efb10be9f58ec16d3e8675b4925cddb | Копировать |
| MD5 | 1cf25a76da59b530dbfc2cf99392dc83 | Копировать |
| BLAKE2b-256 | 1e7dae3f0a63f41e4d2f6cb66a5b57197850f919f59e558159a4dd3a818f5082 | Копировать |
Хеши для pyserial-3.5-py2.py3-none-any.whl
| Алгоритм | Хеш-дайджест | |
|---|---|---|
| SHA256 | c4451db6ba391ca6ca299fb3ec7bae67a5c55dde170964c7a14ceefec02f2cf0 | Копировать |
| MD5 | b6b182ebaf20199e9788214cae349df4 | Копировать |
| BLAKE2b-256 | 07bc587a445451b253b285629263eb51c2d8e9bcea4fc97826266d186f96f558 | Копировать |
Помощь
О PyPI
Внесение вклада в PyPI
Использование PyPI
Разработано и поддерживается сообществом Python’а для сообщества Python’а.
Пожертвуйте сегодня!
PyPI», «Python Package Index» и логотипы блоков являются зарегистрированными товарными знаками Python Software Foundation.
