View topic - why I can't receive char from serial port?

why I can't receive char from serial port?

anything that doesn't fit to other groups.

why I can't receive char from serial port?

Postby kelles007 » Fri Aug 10, 2012 6:45 am

1.I start serial port service by "devc-8250 &"
2.setup parameter for port
if ( ( fd = open ( "/dev/ser1", O_RDWR) ) != -1 )
{
struct termios termios_p;
tcgetattr( fd, &termios_p );
cfsetispeed( &termios_p, 4800);
cfsetospeed( &termios_p, 4800);
tcsetattr( fd, TCSADRAIN, &termios_p );
flag |= CS8 | CREAD ;
flag &= ~CSTOPB;
flag &= ~PARENB;
termios_p.c_cflag = flag;
tcsetattr( fd, TCSADRAIN, &termios_p );
}
3.read(fd,buffer,size);
but I receive nothing,"read" is blocked,in fact,even if I use "cat /dev/ser",I can receive nothing,why?
kelles007
New Member
 
Posts: 1
Joined: Fri Aug 10, 2012 6:43 am

Re: why I can't receive char from serial port?

Postby maschoen » Fri Aug 10, 2012 8:18 pm

kelles007 wrote:1.I start serial port service by "devc-8250 &"
2.setup parameter for port
if ( ( fd = open ( "/dev/ser1", O_RDWR) ) != -1 )
{
struct termios termios_p;
tcgetattr( fd, &termios_p );
cfsetispeed( &termios_p, 4800);
cfsetospeed( &termios_p, 4800);
tcsetattr( fd, TCSADRAIN, &termios_p );
flag |= CS8 | CREAD ;
flag &= ~CSTOPB;
flag &= ~PARENB;
termios_p.c_cflag = flag;
tcsetattr( fd, TCSADRAIN, &termios_p );
}
3.read(fd,buffer,size);
but I receive nothing,"read" is blocked,in fact,even if I use "cat /dev/ser",I can receive nothing,why?


I didn't read your code very carefully, but it looks ok. I would set the port using stty and eliminate everything between fopen and read and try again. Why are you so sure that it should be reading something? Do you have a line monitor on the input? read blocking when nothing is coming in would be normal. Also, if the tty parameters are off, you might also see nothing.
maschoen
QNX Master
 
Posts: 2715
Joined: Wed Jun 25, 2003 5:18 pm

Re: why I can't receive char from serial port?

Postby denkelly » Sat Aug 11, 2012 1:16 pm

I can see two possiblities for why you may not be receiving data. Both have to do with control signal input to the port (especially if using a 3-wire cable).

...
termios_p.c_cflag &= ~(IHFLOW|OHFLOW)"; // add this to cancel input (and output) hw flow control
termios_p.c_cflag |= CLOCAL; // add this to ignore input modem control signals
tcsetattr( fd, TCSADRAIN, &termios_p ); // check for -1 return here - make sure it succeeds


Note IHFLOW and OHFLOW are QNX-only flags.

Of course the other reason may be that pins 2-3 are reversed! :)
denkelly
Senior Member
 
Posts: 163
Joined: Sat Aug 02, 2008 3:27 pm

Re: why I can't receive char from serial port?

Postby johnbevy » Wed Oct 16, 2019 9:27 am

Hi Kelles,

I am also facing the issue as you mentioned. Not able to receive characters via the serial port. But I confirmed that I am able to send data out using echo and write () system call.

Kindly help me if you have any ideas for this issue.
johnbevy
Active Member
 
Posts: 23
Joined: Tue Oct 15, 2019 8:41 am


Return to General Programming

Who is online

Users browsing this forum: No registered users and 2 guests