2

I'm trying to use a usb-to-rs232 adapter to send a serial command to a device connected to the rs232 port. When I login into screen using screen /dev/cu.usbserial 9600 and then enter my command from within the screen program, I get the expected response.

What I'm now trying to do is send a single serial command via a command line, but can't get my syntax quite right.

Here's an example of what I'm trying:

screen -dmS -p 0 /dev/cu.usbserial 9600 "MVUP"

...where MVUP with a carrier return is all I'm needing to send. I don't need to read a response back. Environment is OS X 10.7 and using the default bash shell.

  • man screen: -d -m Start screen in "detached" mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts. The other point is the -p 0 (from man ->) The command will not be executed if the specified window could not be found. So that could not works if it is not create once. Maybe you could try -d -mS -p 0 or just -d -mS – aurelien Apr 2 '16 at 14:07
  • or -mS -p 0 -d to detached immediately after create – aurelien Apr 2 '16 at 14:07
2

It is because of the space!

screen -dmS -p 0 /dev/cu.usbserial 9600 "MVUP"

but

screen -dmS -p0 /dev/cu.usbserial 9600 "MVUP"

works fine on my BBB

then to attach

screen -rmS -p0 /dev/cu.usbserial 9600 "MVUP"



aurelien@snowball:~$ sudo screen -rmS -p0 /dev/ttyUSB0 115200
[remote detached from 2845.-p0]
aurelien@snowball:~$ sudo screen -dmS -p0 /dev/ttyUSB0 115200
aurelien@snowball:~$ sudo screen -rmS -p0 /dev/ttyUSB0 115200
There are several suitable screens on:
        2861.-p0        (04/02/2016 04:10:25 PM)        (Detached)
        2845.-p0        (04/02/2016 04:10:07 PM)        (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.
aurelien@snowball:~$ sudo screen -dmS -p0 /dev/ttyUSB0 115200
aurelien@snowball:~$ sudo screen -rmS -p0 /dev/ttyUSB0 115200
There are several suitable screens on:
        2971.-p0        (04/02/2016 04:13:09 PM)        (Detached)
        2861.-p0        (04/02/2016 04:10:25 PM)        (Detached)
        2845.-p0        (04/02/2016 04:10:07 PM)        (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.

To attach you need to specify the number

sudo screen -rmS **2845** -p0 /dev/ttyUSB0 115200

or give them different name withe -p option -p0 -1 to have not the trouble like in the example of different screen all named 0! That will offer you a simple re-attach way

sudo screen -dmS -p0 /dev/ttyUSB0 115200
sudo screen -rmS -p0 /dev/ttyUSB0 115200

sudo screen -dmS -p1 /dev/ttyUSB0 115200
sudo screen -rmS -p1 /dev/ttyUSB0 115200

sudo screen -dmS -p2 /dev/ttyUSB0 115200
sudo screen -rmS -p2 /dev/ttyUSB0 115200

...

  • Thanks for the help--unfortunately, it's still not working. I'm now wondering whether or not a carriage return is being sent after the "MVUP"? I've also tried "MVUP\r". Anyone know how what screen defaults to or how to insert the return? – johnxreid Apr 3 '16 at 11:46
0

In the past I've started a session, then sent data to it using stuff with \n for newline:

screen -d -m -S myscreen /dev/cu.usbserial 9600
screen -S myscreen -X stuff 'MVUP\n' 

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.