LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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, 02: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, 10:46 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
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


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


All times are GMT -5. The time now is 08:28 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration