Reply
 
Thread Tools Display Modes
  #1  
Old 11-27-2007, 10:13 AM
VunderBob VunderBob is offline
Mostly harmless
Charter Member
 
Join Date: Oct 2002
Location: The VunderLair
Posts: 15,370
Sharing a serial port between two processes in Linux

I'm working on a Linux project to route data between devices attached to a computing platform via serial lines. There is one app that maintains a socket and is responsible for writing socket data to the serial port. The other app reads the serial port, determines which socket(s) the date needs to go to, and sends the data strings on their respective merry ways. Each process, 2 to a port, is unidirectional.

When I was actively debugging, this worked quite well. Now that I'm trying to get it to work IRL for a demonstration, I'm having all kinds of trouble with port contention, and it's not working. My frustration is mounting.

Anyone know how I can get this to work?
  #2  
Old 11-27-2007, 10:28 AM
beowulff beowulff is offline
Member
 
Join Date: May 2001
Location: Scottsdale, more-or-less
Posts: 14,883
Why is this two different apps?
  #3  
Old 11-27-2007, 10:37 AM
VunderBob VunderBob is offline
Mostly harmless
Charter Member
 
Join Date: Oct 2002
Location: The VunderLair
Posts: 15,370
Quote:
Originally Posted by beowulff
Why is this two different apps?
It seems simpler in my mind to implement, along with a heaping helping of VMS experience where I could explicitely share the ports in this manner. It never occured to me that there were no similar options in Linux.

I'm mulling right now the mechanics of combining the two into one process without imposing significant latency in the end-to-end delivery times.
  #4  
Old 11-27-2007, 11:20 AM
Rysto Rysto is offline
Guest
 
Join Date: Jun 2002
Posts: 6,913
Can't you just have one application running two threads?
  #5  
Old 11-27-2007, 11:54 AM
VunderBob VunderBob is offline
Mostly harmless
Charter Member
 
Join Date: Oct 2002
Location: The VunderLair
Posts: 15,370
Quote:
Originally Posted by Rysto
Can't you just have one application running two threads?
That's where I'm headed...
  #6  
Old 11-28-2007, 08:42 AM
VunderBob VunderBob is offline
Mostly harmless
Charter Member
 
Join Date: Oct 2002
Location: The VunderLair
Posts: 15,370
Different, but related, questions.

It appears to me that a large part of the problem is that the serial ports are left open when I kill the processes, and when I restart, the processes fail because they can't open a zombie port.

Q1: Is there a way I can seize a zombie port and slam it shut during startup, and before I actually start the processes?

Q2: Is there a function similar to get_pid() that can get me a pid based on a known name of a process?
  #7  
Old 11-28-2007, 12:37 PM
Digital Stimulus Digital Stimulus is offline
Guest
 
Join Date: Jul 2003
Location: Where everything's bigger
Posts: 3,310
Quote:
Originally Posted by VunderBob
Q2: Is there a function similar to get_pid() that can get me a pid based on a known name of a process?
We always used the ps command (possibly with a "-Af" switch), piped through grep to get a particular line, then picked out what was needed from that line (e.g., using cut).

It's been awhile since I've done low-level serial port stuff, so I'm looking into it. If I find anything, I'll post it, but I have to admit that my programming was much higher level -- solutions concerning hardware were generally ad-hoc and done using command-line scripts called from within a program. I'm not sure if this'll help, but you might want to look at setserial to close/reset the port (someone in our lab used it to figure out that the default settings to open a laser range finder was rendering it inoperable, then reset the port configuration). Perhaps that'll give you a place to start looking, perhaps not.
  #8  
Old 11-28-2007, 12:58 PM
Digital Stimulus Digital Stimulus is offline
Guest
 
Join Date: Jul 2003
Location: Where everything's bigger
Posts: 3,310
It looks like socat might provide the functionality you need (descriptive article from linux.com here).

I'd never heard of it before, but it's already installed on my Debian system (that is, I didn't explicitly install it), so my guess is that it's pretty widely available.
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 04:46 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.

Send questions for Cecil Adams to: cecil@chicagoreader.com

Send comments about this website to: webmaster@straightdope.com

Terms of Use / Privacy Policy

Advertise on the Straight Dope!
(Your direct line to thousands of the smartest, hippest people on the planet, plus a few total dipsticks.)

Publishers - interested in subscribing to the Straight Dope?
Write to: sdsubscriptions@chicagoreader.com.

Copyright 2017 Sun-Times Media, LLC.

 
Copyright © 2017