Serial Port/en: различия между версиями

Материал из Wiren Board
(Новая страница: «== Before you start ==»)
м (FuzzyBot переименовал страницу Working with serial port/en в Serial Port/en без оставления перенаправления: Часть переводимой страницы Working with serial port.)
 
(не показано 15 промежуточных версий 2 участников)
Строка 3: Строка 3:
== Before you start  ==
== Before you start  ==


Монументальное описание последовательных портов - http://www.tldp.org/HOWTO/Serial-HOWTO.html
A monumental description of the serial ports - http://www.tldp.org/HOWTO/Serial-HOWTO.html


Далее будет дано краткое неточное описание.


В последовательный порт вы можете посылать данные, и получать их оттуда. В Linux последовательные порты представлены в виде некоторых псевдофайлов из папки ''/dev/'', например, в Wiren Board это ''/dev/ttyAPP0'', ''/dev/ttyNSC1'', ''/dev/ttyUSB0'' (у всех в названии есть ''tty'').
The following is a brief, inaccurate description.


Перед тем, как начать работать с портом, надо настроить его скорость и другие параметры в зависимости от того, какое устройство к нему подключено:
You can send data to the serial port and receive it from there. In Linux, serial ports are represented as some pseudo-files from the ''/dev/'' folder, for example, in the Wiren Board it is ''/dev/ttyAPP0'', ''/dev/ttyNSC1'', ''/dev/ttyUSB0'' (all have tty in the name).
* скорость в битах в секунду. Самое популярное значение 115200
* количество бит в символе, чётность, количество стоп-битов. Самая популярная конфигурация называется ''8N1'' - восемь бит в символе, проверки чётности нет, один стоп-бит
* аппаратный и программный контроль потока. Если не знаете - поставьте нет в обоих настройках.


Before you start working with the port, you need to adjust its speed and other parameters depending on what device is connected to it:
*speed in bits per second. The most popular value is 115200
*number of bits in the symbol, parity, number of stop bits. The most popular configuration is called ''8N1'' - eight bits per character, no parity, one stop bit
*hardware and software flow control. If you do not know it - put ''no'' in both cases.


== Интерактивный HEX-терминал serial_tool ==


Для интерактивной отправки и приёма данных в HEX (шестнадцатеричном) формате используйте утилиту [https://github.com/contactless/serial_tool serial_tool] (уже установлена в Wiren Board).
== Interactive HEX-terminal serial_tool ==


=== Справка по использованию ===
For interactive sending and receiving of data in HEX (hexadecimal) format, use the  [https://github.com/contactless/serial_tool serial_tool] utility (already installed on the Wiren Board).
 
===Help===


<pre>
<pre>
Строка 47: Строка 48:




=== Пример запуска ===
=== An example of running ===


<pre>
<pre>
Строка 59: Строка 60:
<< FF FF 0A 00 11 00 00 1B
<< FF FF 0A 00 11 00 00 1B
</pre>
</pre>
Здесь установлены настройки 9600 8N2, таймаут 1 секунда, порт /dev/ttyNSC1 (RS-485).
The settings are 9600 8N2, 1 second timeout, port /dev/ttyNSC1 (RS-485).




== Интерактивный режим работы из консоли ==
== Interactive mode from the console ==


Самая удобная утилита для работы с последовательным портом из консоли - '''minicom''' (есть в стандартном образе Wiren Board).
The most convenient tool to work with the serial port from the console is ''minicom'' (available in the standard image of the Wiren Board controller). Minicom is convenient to use for working with devices that are controlled by text commands or output text messages. The examples of such devices are GSM modems (controlled by AT commands), including the GSM module built into the Wiren Board; GPS modules operating under the NMEA Protocol, etc.
Minicom удобно пользоваться для работы с устройстами, которые управляются текстовыми командами или выводят текстовые сообщения. Примерами таких устройств являются GSM-модемы (управляются AT-командами), в том числе встроенный в Wiren Board GSM-модуль; GPS-модули, работающие по протоколу NMEA и т.п.


Краткая инструкция (считаем, что мы будем работать с портом /dev/ttyAPP0):
Brief instructions (we believe that we will work with the port /dev/ttyAPP0):
* В первый раз запускаем '''minicom''' с ключом, создающим профиль работы с портом (в нём хранятся номер порта, скорость передачи данных, чётность, и т.д.):
* For the first time, run minicom with a key that creates a port profile (it stores the port number, data rate, parity, etc.):
<pre>
<pre>
  $ minicom -s /dev/ttyAPP0
  $ minicom -s /dev/ttyAPP0
</pre>
</pre>
* Зайти в настройки (нажать ''Ctrl+A'', затем ''O''), выбрать пункт ''Serial port setup'', там установить порт ''/dev/ttyAPP0'', скорость и чётность - ''115200, 8N1'', ''Hardware flow control - No'', ''Software flow control - No''
* Go to settings (press Ctrl+A, then O), select Serial port setup, there set port /dev/ttyAPP0, speed and parity - 115200, 8N1, Hardware flow control - No, Software flow control - No
* Сохранить настройки: ''Save setup as _dev_ttyAPP0''
* To save settings: Save setup as _dev_ttyAPP0
* Далее запускать как:
* Then run as:
<pre>
<pre>
  $ minicom /dev/ttyAPP0
  $ minicom /dev/ttyAPP0
</pre>
</pre>
(все параметры будут сразу браться из профиля с названием ''/dev/ttyAPP0'', который мы ранее создали)
(all settings will be taken from the profile name /dev/ttyAPP0 that we previously created)
* Теперь можно вводить данные, которые вы хотите отправить в порт. Приходящие в порт данные от внешних устройств также будут выводиться
* You can now enter the data you want to send to the port. Data coming to the port from external devices will also be displayed


----
----
Строка 86: Строка 86:
== modbus-client ==
== modbus-client ==


Одним из самых удобных средств отладки коммуникаций Modbus из командной строки Wiren Board является утилита '''modbus-client'''.
One of the most convenient means of debugging Modbus communications from the command line of Wiren Board is the modbus-client utility. Description and examples can be found on this page [[modbus-client/en|modbus-client]].
Описание и примеры можно найти на этой странице [[Special:MyLanguage/modbus-client|modbus-client]].




== Работа с последовательным портом из своей программы ==
==  
Work with serial port from your program ==


http://tldp.org/HOWTO/Serial-Programming-HOWTO/
http://tldp.org/HOWTO/Serial-Programming-HOWTO/

Текущая версия на 16:36, 16 августа 2021

Другие языки:

Before you start

A monumental description of the serial ports - http://www.tldp.org/HOWTO/Serial-HOWTO.html


The following is a brief, inaccurate description.

You can send data to the serial port and receive it from there. In Linux, serial ports are represented as some pseudo-files from the /dev/ folder, for example, in the Wiren Board it is /dev/ttyAPP0, /dev/ttyNSC1, /dev/ttyUSB0 (all have tty in the name).

Before you start working with the port, you need to adjust its speed and other parameters depending on what device is connected to it:

  • speed in bits per second. The most popular value is 115200
  • number of bits in the symbol, parity, number of stop bits. The most popular configuration is called 8N1 - eight bits per character, no parity, one stop bit
  • hardware and software flow control. If you do not know it - put no in both cases.


Interactive HEX-terminal serial_tool

For interactive sending and receiving of data in HEX (hexadecimal) format, use the serial_tool utility (already installed on the Wiren Board).

Help

root@wirenboard:~# serial_tool -h
usage: serial_tool [-h] [-b BAUD] [-p PARITY] [-d DATA_BITS] [-s STOP_BITS]
                   [-t READ_TIMEOUT]
                   port

serial_tool - interactive hex serial port console

positional arguments:
  port                  Serial port to open, i.e. /dev/ttyXXX

optional arguments:
  -h, --help            show this help message and exit
  -b BAUD, --baud BAUD  Baud rate (default: 9600)
  -p PARITY, --parity PARITY
                        set parity, one of [N, E, O, M, S] (default: N)
  -d DATA_BITS, --data-bits DATA_BITS
                        set number of data bits, i.e. bytesize (default: 8)
  -s STOP_BITS, --stop-bits STOP_BITS
                        set number of stop bits, one of [1, 1.5, 2] (default:
                        1)
  -t READ_TIMEOUT, --timeout READ_TIMEOUT
                        number of seconds to wait for answer (default: 1)


An example of running

root@wirenboard:~# serial_tool -b 9600 -p N -d 8 -s 2 -t 1 /dev/ttyNSC1 
serial_tool on /dev/ttyNSC1: 9600 8N2.0
Enter your commands below in HEX form. 
All characters but 0-9,a-f including spaces are ignored.
Press Control-D or Control-C to leave the application.
Press [Enter] to print received data
>> FF FF 0A 01 11 00 00 1C
<< FF FF 0A 00 11 00 00 1B

The settings are 9600 8N2, 1 second timeout, port /dev/ttyNSC1 (RS-485).


Interactive mode from the console

The most convenient tool to work with the serial port from the console is minicom (available in the standard image of the Wiren Board controller). Minicom is convenient to use for working with devices that are controlled by text commands or output text messages. The examples of such devices are GSM modems (controlled by AT commands), including the GSM module built into the Wiren Board; GPS modules operating under the NMEA Protocol, etc.

Brief instructions (we believe that we will work with the port /dev/ttyAPP0):

  • For the first time, run minicom with a key that creates a port profile (it stores the port number, data rate, parity, etc.):
 $ minicom -s /dev/ttyAPP0
  • Go to settings (press Ctrl+A, then O), select Serial port setup, there set port /dev/ttyAPP0, speed and parity - 115200, 8N1, Hardware flow control - No, Software flow control - No
  • To save settings: Save setup as _dev_ttyAPP0
  • Then run as:
 $ minicom /dev/ttyAPP0

(all settings will be taken from the profile name /dev/ttyAPP0 that we previously created)

  • You can now enter the data you want to send to the port. Data coming to the port from external devices will also be displayed


modbus-client

One of the most convenient means of debugging Modbus communications from the command line of Wiren Board is the modbus-client utility. Description and examples can be found on this page modbus-client.


== Work with serial port from your program ==

http://tldp.org/HOWTO/Serial-Programming-HOWTO/