How to send a BREAK on a serial port from command line in Raspbian Linux?

5,113

I believe the current Raspbian still doesn't come with screen either. If it did, you could run screen /dev/ttyWhatever then hit Ctrl-a b. Ref.

A break is specific to serial interfaces, and does not have a control/escape character representation, so the generic echo, cat and friends do not have a mechanism for sending a break. Thus, the best you could do is call on a serial library in your favourite programming language. I believe Raspbian comes with Python, probably Perl, and maybe gcc too, so any of these three would do the trick:

Python

python -c 'import termios; termios.tcsendbreak(3, 0)' 3>/dev/yourdevicename

Perl

perl -e 'use POSIX; tcsendbreak(3, 0)' 3>/dev/yourdevicename

C

#include <termios.h>
#include <fcntl.h>

int main() { tcsendbreak(open("/dev/yourdevicename", O_RDWR), 0); }

And finally, if you really want to use built-ins, set the baud rate of your serial device much lower than standard and send a NULL. For example:

stty -F /dev/yourdevicename 9600
echo -ne '\0' > /dev/yourdevicename
Share:
5,113

Related videos on Youtube

bigjosh
Author by

bigjosh

Updated on September 18, 2022

Comments

  • bigjosh
    bigjosh over 1 year

    I am looking for a way to send a serial BREAK from a shell script in the Debian Linux that comes default on a Raspberry PI without needing any additional software to be downloaded or compiled.

    Unfortunately, this distribution does not seem to have SETSERIAL or MINITERM, either of which would make this easy.

    Note that this would be trivial to do from a C program, and possible to do from a Python program - but I am really looking for a way to do it using only the shell for both aesthetic reasons and also because I can't figure it out myself... :)

    -josh

  • bigjosh
    bigjosh almost 10 years
    Thanks for the comment. I should have been more explicit that I am looking for a way to send a BREAK out the local serial port. Thanks!
  • bigjosh
    bigjosh about 5 years
    set the baud rate of your serial device much lower than standard and send a NULL This is a very clever hack solution!. I'll try it!
  • Heath Raftery
    Heath Raftery about 5 years
    @bigjosh I first saw it as a way to initiate a DMX transmission, which requires a two-character wide break. For bare metal that doesn't have the concept of a break, it is a useful trick.