LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-03-2007, 08:49 AM   #1
atish
LQ Newbie
 
Registered: Jul 2007
Posts: 1

Rep: Reputation: 0
problems accesing serial port


hii..everybody...i'm tryin to acess serial port.I'm using POSIX based commands...i'm able to send some data..but not able to read anything....read function returns -1...which i thnk says dat..read is not workin....plzz help me out...i've pasted my code here

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

int main()
{
int s;
char port_name[] = "/dev/ttyS0";
char buff[14];
struct termios at;
int x=0,i,y;
char *input;

//----------------------------------------------------------
s = open(port_name, O_RDWR | O_NOCTTY | O_NDELAY);
//----------------------------------------------------------
//struct termios at

tcgetattr(s,&at);
cfsetispeed(&at,B9600);
cfsetospeed(&at,B9600);
at.c_cflag |=(CLOCAL|CREAD);
at.c_cflag &=~(IXON|IXOFF|IXANY);
at.c_cflag &= ~CRTSCTS;
//
tcsetattr(s,TCSANOW,&at);
at.c_cflag &=~(ICANON|ECHO|ECHOE|ISIG);
at.c_cflag &=~PARENB;
at.c_cflag &=~CSTOPB;
at.c_cflag &=~CSIZE;
at.c_cflag |= CS8;

x=write(s,"FFFFFFFFFFFFFF",14);
printf("%d\n",x);

fcntl(s,F_SETFL,FNDELAY);
y=read(s,buff,14);
printf("%d\n",y);
printf("%s\n",buff);

printf("failed!!!");
tcflush(s, TCOFLUSH);
tcflush(s, TCIFLUSH);
close(s);
s = -1;

return 0;
}

pllzz help me out...........!!!!!!!!!1
 
Old 07-03-2007, 10:16 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
When the read function returns -1, the first thing you need to do is look at errno. At the command line, do this:

Code:
man errno
Hope this helps.
 
  


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
Serial port problems (Fedore core 1) skguha Linux - Hardware 1 11-29-2005 10:43 AM
Problems Accesing Content on Apache brokenflea Slackware 2 08-05-2004 01:59 AM
Serious modem & serial port problems Dummy-in-Linux Linux - Hardware 1 06-19-2004 05:06 PM
Serial port or Modem problems ugol Linux - Hardware 2 07-26-2003 02:37 PM
Serial port problems with Red Hat 7.2 puneet7 Linux - General 0 04-09-2002 05:02 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:41 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