I work with an RS-232 device via GNU screen.

$ screen /dev/ttyUSB0 115200

At some point I need to send a local file to the device using either the xmodem or kermit protocol. On Windows I use TeraTerm which has a corresponding menu item. How can I achieve this in GNU screen?

the best way to pass a file through xmodem is to use sx. In debian this application is part of 'lrzsz' package.

In debian:

apt-get install screen lrzsz

screen /dev/ttyUSB0 115200

Then press Ctrl-A followed by : and type:

exec !! sx yourbinary.bin

This will send the file to ttyUSB0 over xmodem protocol

  • Can this operation be executed non-interactively, either with screen cu or any other package? – Vorac Oct 29 '15 at 8:06
  • 1
    @Vorac you can always do sx binary.bin | socat FILE:/dev/ttyUSB0,b115200,raw - – GnP Mar 24 '16 at 19:59
  • 2
    How to give receive command Give your local XMODEM receive command now – AQU Jul 31 '17 at 10:10

If you want to use zmodem you have to set the zmodem option to pass, if your screen session is already running, press CTRL+A : and just enter zmodem pass . To send the data just use the sz command from the lrzsz package.

If you want to receive data via screen you have to set the value to catch.

  • zmodem catch is an option I've been search for for ages! Good riddance, minicom. – ijustlovemath Apr 11 '17 at 2:48

If you are trying to do this through screen on OSX, you can follow the procedure laid out by user32704 with some small modifications. You will need to first build lrzsz from source, which can be found here:

https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz

Then, instead of exec !! sx yourbinary.bin you should use:

exec !! lsz -X yourbinary.bin
  • 3
    brew install lrzsz – Daniele Brugnara Sep 2 '16 at 10:34
  • sudo port install lrzsz – miken32 Sep 20 '16 at 17:36

I was in need to automate the serial transfer of a .bin file to an xbee with xmodem so I used this sloppy bash code:

echo "Starting connection..."
screen -d -m -S uart_con /dev/ttyO1 115200
sleep 1
screen -S uart_con -X stuff 'F'$(echo -ne '\015')
sleep 1
screen -S uart_con -X exec \!\! sz -X /home/file_directory/example.abs.bin
echo "now transfering... "
sleep 20
pkill screen

The third line sends a command to the other side(xbee) to start listening for a file transfer. So you are probably good with just:

screen -d -m -S uart_con /dev/ttyUSB0 115200
screen -S uart_con -X exec \!\! sz -X /path_to_file/example.file

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.