473,508 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading from serial to an array

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
2 1605
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9061
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the...
16
7500
by: halukg | last post by:
I am trying to send a 6 byte char array from the serial port in new C# 2005 Express: com.Write(new string(new char { (char)34, (char)14, (char)192, (char)51, (char)0, (char)0 }, 0, 6)); I am...
5
11089
by: Mo | last post by:
I am trying to set a text box value when data is received from the com port (barcode reader). I am getting the following error when I try to set the text box TXNumber after data is received ...
4
1962
by: sherifffruitfly | last post by:
Hi, I have an xml file with structured like this: <?xml version="1.0" encoding="UTF-8"?> <Soldiers> <Soldier name="Billy Smith" rank="Private" serial="34" /> (a bunch more soldiers)
8
16324
by: Vivek Menon | last post by:
Hi, I am using a C program to write/read from a serial port. The writing part is working perfectly fine. However, I am not able to read the values correctly and display them. To debug this issue I...
0
1986
by: RG | last post by:
I am trying to read from my serial port a 24 bit binary number. I was able to read this number as a HEX but I was getting errors as at times using the vBCrLf indicator. I also can read it as an...
6
11877
by: John Wright | last post by:
I am trying to read the data from a device on a serial port. I connect just fine and can receive data fine in text mode but not in binary mode. In text mode the data from the device comes in...
9
1609
by: cmdolcet69 | last post by:
The sub below reads the value of position from my serial write command. However i need to read only the (3) and (4) index of the byte array and then need to convert it into a integer. When i get to...
9
14350
by: Hal Vaughan | last post by:
I've done a fair amount of Googling for information on reading the serial port in C++ (and in Linux). Unfortunately, out of every 4 hits, 1 seems to be an unanswered question, 1 is someone saying,...
0
7114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7034
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.