LinuxQuestions.org
Help answer threads with 0 replies.
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 04-22-2004, 08:13 AM   #1
newtolinux123
LQ Newbie
 
Registered: Apr 2004
Posts: 1

Rep: Reputation: 0
Data acquisition from a device through serial port in linux


I have to read and write data frames from & to an electronic device.I am using C for establishing serial port communication with the device.
I have successfully implemented writing to the device.I sent data using this
code patch


fd = open(COMPORT,O_RDWR | O_NOCTTY | O_NDELAY);
fcntl(fd,F_SETFL,0);
tcgetattr(fd,&options);
cfsetospeed(&option,B9600);
cfsetispeed(&option,B9600);
options.c_cflag |= ( CLOCAL | CREAD );
options.c_cflag &= PARENB;
options.c_cflag &= ~PARODD;
options.c_cflag &= ~CSTOP;
options.c_cflag &= ~CSIZE;
options.c_cflag &= ~CRTSCTS;
options.c_cflag |= CS8;
options.c_oflag &= ~OPOST;
options.c_cc[VMIN]=1;
options.c_cc[VTIME]=0;
tcsetattr(fd,TCSANOW,&options);
tcflush(fd,TCIOFLUSH);
for(i=0;i<=7;i++)
n = write(fd,&buff1[i],2);
/*
for(i=0;i<=7;i++)
n = read(fd,&buff3[i],1);
*/
tcdrain(fd);
close(fd);
return 0;
}
when i remove comments and execute read portion of the patch it doesnot read the data comming from the device
Now i am trying to read from the serial port but no success please help me
Esp............... newbie42
 
Old 04-22-2004, 08:27 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,681

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
I suspect you are attempting to read the data before it is ready to be received. You need to wait until there are characters in the UART receive buffer first. This program might provide some hints.

http://www.comptechdoc.org/os/linux/...pgcserial.html

BTW the program will execute way faster then the UART transmits.
 
  


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
reading data from a serial port mchitrakar Linux - Networking 3 12-04-2004 01:24 PM
Data Acquisition agarbino Linux - Hardware 0 12-02-2004 12:20 AM
accessing data from serial port PrerakParikh Linux - Hardware 2 08-24-2004 10:17 PM
exchanging data between 2 computer using serial port blackzone Linux - General 1 07-24-2004 02:54 AM
trouble receiving serial port data mtPete Linux - General 1 08-20-2003 04:27 PM

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

All times are GMT -5. The time now is 08:52 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
Open Source Consulting | Domain Registration