Quote:
Originally Posted by hardikgohil1988
Hello,
I want to send data over RS485 port from two different user space application.
since we cannot open port 2 times how can i share file descriptor b/w 2 applications so that i can write data over RS485 port.
can any body suggest how to do this ?
|
There's a right way and a wrong way to do things. I "believe" you can open() the resource and then double use the descriptor, however you'd have to share that descriptor between the two applications where the second one knows what descriptor ID was used by the first application. HOWEVER, this is the wrong way to do things, it can leave open corruption by two applications trying to write data at the same time.
The correct way to do this is to have a third application which is the interface to the serial port. Have that open, write, and read from the port, and have it dispatch received data to the other two applications, or accept API calls from those other two applications to arbitrate properly the data to and from that port.
I've tried the first option in the past, and it is usually due to laziness where you do not wish to type in a lot of extra stuff, spend time creating an architecture to manage things properly. Well, some time down the pike you find that you have bugs, things you can't explain. Data is getting lost, overwritten, or corrupted and you stand there and vociferously tell everyone else that it's not your code. Until you finally spend some long time finally doing what you were supposed to do the first time. And then it all works.