The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Serial port programming raj8109 High Level Programming 2 08-19-2008 12:20 PM
Serial port redirector steel98 UNIX for Dummies Questions & Answers 0 07-20-2008 03:30 PM
Communicating with Serial Port netsavant UNIX for Advanced & Expert Users 4 03-15-2008 05:19 PM
urgent......Serial port arunchaudhary19 Linux 16 11-02-2007 06:42 AM
serial port reading viswanath High Level Programming 0 10-21-2001 04:05 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-15-2008
jvrlic jvrlic is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 3
Programming serial port

Hello!
Can someone advice me which method I will use if I want to communicate with device via RS232 serial port with this requirements:
1. Serial port is opened in non-canonical mode.
2. All the time I need to check is there something to read.
3. If I have to write something I need to write it immediately.
4. Overhead of CPU have to be minimum.

Thanks!

Jvrlic
  #2 (permalink)  
Old 11-15-2008
jvrlic jvrlic is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 3
I forget to tell I programming with C on debian with posix standard.
  #3 (permalink)  
Old 11-15-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
You need to do soime reading. This is the best guide out there for POSIX serial port programming:

Serial Programming Guide for POSIX Operating Systems - Michael R Sweet
  #4 (permalink)  
Old 12-17-2008
WebKruncher WebKruncher is offline VIP Member  
VIP Member
  
 

Join Date: Dec 2007
Location: Simi Valley, CA
Posts: 29
C++

The Michael R Sweet reference looks really good - I'll keep this handy. But, it shows only the C interface. The samples demonstrate the critical components, and understanding it is a necessary first step before building your object oriented design.

If your target supports standard exception handling, you can take advantage of C++ streams. Here is an example http://www.webkruncher.com/speedstreams.h that demonstrates using C++ iostreams for a local file. I've used the same method to interface with serial ports and sockets. It can be adapted to virtually any IO. Even if your IO needs to be fully optimized, you can still take advantage of the OO structure.

The goal is really to have one, straight forward C++ header file that defines and fully implements everything needed to communicate with your target port. Then, your protocol manager sees your target device as if it were a simple file. So, when you initialize the system that interfaces with your target device, the source code could look something like this....

SerialStream io("COM1");
while(!io.eof())
{
string line;
getline(io,line);
}

io<<"hello"<<endl;

Then you build an object to manage the negotiations required by your protocol and put it to use.



Hope that helps.
-Jmt
  #5 (permalink)  
Old 11-15-2008
kpedersen kpedersen is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 12
Hello,

I worked on a simple oil rig safety device using an RS-232 a few weeks back. I used code based on this class (CSerial). It seems pretty good...

Information
------------
http://www.codeguru.com/cpp/i-n/netw...icle.php/c2503

Download
---------
http://www.codeguru.com/code/legacy/...serial_src.zip

Hope this helps!

Karsten
  #6 (permalink)  
Old 11-16-2008
jvrlic jvrlic is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 3
jim: I asked on this forum: High Level Programming!

kpedersen: Thansk, but I work with C not C++.
  #7 (permalink)  
Old 11-17-2008
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,929
Quote:
Originally Posted by jvrlic View Post
jim: I asked on this forum: High Level Programming!

kpedersen: Thansk, but I work with C not C++.
There's little difference when the relevant system calls will work in both. Just tear apart classes and make members functions instead.
Closed Thread

Bookmarks

Tags
operating systems

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0