Results 1 to 6 of 6
All,
I'm building an embedded system and I've got a bit a quandary reading a serial port. Here's why and how:
I've got a program, written in C, which I ...
- 04-24-2008 #1
Serial + C + bash script
All,
I'm building an embedded system and I've got a bit a quandary reading a serial port. Here's why and how:
I've got a program, written in C, which I didn't write and don't want to modify at this point. It talks on ttyS1. I am interested in monitoring that traffic to decide if there's been a failure. I'd like to right a really simple bash script to read characters off ttyS1 but I'm worried that it could mess up that C program. So here's my big question: can a command like "cat /dev/ttyS1" block the serial port? Or is that all software and it won't upset the C program?
Thanks for any help!
- 04-24-2008 #2Linux Engineer
- Join Date
- Nov 2004
- Location
- Ft. Polk, LA
- Posts
- 796
Have you tried it? I tried running tail on /dev/ttyUSB0 which my modem uses, and it won't let me, saying it's unavailable. I figured it would already be blocked, and it appears I was right. I'm guessing only one thing will be able to use the device at a time. But you might go ahead and try it to find out.
- 04-24-2008 #3
I can see lots of problems with this approach. The biggest one is that even if your shell script can read from /dev/ttyS1, remember than a given byte will be read by either your shell script or the C program, not by both.
--
Bill
Old age and treachery will overcome youth and skill.
- 04-25-2008 #4Linux Engineer
- Join Date
- Nov 2004
- Location
- Ft. Polk, LA
- Posts
- 796
I just now remembered something that might be helpful. Awhile back I read about some device which takes an input and can branch it to multiple other devices. Can't remember what it's called though, but I'll keep looking around for it.
- 04-25-2008 #5
Yes, I can read from the serial port doing cat /dev/ttyS1.
This is sort of what I've been wondering about. I wasn't sure how Linux handled the serial port and if more than one process could read from it simultaneously. Do you think if one process (my C program) is reading the port and then a shell script does a read it could mess up the C program?
That sounds like exactly what I need. I'm going to poke around the Internets for that--if you think of the name please let me know!
Thanks for all the help. I'm still figuring out how to get this thing working reliably, but now I know what not to do and possibly what to do.
- 04-25-2008 #6It won't mess up the program, exactly, but it will mess up the data that the program's reading from the serial port, because the data can go to only one place, either the C program or your shell script. This is assuming that you don't find some magic bullet (either software or hardware) which takes the input data and sends it to two places.Do you think if one process (my C program) is reading the port and then a shell script does a read it could mess up the C program?
Sounds to me like the most straightforward solution is to mess with the C program that you said you don't want to mess with.--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote
