By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,382 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,382 IT Pros & Developers. It's quick & easy.

Reading from serial to an array

P: n/a
Hello all..

I am quite new to C programming, but am having pretty good success so
far. I've written a short program to read from the serial port and
print the data to the screen, then quit. I'm starting simple!

My problem is that I only get the first line of data, up to the first
<cr>, then it quits. I'm sure this syntax isn't the best, so any
suggestions would be helpful. Here's how I'm doing it:
-------------------relavent code--------------

char sResult[4096];
fcntl(fd, F_SETFL, O_NDELAY);
read(fd, sResult, 200);

----------------------------------------------------

The messages that I read won't always be the same length, but should
always be less than 200. The output from the device looks like this:

P +
BNK +---------
CHN [ 1]
FRQ [ 856.3375]
CTC [ ]
With each line ending in a <cr>. When I compile and run all I get is:

P +

and nothing else. A dumb mistake, I'm sure. Any pointers/help
would be greatly appreciated. Thanks!
Dec 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Shawn wrote:
Hello all..

I am quite new to C programming, Off topic. THis group is for C++ programming.


-------------------relavent code--------------

char sResult[4096];
fcntl(fd, F_SETFL, O_NDELAY);
read(fd, sResult, 200);
Off topic. fcntl() and read() are *nix-isms. Please consult
comp.unix.programmer.

----------------------------------------------------

The messages that I read won't always be the same length, but should
always be less than 200. The output from the device looks like this:

P +
BNK +---------
CHN [ 1]
FRQ [ 856.3375]
CTC [ ]
With each line ending in a <cr>. When I compile and run all I get is:

P +


Even if this was on topic, which it isn't, there is insufficient
information to answer your question. You have an error on line 42.

Dec 19 '05 #2

P: n/a
Shawn wrote:
I am quite new to C programming,
....which is off-topic in comp.lang.c++, BTW...
but am having pretty good success so
far. I've written a short program to read from the serial port and
print the data to the screen, then quit. I'm starting simple!
Wow! Considering that C++ (and C as well) has no means to do what you
claim you have done, I am fairly impressed.
My problem is that I only get the first line of data, [...]


C++ FAQ 5.8.

V
Dec 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.