Serial port problem.

Hi everyone !


I’m having a ‘minor’ problem with a serial port in QNX 4.25. i have a small
aplication that talks to a hhardware unit connected to the serial port. My
problem is that in order to get the communications working, I have to manually
use ‘stty -brkint -ohpaged -ihflow -ohflow -lkhflow -DTR -RTS < /dev/ser1’ to
get my software to talk nicely to the hardware. I have been looking in the
doumentation to try to find a way to set these flags when I initiate the port
in my software but haven’t been able to find anything that seems to work.

i try to set the port to RAW mode with:
dev_mode(fd ,0, _DEV_MODES);

The I use tcgetattr / tcgetattr to get te current settings and set my
requested ones. All seems to work except that when I run sttys on the port
after it has been opened, it doesn’t remove the flags mentioned above. I found
ihflow/ohflow flags that work if IEXTEN is used but I guess that I haven’t
used them correctly.

I would appreciate if someone could give me a pointer or an examle of how to
get the port working the way I’d like.

Regards,
Joachim Holst

Joachim Holst wrote:

Hi everyone !


I’m having a ‘minor’ problem with a serial port in QNX 4.25. i have a
small aplication that talks to a hhardware unit connected to the serial
port. My problem is that in order to get the communications working, I
have to manually use ‘stty -brkint -ohpaged -ihflow -ohflow -lkhflow
-DTR -RTS < /dev/ser1’ to get my software to talk nicely to the
hardware. I have been looking in the doumentation to try to find a way
to set these flags when I initiate the port in my software but haven’t
been able to find anything that seems to work.

i try to set the port to RAW mode with:
dev_mode(fd ,0, _DEV_MODES);

The I use tcgetattr / tcgetattr to get te current settings and set my
requested ones. All seems to work except that when I run sttys on the
port after it has been opened, it doesn’t remove the flags mentioned
above. I found ihflow/ohflow flags that work if IEXTEN is used but I
guess that I haven’t used them correctly.
Some utilities, such as ksh, restore the stty settings when they exit.

If you have /dev/ser1 opened by ksh, and then from another program you
change the settings, when ksh exits the settings will be reset.

Richard

I would appreciate if someone could give me a pointer or an examle of
how to get the port working the way I’d like.

Regards,
Joachim Holst

Hello Richard and everyone else !

Richard Kramer wrote:

The I use tcgetattr / tcgetattr to get te current settings and set my
requested ones. All seems to work except that when I run sttys on the
port after it has been opened, it doesn’t remove the flags mentioned
above. I found ihflow/ohflow flags that work if IEXTEN is used but I
guess that I haven’t used them correctly.

Some utilities, such as ksh, restore the stty settings when they exit.
If you have /dev/ser1 opened by ksh, and then from another program you
change the settings, when ksh exits the settings will be reset.

Thanks’ for the info. This was new to me, however in my current state of
blindness I’m not able to see how this can be related to my problem which is
that unless I manually run the stty utility on a serial port, my hardware
stubbornly refuses to talk to my program. I run the program in the same shell
as I run stty and do not close any shells while I’m testing.

Regards,
Joachim Holst

Joachim Holst wrote:

Hello Richard and everyone else !

Richard Kramer wrote:

The I use tcgetattr / tcgetattr to get te current settings and set my
requested ones. All seems to work except that when I run sttys on the
port after it has been opened, it doesn’t remove the flags mentioned
above. I found ihflow/ohflow flags that work if IEXTEN is used but I
guess that I haven’t used them correctly.


Some utilities, such as ksh, restore the stty settings when they exit.
If you have /dev/ser1 opened by ksh, and then from another program you
change the settings, when ksh exits the settings will be reset.


Thanks’ for the info. This was new to me, however in my current state of
blindness I’m not able to see how this can be related to my problem
which is that unless I manually run the stty utility on a serial port,
my hardware stubbornly refuses to talk to my program. I run the program
in the same shell as I run stty and do not close any shells while I’m
testing.

A couple more things - to set the IHFLOW and OHFLOW, and maybe some of
the others, you may need to unset TC_PROTECT_HFLOW. Here is an example:
static void set_line( speed_t Baud )
{
tcgetattr( Mdm_fd, &Termio );

Cur_termio = Termio;
Cur_termio.c_cflag &= ~( PARENB | PARODD | PARSTK | CSIZE | CSTOPB );
Cur_termio.c_cflag |= CS8;

Cur_termio.c_lflag |= IEXTEN;
Cur_termio.c_iflag &= ~IXOFF ;
if ( Xonxoff ) {
Cur_termio.c_iflag |= IXON;
Cur_termio.c_cflag &= ~( IHFLOW | OHFLOW );
}
else {
Cur_termio.c_iflag &= ~IXON;
Cur_termio.c_cflag |= ( IHFLOW | OHFLOW );
}
Cur_termio.c_qflag &= ~( TC_PROTECT_HFLOW | TC_PROTECT_SFLOW );

if ( Baud ) {
cfsetispeed( &Cur_termio, Baud );
cfsetospeed( &Cur_termio, Baud );
}

tcsetattr( Mdm_fd, TCSANOW, &Cur_termio );
Cur_termio.c_qflag |= TC_PROTECT_HFLOW | TC_PROTECT_SFLOW ;
tcsetattr( Mdm_fd, TCSANOW, &Cur_termio );
tcflow( Mdm_fd, TCOON | TCOONHW | TCION | TCIONHW );
}

In addition, your original post mentioned setting DTR and RTS. To the
best of my knowlege, you need to use qnx_ioctl() for this. To see which
bits you need to set, look at /usr/include/sys/qioctl.h

Good luck,

Richard

Regards,
Joachim Holst

A couple more things - to set the IHFLOW and OHFLOW, and maybe some of
the others, you may need to unset TC_PROTECT_HFLOW. Here is an example:

— cut code example —

In addition, your original post mentioned setting DTR and RTS. To the
best of my knowlege, you need to use qnx_ioctl() for this. To see which
bits you need to set, look at /usr/include/sys/qioctl.h

Thank’s for your help. I seem to have solved my problem now. My application is
working the way I like it to :slight_smile:

Regards,
Joachim Holst