1

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

1

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>

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
  • 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! – bigjosh Apr 30 at 19:03
  • @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. – Heath Raftery May 1 at 1:34
0

I can't comment on your post due to my rep, but if you need to send a break with a modem, the following will work. If you're simply trying to send a break via RS-232, then it won't.

If you can send AT commands to a /dev/ttyS*, then sending AT\Bn should do the trick. n can be a digit between 0 and 9, and each value represents 100 ms.

So, sending AT\B4 should send a break for 500 ms.

I haven't tested this - who uses modems any more? (Actually, Best Buy still sells 56.7k modems...)

  • 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 Jul 23 '14 at 2:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.