Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-29-2004, 02:34 PM   #1
LQ Newbie
Registered: Sep 2004
Posts: 2

Rep: Reputation: 0
C++ serial port program problem

I have borrowed a simple program that is supposed to read from a file and
output to the screen. Simply pass the file to it at the command line. I am
pointing it at a serial port, instead of a regular file and I get different results when I run it from the old C++ compiler instead
of the new. Any help is VERY VERY appreciated. I am not sure if I am
simply not using the new standard appropriately, or if my system is
configured incorrectly, or the compiler.

Here are the specifics:
System: Suse Linux 9.0 (i586) Kernel 2.4.21-243-smp4G
Old compiler: g++ using gcc version 2.95.3 20010315 (release)
New compiler: g++ using gcc version 3.3.3 (SuSE Linux)
to run command line: a.out /dev/ttyS0

What happens:
When I compile under the old compiler it works fine, I send info down the
port, it reads it and displays it on my screen.
When I compile under the new compiler, it simply blocks, no info is read,
the program never proceeds past the first get().

Here is the code:

#include <fstream>
#include <iostream>
using namespace std;

int main (int argc, char* argv[])
ifstream file;

for (int i=1; i<argc; ++i) {[i]);

char c;
while (file.get(c)) {

Old 09-30-2004, 01:22 AM   #2
Registered: May 2004
Posts: 552

Rep: Reputation: 31
Can't say exactly what the diff is between the two compilers, though I'm not surprised it happens. You need to do more than just open the tty file and read from it, there is a lot of other things to configure. You'll need to understand your hardware, and if it uses flow control and what kind so you can set your rts and dtr as required, also baud rate, etc...
I've written a C serial library, what's the best way to get it to you. Its too large to post here. You can email me if you want it.
Old 09-30-2004, 06:56 AM   #3
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
You may also want to read this document:
Old 10-01-2004, 11:46 AM   #4
LQ Newbie
Registered: Sep 2004
Posts: 2

Original Poster
Rep: Reputation: 0
Ok, thanks....

I must have just gotten lucky with the old compiler. I have done serial communications using C before, and was impressed with how easy it was to use C++, I was just fooling myself...;-) Thanks again.


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
serial port program for Linksys WAP54G segfaulting (linux) hedpe Programming 3 06-06-2005 03:58 PM
Serial port problem floydes Programming 1 10-14-2004 12:50 PM
serial port problem... linux4john Linux - Software 1 10-30-2003 11:02 PM
Controlling serial port RTS pin from 'C' program dcarter Slackware 1 09-26-2003 08:01 PM
Serial port problem ruchika Linux - Networking 0 08-15-2003 05:18 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:24 PM.

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