Reading from serial to an array

S

Shawn

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!
 
R

red floyd

Shawn said:
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.
 
V

Victor Bazarov

Shawn said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,068
Latest member
MakersCBDIngredients

Latest Threads

Top