LinuxQuestions.org
Help answer threads with 0 replies.
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 11-21-2001, 02:39 AM   #1
Sree
LQ Newbie
 
Registered: Nov 2001
Location: India
Distribution: Redhat 7.1,Redhat 6.1,Redhat 6.2
Posts: 1

Rep: Reputation: 0
Question Serial Programming on an i486


hi all,

This is my first posting.
Here I have a problem related with linux serial programming
in C.Hope u can help me in this.

I have a C program that communicates with a remote terminal
unit via serial port.The program uses termios structure to initialise
the port.
The program works as expected in kernel
version 2.4.2-2 on an i686 macine.

This same program when tested on a 586 (Kernel 2.2.14-12 on an i586)
machine fails to read the port properly.
Writing to the port was working properly.
The setserial and stty commands produced the same result on both machines.

Later i found that minicom(communicating with hyperterminal in windows) also
showed the same problem while reading the port on the 486 macine.
Writing to the port was working properly.
Communication was proper when hyperterminal was used on
both sides.




Here is the o/p of the setserial command.

/dev/ttyS0, Line 0, UART: 16550A, Port: 0x03f8, IRQ: 4
Baud_base: 115200, close_delay: 50, divisor: 0
closing_wait: 3000
Flags: spd_normal skip_test

and here is the settings on the port using stty command while my program is
running.



speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc -ixany -imaxbel
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0
ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke


If anybody knows what is creating the problem...
please do help..

regards,
sree
 
Old 12-10-2001, 06:13 AM   #2
Lazarus
Member
 
Registered: Dec 2001
Location: Kent in UK
Distribution: Fedora 2
Posts: 170

Rep: Reputation: 30
If this is any help wrote a process that communicates with a device I have that receives teletext data. I use /dev/ttyS0 for this.

I use this procedure to set up the port.

ttext_setraw()
{
if(ttext_debug) printf("\nEntering setraw\n");
if(ioctl(fp,TCGETA,&tbuf) == -1)
{
printf("\n\nSetraw IOCTL error fp = %d\n\n",fp);
close(fp);
delay(2);
longjmp(serial_fail,0);
}
tbuf.c_iflag &=~(INLCR | ICRNL | IUCLC | ISTRIP | IXON | BRKINT);
tbuf.c_oflag &=~OPOST;
tbuf.c_lflag &=~(ICANON | ISIG | ECHO);
tbuf.c_cflag &= (B9600 | CS8 | CLOCAL | CREAD );
tbuf.c_cc[4]=1; /* min */
tbuf.c_cc[5]=2; /* time was 2 */
if(ioctl(fp,TCSETAF,&tbuf) == -1)
{
fprintf(outptr,"\nsetraw failed to set IOCTL attributes\n");
fflush(outptr);
return(-1);
}
if(ttext_debug) printf("\nLeaving setraw\n");
return(0);
}

I read the serial port thus read(fp,&ic,1)
and write to it write(fp,&ic,1)

I open the port thus

fp=open("/dev/ttyS0",O_RDWR | O_NONBLOCK );

I hope this points you in the right direction.
 
Old 12-10-2001, 01:37 PM   #3
pinoy
LQ Newbie
 
Registered: Sep 2001
Posts: 21

Rep: Reputation: 15
Are you connecting two computers directly? Make sure you have the proper cross-over cables.
 
Old 07-03-2003, 06:09 AM   #4
narinder
LQ Newbie
 
Registered: Jul 2003
Posts: 1

Rep: Reputation: 0
Wink May be a bit useful

hi ,
I am also trying to communicater over serial port and i am able to do it sucessfully but sometimes i am getting overrun error( once in 15-20 transactions). I am using inb(port) and outb(port) to read and write a byte on the serial port. If this information is anyhow helpful to you its ok and if you knw how to get rid of this overrun error please let me knw.
and one personal question " are you sreejith ?" as ur nick name being SREE
 
Old 07-03-2003, 07:35 AM   #5
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Rep: Reputation: 31
I remember there was a howto named "serial port howto mini" some where available on the internet.
 
Old 07-03-2003, 07:36 AM   #6
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Rep: Reputation: 31
Yeah, find on http://www.tldp.org/HOWTO/HOWTO-INDEX/howtos.html
 
  


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 programming!!! novice_din Programming 4 02-03-2005 08:50 PM
Programming the Serial Port karans Linux - Networking 2 11-03-2003 01:54 AM
Serial Programming ganninu Programming 0 08-27-2003 05:37 AM
serial programming sabeel_ansari Programming 0 11-15-2001 12:14 PM
serial programming zkumar Programming 1 08-07-2001 05:37 AM

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

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