Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to connect to a Khepera robot using serial interface (running Scientific Linux 6.1) I used the command screen /dev/ttyS0 to communicate which worked OK, but then I wanted to close it and use MATLAB, but I found no way to close that session, so I just clicked X on the terminal window running screen.

Now my ttyS0 port cannot be opened. Both MATLAB and screen says that it cannot open that port.

How can I reset the ttyS0 port? I mean one choice is to restart the computer. But how to do it without restarting?

What is the proper way to terminate a serial communication?

Also, what does the following command do? I've found it with Google and run it but nothing happened. Did it do anything bad what I need to fix?

/sbin/agetty -L -f /etc/issueserial 9600 ttyS0 vt100
share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

You can issue the command screen -ls to get a status of all current screen sessions. Then use the screen -r option to "reattach" to the disconnected screen session and the -X option to kill the session.

Here's an example shell session. I'm using the -d -m options to start the screen session in "detached" mode (in the background) to simulate closing the session using the X on the terminal window running screen. The 5207 from screen's -ls output is the process ID number, which will be used to "reattach" to that specific screen session.

$ screen -d -m /dev/ttyS0
$ screen -ls
There is a screen on:
    5207..host  (10/04/2011 10:16:50 AM)    (Detached)
1 Socket in /var/run/screen/S-user.

$ screen -r 5207 -X kill
$ screen -ls 
No Sockets found in /var/run/screen/S-user.

$ 
share|improve this answer
    
I did just that and could kill my process. However, my /dev/ttyS0 is still busy after this. /var/run/screen/S-<user> is empty. How do I free ttyS0? –  Gauthier May 27 at 12:17
add comment

What is the proper way to terminate a serial communication?

From a programming point of view – simply close() the opened file descriptor. Exiting the program does that automatically. However, you did not exit Screen.

One of the most commonly used GNU Screen features is the ability to detach and reattach to sessions. When you closed the window, the "server" part of Screen remained running, and you can reattach to it with screen -r.

Use C-a, k to actually kill a Screen window.

Also, what does the following command do? I've found it with Google and run it but nothing happened. Did it do anything bad what I need to fix?

/sbin/agetty -L -f /etc/issueserial 9600 ttyS0 vt100

agetty is a TTY monitor program. Its job is to reinitialize the terminal device's configuration and to display a login prompt; you can see it in action by switching to the console login prompts at tty1...tty6. 1

In this case, when you started agetty on your end, it sent a login prompt2 to the robot, which probably discarded it as garbage. It is normally harmless, unless the robot somehow interprets "login:" as "initiate world takeover". The configuration done by agetty shouldn't break anything either.


1 Note that getty does not handle actual logins – it just asks for the user name. Once you enter it, agetty starts /sbin/login to perform the login process.

2 It would also have sent the contents of /etc/issueserial text file, but since you found the command on Google, it's most likely that you don't even have that file.

share|improve this answer
    
Thanks for the writeup. I still don't understand how can I reinitialize the ttyS0 port after I incidentally closed the Screen program. I tried with ps and there was no process called screen, but the port was still in use. What can I do now? (other than restart) –  zsero Oct 4 '11 at 14:03
    
@zsero: Reattach like I suggested. (The Screen server calls itself "SCREEN", in upper case.) Alternatively, run lsof /dev/ttyS0 as root and you'll see all programs using the port. –  grawity Oct 4 '11 at 14:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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