wjmnelis
Posts: 16
Joined: Thu Oct 26, 2017 5:03 pm

serial port API documentation

Thu Aug 16, 2018 5:29 pm

My next project is to read asynchronous (9600, 8N1) data from a bus. Each message is terminated by a break signal. I hope it will be possible to read messages from the serial async port using Python 3. I have been searching for documentation of the API for the serial port on a Raspberry Pi 0W (or 3B) running a recent version of Raspbian, but I did not find it. Can someone give a pointer to such documentation?

User avatar
joan
Posts: 13540
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: serial port API documentation

Thu Aug 16, 2018 5:35 pm

What documentation do you expect for a serial port?

Any relevant documentation will be in the Python serial module you choose to use.

wjmnelis
Posts: 16
Joined: Thu Oct 26, 2017 5:03 pm

Re: serial port API documentation

Fri Aug 17, 2018 10:43 am

The most important I am looking for are ways to handle the reception of a break signal. The only serial Python module I know of is PySerial. With this module, one can send a break, but I've found nothing about receiving a break signal. Perhaps I need to go one level deeper, and use Linux I/O and ioctl to do what I want to be done. Even with the use of Google, I could not find any serial port specific ioctl documentation.

User avatar
joan
Posts: 13540
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: serial port API documentation

Fri Aug 17, 2018 11:36 am

I'd avoid break if possible. Is it even part of any standard? Can you find an alternative way to signal the condition?

wjmnelis
Posts: 16
Joined: Thu Oct 26, 2017 5:03 pm

Re: serial port API documentation

Sun Aug 19, 2018 2:50 pm

Yes, it's part of a proprietary standard called EMS, which is the protocol used between in the central heating systems of a few manufacturers, amongst which Nefit.

Paul Hutch
Posts: 279
Joined: Fri Aug 25, 2017 2:58 pm
Location: Blackstone River Valley, MA, USA

Re: serial port API documentation

Mon Aug 20, 2018 2:31 pm

I think you will need to use lower level code to detect a break and depending on the hardware UART's architecture it may not be detectable. Break is simply a signal outside the limits set in the TIA-232 standard (above -3V and below +3V, like a break in the wiring will give). Some modern hardware UARTS consider 0 volts a valid signal for a simpler hardware design (not TIA-232 compliant) so with those UARTS a break is not detectable.

wjmnelis
Posts: 16
Joined: Thu Oct 26, 2017 5:03 pm

Re: serial port API documentation

Wed Aug 29, 2018 8:30 am

A break is a logical zero which lasts longer than one word, thus from start bit up to and including the stop bits.
The original question still stands: where can I find some documentation about his "lower level coding", which is hopefully an API.
This APi in turn can hopefully be used to extend module PySerial to recognise a received break signal when using the PL011 of an RPi.

User avatar
joan
Posts: 13540
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: serial port API documentation

Wed Aug 29, 2018 9:38 am

I doubt such general documentation exists.

Here is a method of detecting the condition.

Code: Select all

#!/usr/bin/env python

import pigpio
import time

RX=15

BREAK_MICROS = int(11.0/9600.0*1e6)

def break_detected():
   print("break detected")

def callback_func(gpio, level, tick):
   break_detected()           # long low detected

pi = pigpio.pi()              # connect to daemon
if not pi.connected:
   exit()

pi.set_glitch_filter(RX, BREAK_MICROS) # ignore short level changes

print(BREAK_MICROS)

cb = pi.callback(RX, pigpio.FALLING_EDGE, callback_func)

time.sleep(300)

cb.cancel()                    # cancel callback
pi.set_glitch_filter(RX, 0)    # cancel glitch filter
pi.stop()                      # disconnect from daemon


6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5557
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: serial port API documentation

Wed Aug 29, 2018 11:11 am

https://github.com/raspberrypi/linux/bl ... al/tty.txt
set_termios()
Notify the tty driver that the device's termios
settings have changed. New settings are in
tty->termios. Previous settings should be passed in
the "old" argument.

The API is defined such that the driver should return
the actual modes selected. This means that the
driver function is responsible for modifying any
bits in the request it cannot fulfill to indicate
the actual modes being used. A device with no
hardware capability for change (e.g. a USB dongle or
virtual port) can provide NULL for this method.
https://linux.die.net/man/3/termios
c_iflag flag constants:
...
If IGNBRK is set, a BREAK is ignored. If it is not set but BRKINT is set, then a BREAK causes the input and output queues to be flushed, and if the terminal is the controlling terminal of a foreground process group, it will cause a SIGINT to be sent to this foreground process group. When neither IGNBRK nor BRKINT are set, a BREAK reads as a null byte ('\0'), except when PARMRK is set, in which case it reads as the sequence \377 \0 \0.
So it appears your want to set PARMRK and BRKINT, and then monitor the incoming data stream for 0xFF,0x00,0x00 (don't ask why they quote it in octal!)
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
davidcoton
Posts: 3124
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: serial port API documentation

Wed Aug 29, 2018 1:07 pm

6by9 wrote:
Wed Aug 29, 2018 11:11 am
https://github.com/raspberrypi/linux/bl ... al/tty.txt
c_iflag flag constants:
...
... BRKINT is set, then a BREAK causes the input and output queues to be flushed, and if the terminal is the controlling terminal of a foreground process group, it will cause a SIGINT to be sent to this foreground process group. When neither IGNBRK nor BRKINT are set, a BREAK reads as a null byte ('\0'), except when PARMRK is set, in which case it reads as the sequence \377 \0 \0.
So it appears your want to set PARMRK and BRKINT, and then monitor the incoming data stream for 0xFF,0x00,0x00 (don't ask why they quote it in octal!)
As I read that, to get the byte sequence representing BREAK in the stream, only PARMRK should be set, IGNBRK and BRKINT should be unset. :?
"Thanks for saving my life." See https://www.raspberrypi.org/forums/viewtopic.php?p=1327656#p1327656
“Raspberry Pi is a trademark of the Raspberry Pi Foundation”

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5557
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: serial port API documentation

Wed Aug 29, 2018 1:32 pm

davidcoton wrote:
Wed Aug 29, 2018 1:07 pm
As I read that, to get the byte sequence representing BREAK in the stream, only PARMRK should be set, IGNBRK and BRKINT should be unset. :?
You're right, my bad. I skim read it and stumbled over the "if this else that" phrasing.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

wjmnelis
Posts: 16
Joined: Thu Oct 26, 2017 5:03 pm

Re: serial port API documentation

Sun Sep 02, 2018 2:17 pm

Thanks for the pointers. Although anxious to get started, I now have to wait for the hardware (level shifter) to arrive.

Return to “Advanced users”

Who is online

Users browsing this forum: verkerkbr and 10 guests