![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
There's little difference when the relevant system calls will work in both. Just tear apart classes and make members functions instead.
|
![]() |
| Bookmarks |
| Tags |
| operating systems |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|