LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   clone/emulate serial port (http://www.linuxquestions.org/questions/linux-software-2/clone-emulate-serial-port-823036/)

maveq 07-30-2010 08:46 AM

clone/emulate serial port
 
Hello

I have a usb gps receiver. The navigation program I use, uses the serial port directly.
Now I would like to use another program e.g. gpsd to use the same data that comes from the serial port, simultaneously with my navigation program. But only one program at a time can use the port.

So I am looking for a way to clone the serial port. Or any other way I can use two (or more) programs reading from the same serial port.
I can let gpsd use the gps serial port and use gpspipe to connect to gpsd and that way I can get the data I need (as standard output) , but I still need a way to make my navigation program use that data.
I won't necessarily have a hardware serial port (rs-232) on the machine.


Benjamin

MS3FGX 07-30-2010 10:36 AM

The navagation software doesn't support anything but direct serial connection for the GPS?

maveq 07-30-2010 10:44 AM

No, I have to define a com (serial) port in the navigation software (which I am running with wine).

tredegar 07-30-2010 11:09 AM

From man gpspipe
Code:

-s    option causes the collected data to be written to the specified
      serial device with setttings 4800 8N1. Thus gpspipe can be used with -s
      and -r options to emulate a serial port hardwired to a GPS that gpsd is
      managing.

And you are using wine (which I know next to nothing about), but maybe try something like this

Code:

gpspipe -r -s ~/.wine/dosdevices/com1
Then see if your windows program can use com1 as a gps receiver

maveq 07-30-2010 11:44 AM

I have tried that.
Code:

gpspipe -r -s /dev/ttyS0
and I linked /home/ravenous/.wine/dosdevices/com2 to /dev/ttyS0
but 'cat /dev/ttyS0' or 'gpscat /dev/ttyS0' gave nothing and my navigation software couldn't find it either.

On this machine, I do have one real serial port /dev/ttyS0. Using anything else gives the following error.
Code:

ravenous@square:~/gpsd-2.92$ ./gpspipe -r -s /dev/ttyS1
gpspipe: error reading serial port settings

I suppose this is because ttyS0 is a real port. I probably would be able to read from it, if I connected it to another computer and read that other computer's serial port.
That is why I need to emulate a serial port, I think. Or if there is a way to loopback ttyS0, so that you can read everything you write to it, but I haven't found anything in the setserial manual.

tredegar 07-30-2010 01:40 PM

Quote:

I have tried that.
OK, so what happened?
Quote:

and I linked /home/ravenous/.wine/dosdevices/com2 to /dev/ttyS0
I don't think that is going to help, just telling gpspipe to send the data to /home/ravenous/.wine/dosdevices/com2 should be enough. Better to remove that link before you find it complicating things.
Quote:

gpspipe: error reading serial port settings
I see you are running gpspipe as yourself. That's OK, but what are the permissions on /dev/ttyS1 (where you have a node, but no real device) and what groups are you in?
Code:

ls -l /dev/ttyS1
groups

It would also be useful to know what distro you are running

On another track:
Maybe, as you are using wine, life would be easier if you were not running gpsd at all.

What happens if you kill gpsd and then symlink /dev/ttyUSB0 (where the GPS device is) to /home/ravenous/.wine/dosdevices/com2

Wine / windows program should say "com2 is a COM port, with a GPS receiver spitting out NMEA data, I'll use it".

maveq 07-30-2010 02:29 PM

Quote:


I don't think that is going to help, just telling gpspipe to send the data to /home/ravenous/.wine/dosdevices/com2 should be enough. Better to remove that link before you find it complicating things.
~/.wine/dosdevices/com2 is just a symlink to /dev/ttyS0 or /dev/ttyUSB0
It is the way wine accesses serial devices. If I should remove the link, what kind of file should ~/.wine/dosdevices/com2 be? It is not automatically created by wine.
This is how my navigation software can use /dev/ttyUSB0, which is my gps receiver and this way the navigation software can use the gps receiver just fine.
But the problem is that I want to use my navigation software on one hand, and use gpsd on the other, running side by side; both using the same gps receiver.

Quote:

I see you are running gpspipe as yourself. That's OK, but what are the permissions on /dev/ttyS1 (where you have a node, but no real device) and what groups are you in?
It would also be useful to know what distro you are running
/dev/ttyS1 is rw for dialout group, which ravenous belongs to.
I tried running gpspipe as root and using sudo, but I get the same message.
I am using Kubuntu 10.04

I have read several things about socat and remserial. I just came up with an idea. Creating a stream with socat between my gps receiver and a network port. Then creating two other streams that connect between that network port and two PTY's, which according to the manual, can be accessed as a serial line. But I don't know socat, so maybe someone has some suggestions about this?

maveq 07-31-2010 05:00 AM

I have found a way to do what I want.
I let gpsd use the gps receiver and then use the following
Code:

gpspipe -r | socat - PTY,link=/home/ravenous/pty,raw
and create a link to /home/ravenous/pty in ~/.wine/dosdevices
Now I can use gpsd and my navigation software simultaneously.
All in all, an easy solution.

Thank you.

tredegar 07-31-2010 05:14 AM

Brilliant!

I was about to refer you to this page where they seem to have solved it with a php script and a fifo pipe, when you posted the above.
The script I linked probably won't work with the latest version of gpsd anyway.

But your fix is more elegant, easier and probably the "right" way to do it.
man socat was giving me a headache!

Thanks for posting the solution :)

maveq 07-31-2010 05:41 AM

Quote:

Originally Posted by tredegar (Post 4050779)
man socat was giving me a headache!

tell me about it :)


All times are GMT -5. The time now is 08:50 AM.