Question

I'm connecting to a development board over a serial port like so..

$ screen /dev/ttyUSB0 9600

I'm connected to a boot loader now, and it is asking me to send a file in srec format. I have the file, but how can I send it over the screen session?

Was it helpful?

Solution

Hopefully you have already solved this problem yourself, but I'll answer in case anyone else have the same problem.

GNU screen has a command called readreg which you can use to read a file into a register. After a register is filled with data you can paste that data using the paste command.

Inside screen

Inside screen you press Ctr + a and then : to execute a command. Then you simply write and press enter:

readreg p /path/to/thefile

After you have executed the command you should se a message saying Slurped X character into buffer.

You can then paste the data in that buffer by again pressing Ctr + a and then :, then write and press enter:

paste p

Note: p is the name of the register

And you're done.

Outside screen

You could also execute the commands outside the screen session using the -X option. If you have a screen session named "ucontroller" which is attached to your serial port you can send the commands by executing:

screen -S ucontroller -X readreg p /path/to/thefile
screen -S ucontroller -X paste p

More resources

The information I have provided is taken directly from the man pages of screen(1), here is the relevant part of the man page:

readreg [-e encoding] [register [filename]]

Does one of two things, dependent on number of arguments: with zero or one arguments it it duplicates the paste buffer contents into the register specified or entered at the prompt.

With two arguments it reads the contents of the named file into the register, just as readbuf reads the screen-exchange file into the paste buffer. You can tell screen the encoding of the file via the -e option. The following example will paste the system's password file into the screen window (using register p, where a copy remains):

C-a : readreg p /etc/passwd

C-a : paste p

OTHER TIPS

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

"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top