0

I know how to open a serial port using 'open' function:

open("/dev/portname", flags)

But I want two programs to open this port but with reversed read/write lines. For example when program 2 writes something to the port, program 1 can read it.

kptlronyttcna
  • 1,461
  • 1
  • 16
  • 22
  • And how serial port is related to IPC between some programs? – 0andriy Jan 22 '17 at 11:55
  • But that's kind of how serial ports *works*, one program writes to its end of the serial connection, and another program reads from it. Can you please elaborate on your setup, and what you want to accomplish. – Some programmer dude Jan 22 '17 at 11:58
  • *'I want two programs to open this port"* -- Two programs on the same computer? Seems like you're asking an XY question. – sawdust Jan 23 '17 at 00:47

2 Answers2

1

If you're using a Unix-like operating system, and if you don't need full serial port semantics, named pipes can be quite useful for doing this sort of thing.

If you need more control, you could perhaps use a pair of pseudoterminals, with a third program running in the background shuttling characters between the master ends.

And do see the related question "Virtual Serial Port for Linux" that the StackOverflow machinery already found for you.

Community
  • 1
  • 1
Steve Summit
  • 45,437
  • 7
  • 70
  • 103
0

You cannot typically do that in software.

Such things are normally done by hardware, and that is what cross-over cables and "null-modem" cables are good for.

tofro
  • 5,640
  • 14
  • 31