Re: [SLUG] one serial port multiple readers
BTW, I think you asked the wrong question. For example, I personally would have fed the NMEA messages into a NMEA channel on D-BUS, allowing any application to subscribe to the message flow. But to get that answer the question is about sharing messages, not about sharing serial ports. That assumes you've got the source code to the application, and can modify it to subscribe to a D-BUS message flow. It also assumes that the application runs on an OS that supports D-BUS. Neither of those two are the case for all of the apps at this point. The answer involved some chicanery with gpsd, gpsprobe, socat, and a Windows program called HW VSP 3 (for those apps running on Windows that expect to read NMEA data from a serial port). I'm putting the solution up on a wiki shortly -- one that's well known to the sort of people who do ocean navigation and are likely to need it. -- Del Babel Com Australia http://www.babel.com.au/ -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] one serial port multiple readers
On Wed, 2009-12-30 at 18:45 +1100, Del wrote: > > USB serial ports are easy and cheap: 1 serial port per consumer > > Yeah, in this case that wasn't going to work because the object on the > end of the serial port is (a) expensive and (b) susceptible to the sort > of voltage drops that can be caused by parallelising serial ports. Yep, any PPS signal will be totally stuffed. BTW, I think you asked the wrong question. For example, I personally would have fed the NMEA messages into a NMEA channel on D-BUS, allowing any application to subscribe to the message flow. But to get that answer the question is about sharing messages, not about sharing serial ports. Best wishes, Glen -- Glen Turner www.gdt.id.au/~gdt -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] one serial port multiple readers
USB serial ports are easy and cheap: 1 serial port per consumer Yeah, in this case that wasn't going to work because the object on the end of the serial port is (a) expensive and (b) susceptible to the sort of voltage drops that can be caused by parallelising serial ports. -- Del Babel Com Australia http://www.babel.com.au/ ph: 02 9966 9476 fax: 02 9906 2864 -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] one serial port multiple readers
Terry Dawson wrote: Del wrote: Does anyone have a solution to this problem? This might do what you want: http://freshmeat.net/projects/conserver Although it could be overkill for what you want to do. It does the job, though. I found a simple solution for the specific case that I was after, and that is to use gpsd. gpsd contains a client called gpspipe which can query gpsd for the raw data received on the serial port. Then it was a matter of creating a forked gpspipe process for each incoming socket connection, which socat can do: socat -lm TCP4-LISTEN:25591,fork,reuseaddr EXEC:"/usr/bin/gpspipe -r",pty ... so every process connecting to TCP port 25591 gets its own copy of the raw NMEA data from the GPS. conserver seems to be the solution for the general case of one serial port, multiple readers (or writers), however. It seems a pretty simple exercise to write a small daemon program that opens a serial port, and listens for incoming TCP connections, multiplexing the data about as you want it though. It's not trivial but it's possible. The problem is in giving all clients a shared buffer that they can read from and allowing each client to read from the buffer using its own read pointer but also having a single write buffer pointer. Multiple FIFOs could handle it but I'd be inclined to code something using memcached or shared memory segments. Then there's the mess of cleaning up the various forked children, scavenging their read pointers for reuse, etc. I got part way through a perl implementation (before I discovered gpspipe and conserver) and it was a few hundred lines. I presume you don't need two way comms, just simplex? Yeah, in this case nobody is allowed to write to the GPS, only read from it. -- Del Babel Com Australia http://www.babel.com.au/ ph: 02 9966 9476 fax: 02 9906 2864 -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] one serial port multiple readers
On Wednesday 30 December 2009 08:12:13 slug-requ...@slug.org.au wrote: > Hi, Del. Have you considered a hardware solution using a one-to-many > transceiver? I never heard of a such a thing but I am sure it either > exists or can be built. I don't know if your clients are remote > (other locations) and that is why you are using TCP? > > Software solution: I'd write a program to read from the serial port > and write the data over TCP to any connected listeners. > > Is that too simple of an answer? For me that is solved with a 1/2 page of C. I'm sure other scripting languages do likewise. Thinks for a moment: a tcp/ip port-share-server gives the data to anyone making a connection, terminates that connection when they do ... USB serial ports are easy and cheap: 1 serial port per consumer Serials in parallel James -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] one serial port multiple readers
Del wrote: Does anyone have a solution to this problem? This might do what you want: http://freshmeat.net/projects/conserver Although it could be overkill for what you want to do. It seems a pretty simple exercise to write a small daemon program that opens a serial port, and listens for incoming TCP connections, multiplexing the data about as you want it though. I presume you don't need two way comms, just simplex? Terry -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] one serial port multiple readers
Hi, Del. Have you considered a hardware solution using a one-to-many transceiver? I never heard of a such a thing but I am sure it either exists or can be built. I don't know if your clients are remote (other locations) and that is why you are using TCP? Software solution: I'd write a program to read from the serial port and write the data over TCP to any connected listeners. Is that too simple of an answer? Yours, -at -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] one serial port multiple readers
> "del" == del writes: del> Martin Visser wrote: del> I can create a listener on one of the FIFOs above like this: del> socat -u /tmp/r1 TCP-LISTEN:2,fork,reuseaddr del> However I still hit the same issue -- the first client connects del> to port 2 and gets the data, the second listener connects to del> port 2 and then each client gets half of the data. Yes, when a client reads from the FIFO it removes the data from the fifo --- the next read, from whereever it comes, removes the next bit of data. Short of writing yourself a multiplexing device driver, I'm not sure there is a way to get what you want. Peter C -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] one serial port multiple readers
Martin Visser wrote: Del, I just did a simple test, that might help you to a solution 1. Used mkfifo to create 3 pipes "mkfifo /tmp/r1;mkfifo /tmp/r2;mkfifo /tmp/r3;" 2. Used "tee -a" to write a copy of data to each of these - "(while [ 1 ]; do date; sleep 1; done ) | tee -a /tmp/r1 | tee -a /tmp/r2 | tee -a /tmp/r3" 3. In 3 separate terminals did a "cat /tmp/r1" (and r2 and r3). This *mostly* works, but killing one listening process seems to cause the others to abort. I am guessing there is some foo I am not aware of. It doesn't solve the problem that I can't have two clients both connected to a listening TCP port on the machine and both receiving the same data. I can create a listener on one of the FIFOs above like this: socat -u /tmp/r1 TCP-LISTEN:2,fork,reuseaddr However I still hit the same issue -- the first client connects to port 2 and gets the data, the second listener connects to port 2 and then each client gets half of the data. A partial workaround appears to be to create a separate listener for each client, e.g. socat -u /tmp/r1 TCP-LISTEN:2 socat -u /tmp/r2 TCP-LISTEN:25556 socat -u /tmp/r3 TCP-LISTEN:25557 ... but that appears to defeat the purpose somewhat. I now have to configure each client to connect to a separate port. -- Del Babel Com Australia http://www.babel.com.au/ ph: 02 9966 9476 fax: 02 9906 2864 -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] one serial port multiple readers
Del, I just did a simple test, that might help you to a solution 1. Used mkfifo to create 3 pipes "mkfifo /tmp/r1;mkfifo /tmp/r2;mkfifo /tmp/r3;" 2. Used "tee -a" to write a copy of data to each of these - "(while [ 1 ]; do date; sleep 1; done ) | tee -a /tmp/r1 | tee -a /tmp/r2 | tee -a /tmp/r3" 3. In 3 separate terminals did a "cat /tmp/r1" (and r2 and r3). This *mostly* works, but killing one listening process seems to cause the others to abort. I am guessing there is some foo I am not aware of. Regards, Martin martinvisse...@gmail.com On Tue, Dec 29, 2009 at 10:03 PM, Del wrote: > > Hi, > > Does anyone have a solution to this problem? > > I have a serial port (connected to a GPS at 4800 baud). I have multiple > processes that need to read from that serial port. I need all of the > processes to read the same data, essentially creating a one way chat from > the serial port to all processes listening in. > > I've tried using socat but if I create a socket connection, using, e.g. > > socat TCP4-LISTEN:2,reuseaddr,fork /dev/ttyUSB0,b4800,raw,echo=0 > > ... then have multiple connections in to TCP socket 2, then each socket > connection gets part of the data stream from the serial port. > > I've tried setting up a multicast, but because multicast is UDP based I'm > seeing occasional packet-out-of-order and packet-dropped issues. Ideally I'd > like it to be TCP based -- I have one process that can connect to a TCP > socket for its data rather than read from the port, and I can use socat to > create PTYs for the other processes that expect a serial port provided the > data comes in in the right order. > > Yes, I know about gpsd, and one of the processes that needs to read the > serial data is gpsd, but I have some processes that need to read the raw > data provided by the GPS and not gpsd's output. > > Thanx, > > -- > Del > Babel Com Australia > http://www.babel.com.au/ > ph: 02 9966 9476 > fax: 02 9906 2864 > -- > SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ > Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html > -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] one serial port multiple readers
Del wrote: Hi, Does anyone have a solution to this problem? I have a serial port (connected to a GPS at 4800 baud). I have multiple processes that need to read from that serial port. I need all of the processes to read the same data, essentially creating a one way chat from the serial port to all processes listening in. I've tried using socat but if I create a socket connection, using, e.g. socat TCP4-LISTEN:2,reuseaddr,fork /dev/ttyUSB0,b4800,raw,echo=0 ... then have multiple connections in to TCP socket 2, then each socket connection gets part of the data stream from the serial port. I've tried setting up a multicast, but because multicast is UDP based I'm seeing occasional packet-out-of-order and packet-dropped issues. Ideally I'd like it to be TCP based -- I have one process that can connect to a TCP socket for its data rather than read from the port, and I can use socat to create PTYs for the other processes that expect a serial port provided the data comes in in the right order. Yes, I know about gpsd, and one of the processes that needs to read the serial data is gpsd, but I have some processes that need to read the raw data provided by the GPS and not gpsd's output. Thanx, If you know the number of processes I'd be tempted to just tee it off into some fifo type buffers, one per process. the fifo would I hope look enough like a serial port to your programs that it might be able to handle it. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
[SLUG] one serial port multiple readers
Hi, Does anyone have a solution to this problem? I have a serial port (connected to a GPS at 4800 baud). I have multiple processes that need to read from that serial port. I need all of the processes to read the same data, essentially creating a one way chat from the serial port to all processes listening in. I've tried using socat but if I create a socket connection, using, e.g. socat TCP4-LISTEN:2,reuseaddr,fork /dev/ttyUSB0,b4800,raw,echo=0 ... then have multiple connections in to TCP socket 2, then each socket connection gets part of the data stream from the serial port. I've tried setting up a multicast, but because multicast is UDP based I'm seeing occasional packet-out-of-order and packet-dropped issues. Ideally I'd like it to be TCP based -- I have one process that can connect to a TCP socket for its data rather than read from the port, and I can use socat to create PTYs for the other processes that expect a serial port provided the data comes in in the right order. Yes, I know about gpsd, and one of the processes that needs to read the serial data is gpsd, but I have some processes that need to read the raw data provided by the GPS and not gpsd's output. Thanx, -- Del Babel Com Australia http://www.babel.com.au/ ph: 02 9966 9476 fax: 02 9906 2864 -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html