LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

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


Hi,

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);
sleep(1);
write (fd, "data ", 5);

}
close(fd);
return 0;
}


Do you have any ideas why this happens? thanks.

-uchiha
 
Old 08-20-2011, 09:46 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
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.
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:12 AM.

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