24

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?

George M
  • 13,959

5 Answers5

34

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

user32704
  • 341
9

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.

Ulrich Dangel
  • 25,369
5

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
4

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
minn3h
  • 41
1

Quoting AltairClone.com Using “screen” as terminal emulator under UNIX/LINUX https://altairclone.com/downloads/Using%20SCREEN%20as%20terminal%20emulator.pdf :

"

Using “screen” as terminal emulator under UNIX/LINUX

To start a session, type “screen” followed by the serial device name and baud rate:

Unix prompt> screen /dev/ttyUSB0 9600

To get to screen commands, type ctrl-a followed by a command character. To see a list of commands, type ctrl-a ? (no space after ctrl-a, ctrl is not held for ?).

To exit the current screen, type ctrl-a k

To exit all screens (if multiple started by mistake), type ctrl-a
Some versions of screen may require ctrl-a ctrl-\


To send a file with XMODEM, type ctrl-a : (colon is the command character), then at the prompt, type:

exec !! sx [-a] filename

(Use –a to convert single new-line characters to CR/LF pairs.)

To receive a file with XMODEM, type ctrl-a : (colon is the command character), then at the prompt, type:

exec !! rx [-a] filename

(Note: The first ! tells sx/rx to get stdin through screen’s input connection. The second ! tells sx/rx to route stdout through screen’s output connection.)

To change the baud rate prior to an XMODEM transfer, type ctrl-a : (colon is the command character), then at the prompt, type:

exec !! stty new_baud_rate

Alternatively, exit screen by typing ctrl-a k, then re-start screen at the new baud rate (e.g.):

Unix prompt> screen /dev/ttyUSB0 new_baud_rate

To simply send an ASCII or binary file (i.e., XMODEM not used), type ctrl-a : (colon is the command character), then at the prompt, type:

exec !! cat filename

"

ZeZNiQ
  • 111