LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-27-2017, 09:52 PM   #1
hardikgohil1988
Member
 
Registered: Sep 2014
Posts: 63

Rep: Reputation: Disabled
access serial port from applications


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 ?
 
Old 05-29-2017, 07:00 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,457

Rep: Reputation: 2778Reputation: 2778Reputation: 2778Reputation: 2778Reputation: 2778Reputation: 2778Reputation: 2778Reputation: 2778Reputation: 2778Reputation: 2778Reputation: 2778
would be nice to see some sample/example and also would be nice to know the programming language (at least)
 
Old 05-29-2017, 06:53 PM   #3
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,768
Blog Entries: 27

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Moderator response

Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 05-29-2017, 07:49 PM   #4
hardikgohil1988
Member
 
Registered: Sep 2014
Posts: 63

Original Poster
Rep: Reputation: Disabled
I am doing in C.

using open() API to open the port.
 
Old 05-29-2017, 09:14 PM   #5
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 842

Rep: Reputation: 201Reputation: 201Reputation: 201
If the two user spaces are on the same machine, the cable specs (RS 485 etc) are not important.

Easy way:You must handle it in the application by prefixing it with "01", "02" .. etc to each record before appending it to the data stream.

Same applies if the user spaces are on different machines.

Not so easy
Since RS 485 is multi drop it must be providing a way (in the header) to identify each port. An option is for you to look at specialized sites that could have specific APIs or tutorials for it.

OK

Last edited by AnanthaP; 05-29-2017 at 09:24 PM.
 
Old 05-30-2017, 07:21 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,455
Blog Entries: 12

Rep: Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903Reputation: 1903
Quote:
Originally Posted by hardikgohil1988 View Post
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Access Denied when trying access a serial port RogerInHawaii Debian 1 08-20-2013 04:13 PM
Access serial port over Bluetooth Jaykob Linux - Software 2 02-17-2009 09:08 AM
How to access the second serial port cheema Programming 2 07-29-2004 01:26 PM
Serial Port Access stweaver Linux - Newbie 3 09-14-2003 01:21 AM
Serial Port Access gblydenburgh Linux - General 3 08-21-2001 07:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration