LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-01-2007, 03:45 AM   #1
madhivadhana
LQ Newbie
 
Registered: Oct 2007
Posts: 2

Rep: Reputation: 0
Question Rs 232 pgm - Please help


Hi,
I am a newbie. I have to do Linux rs232 programming to connect a device.
the device settings,
9600, 7 bit, 1 start bit, 1 stop bit, Even parity.

I have written the below code. But there is no response.
Please, .. someone help me. I am very much struck in this.
*************************************************
struct termios newtio;
struct timeval tv;
int retval;

char buf[255];



FD_ZERO(&read_set);

tv.tv_sec = 5;
tv.tv_usec = 0;
fd=open("/dev/ttyAM1",O_RDWR | O_NOCTTY |O_NDELAY);
if(fd < 0)
{
fprintf(stderr, "Unable to open /dev/ttyAM1");

exit(1);
}
fcntl(fd,F_SETFL,FNDELAY);




cfsetispeed(&newtio,B9600);
cfsetospeed(&newtio,B9600);
newtio.c_cflag |= CREAD;

newtio.c_cflag |= CLOCAL;
newtio.c_cflag |= PARENB;

newtio.c_cflag &= ~PARODD;
newtio.c_cflag |= ~CSTOPB;
newtio.c_cflag &= ~CSIZE;
newtio.c_cflag |= CS7;

newtio.c_cflag &= ~CRTSCTS;
newtio.c_iflag &= ~(IXON | IXOFF | IXANY | ICRNL | IGNCR);
newtio.c_lflag &= ~(ICANON | ECHO | ISIG );
newtio.c_oflag &= ~(OPOST | ONLCR | OCRNL | ONLRET);



tcsetattr(fd,TCSANOW,&newtio);


FD_SET(fd,&read_set);
write(fd,&cmd,sizeof(cmd));


retval = select(fd+1,&read_set,NULL,NULL,&tv);
if(retval)
{
printf("Data is available");
res=read(fd,buf,255);
printf("\n");
printf("%d\n",res);
for(i=0;i<res;i++)
{
printf("%x",buf[i]);
}
}
else
printf("No data within five seconds");


printf("retval=%d",retval);
close(fd);
**********************************************************
Regards,
Madhi.
 
Old 11-02-2007, 01:18 AM   #2
ehawk
Senior Member
 
Registered: Jul 2003
Posts: 1,257

Rep: Reputation: 48
possibly useful links

http://www.agsrhichome.bnl.gov/Contr...Ado_Digi_.html

http://lpccomp.bc.ca/remserial/

The following link looks quite promising:

http://www.egr.msu.edu/classes/ece48...ote_wa-jiw.pdf

This product includes a free trial period:

http://www.dcbnet.com/notes/0006etherpathredirect.html

Also try posting to justlinux.com if you haven't already. They seem quite well informed.
 
  


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
remote pgm execution in C cynthia_thomas Programming 7 05-21-2006 09:16 PM
What is pgm.h and how do I install? WESS126 Linux - Software 1 05-07-2006 09:16 AM
can't compile C pgm in SUSE 9.1 gjo Programming 10 10-25-2004 11:00 AM
Rs-232 yogotie Linux - Hardware 2 08-03-2003 01:02 PM
problems compiling qt-pgm engman Programming 0 05-31-2001 07:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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