Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-19-2011, 02:10 AM   #1
LQ Newbie
Registered: Aug 2011
Posts: 1

Rep: Reputation: Disabled
problem in viewing data on serial port


I wrote a simple code in C that intends to write data on the serial port (/dev/ttyGS0) and verify if that data is being written (using windows - COM4). The code intends to write the word "DATA " on the serial port once every second, but on the console terminal on windows (command prompt) I see the word data being printed 7x every seven seconds. Below is the code:

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>

int main(int argc, char *argv[])
int fd;
struct termios options;

fd = open ("/dev/ttyGS0", O_RDWR | O_NOCTTY | O_NDELAY);

memset(&options, 0x00, sizeof(options));

options.c_cflag = (B115200 | CS8 | CLOCAL | CREAD);

options.c_lflag = 0;
options.c_iflag = 0;
options.c_oflag = 0;

options.c_cc[VTIME] = 0;
options.c_cc[VMIN] = 1;

tcsetattr(fd, TCSANOW, &options);

for (;
tcflush(fd, TCIOFLUSH);
write (fd, "data ", 5);

return 0;

Do you have any ideas why this happens? thanks.

Old 08-20-2011, 10:46 AM   #2
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Well, you didn't test the return value of your call to open(), so it is hard to know for sure. I'd guess that your file descriptor, fd, is pointing at either the stdout or stderr stream.
--- rod.


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
the get data from serial port function read() blocks when data not available DEF. Programming 3 11-17-2014 08:11 AM
Serial port data read time interval problem... rados Programming 11 11-01-2010 02:03 AM
[SOLVED] Serial port : Read data problem, not reading complete data anujmehta Linux - Networking 5 09-06-2010 07:10 AM
help reading data from a serial port skydemon Linux - General 1 08-10-2006 09:48 AM
accessing data from serial port PrerakParikh Linux - Hardware 2 08-24-2004 11:17 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:14 AM.

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