T.R | Title | User | Personal Name | Date | Lines |
---|
9132.1 | | NETRIX::"[email protected]" | paradis | Wed Mar 12 1997 07:39 | 9 |
| I tried your program on my system and it works. How are you checking
to see if crtscts is set/cleared?
As far as using ioctl(fd,TCSETAF,&rs_type) it should also work except
that rs_type would be a termio structure and not a termios structure
and you would have to include the termio.h header file.
--dennis
[Posted by WWW Notes gateway]
|
9132.2 | | JRDV04::SURUGA | | Thu Mar 13 1997 04:27 | 20 |
| >I tried your program on my system and it works. How are you checking
>to see if crtscts is set/cleared?
I hook up a serial line and attach a 25 connector and use a DC tester
to check line 4 which is a RTS. Currently in my system with the program
posted in .0, when the program sets CRTSCTS, the tester shows few voltage
and waits about 5 seconds, and it does not goes low even the CRTSCTS unset
is executed. When program finishes, it goes low. If I understands corretly,
it should go low when CRTSCTS unset is executed 5 seconds before the program
finishes. I am using AlphaStation 200 4/100 running Digital UNIX V4.0B.
I have a same question - how did you check in your system ?
Another question: what is the difference between TCSETAF and TCSETAW ?
I looked at the ioctl.h file but really cannot tell the difference.
Is there any manual explain ttys in more detail ?
Thanks,
K. Suruga
|
9132.3 | | NETRIX::"[email protected]" | paradis | Thu Mar 13 1997 13:41 | 22 |
| When you set/clear CRTSCTS that has no immediate impact on the RTS signal.
All that does is tells the driver to use hardware flow control. The lowering
and raising of RTS will not be seen until data is being sent from a device
to the system. As data is coming in and being stored in clist buffers the
subsystem checks to see if the number of bytes stored is at a certain
threshold. If so the driver will drop RTS indicating to the sender that they
should stop tranmitting. When the number of bytes stored drops below the
threshold the driver will raise RTS and the device on the other end should
resume sending. So setting/clearing the flag will not raise/lower RTS. If
you seeing the signal raise and drop it's because the driver raises the
signal, along with DTR, when the device is opened and drops them on the
close.
To check whether or not the flag was being set/cleared I issued a
stty -f /dev/tty00 -a from another window at each sleep point in
your program.
The difference between TCSETAF and TCSETAW is that TCSETAF causes the
input buffers to be flushed.
--dennis
[Posted by WWW Notes gateway]
|
9132.4 | | JRDV04::SURUGA | | Fri Mar 14 1997 00:17 | 7 |
| Thank you for clear explonation. I checked with stty and seem to be
working correctly. I will pass this info to our partner. Since they asked,
is there any manual explains tty programming ?
Thanks,
K. Suruga
|
9132.5 | | NETRIX::"[email protected]" | paradis | Fri Mar 14 1997 08:03 | 6 |
| The manpages provide some information. See man 7 tty and man termios for
additional information. If you do a man scc and man ace that will give
you some info on the hardware.
--dennis
[Posted by WWW Notes gateway]
|
9132.6 | thank you. /KS | JRDV04::SURUGA | | Sun Mar 16 1997 21:04 | 0 |
9132.7 | | JRDV04::SURUGA | | Wed Mar 19 1997 02:46 | 87 |
| I thought this issue was resolved but the partner keep asking more quetions.
They asked about TIOCM_RTS and TIOCM_CTS defined in the ioctl.h.
Can they use these values to control RTS and CTS from application program ?
They want to control these lines from application program because the target
subsystem requires use of these lines. In the case of CRTSCTS, the driver
handles flow control, but this is not what they want to do. Here is a
timming chart of 2 devices.
AS2100 TXD --------------------------------------------
SND SND
RTS -------| |--------------| |
| | | |
----------- -----------
target TXD ---------------------------------------------
REC RTS REC RTS
The AS2100 sends commands to to target and while the target is processing,
the RTS must be high. The RTS goes low when target returns some signal to
AS2100.
It seems to me that they can use TIOCM_RTS and TIOCS_CTS to on/off the
values shown in the last line of stty -a output.
dtr = on; dsr = off; rts = on; cts = off; dcd = off
If not, how can I control dtr, dsr, rts, cts, dcd shown in the stty -a
output ? I wrote a small program (attached below) to on/off RTS but this
program does not work. When I issue ioctl, it returns errno 25 (Not a
typewriter). I assume I am not using TIOCM_RTS correctly.
Can you help me ?
Thanks,
K. Suruga
#include <stdio.h>
#include <termio.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <stdlib.h>
#include <errno.h>
main ()
{
int fd,ret;
struct termio rs_type;
int buf=0;
fd = open("/dev/tty00",O_RDWR,0);
if (fd < 0) {
printf("Unable to open /dev/tty00\n");
perror("open:");
exit(1);
}
printf("TIOCM_RTS:%d\n",TIOCM_RTS);
if((ioctl(fd,TIOCMODG,&buf))==-1){
printf("errno= %d\n",errno);
printf("ioctl error1\n");
}
buf |= TIOCM_RTS;
printf("buf :%d\n", buf);
if((ioctl(fd,TIOCMODS,&buf))==-1){
printf("errno= %d\n",errno);
printf("ioctl error2\n");
}
sleep(5);
printf("buf :%d\n", buf);
system("stty -f /dev/tty00 -a");
buf &= ~TIOCM_RTS;
if((ioctl(fd,TIOCMODS,&buf))==-1){
printf("errno= %d\n",errno);
printf("ioctl error3\n");
}
sleep(5);
system("stty -f /dev/tty00 -a");
close(fd);
}
|
9132.8 | | JRDV04::SURUGA | | Wed Mar 19 1997 07:31 | 10 |
| If I set ICANON flag and issue ioctl such as
rs_type.c_lflag |= ICANON;
ioctl(des,TCSETAF,&rs_type);
do I see the changes (icanon/-icanon ) if I issue stty -f /dev/tty00 -a ?
Thanks,
K. Suruga
|
9132.9 | | NETRIX::"[email protected]" | paradis | Wed Mar 19 1997 08:37 | 124 |
| Your application can only control DTR and RTS. The DSR, CTS and DCD signals
are controller by the device connected to serial port. Now if what's connected
to the serial port is another system then you would need to use a null modem
cable in which case when the system on the other end drops RTS this would
cause the local system to see CTS drop.
As far as your program goes you need to use the ioctls TIOCMSET, TIOCMGET or
TIOCMBIS, TIOCMBIC to manipulate DTR and RTS. Here's a sample program:
/* dtr_rts.c
*
* Test program for testing the ability to set/clear
* DTR and RTS independently.
*
*/
#include <stdio.h>
#include <signal.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/termios.h>
void prompt();
void show_settings();
main()
{
int c, fd, cflag, nflag, status, show;
if ((fd = open("/dev/tty00", O_RDWR | O_SYNC, 0)) < 0) {
printf ("Cannot open /dev/tty00");
exit(-1);
}
prompt();
while ((c = getchar()) != EOF) {
if (c != '\n') {
/* Get current settings and display them. */
if ((status = ioctl(fd, TIOCMGET, &cflag)) < 0)
printf("Cannot get modem bits\n");
show = 0;
nflag = cflag;
/* Set/clear DTR or RTS according to users request. */
switch (c) {
case '0': exit (0);
case '1': nflag |= TIOCM_DTR; break;
case '2': nflag &= ~TIOCM_DTR; break;
case '3': nflag |= TIOCM_RTS; break;
case '4': nflag &= ~TIOCM_RTS; break;
case '5': show++; break;
default: break;
}
printf("Current seetings are: (0%o) ", cflag);
show_settings(cflag);
if (!show) {
/* Write the new settings back out. */
if ((status = ioctl(fd, TIOCMSET, &nflag)) < 0)
printf("Cannot set modem bits\n");
/* Now read them back in and display them. */
if ((status = ioctl(fd, TIOCMGET, &cflag)) < 0)
printf("Cannot get modem bits\n");
printf("New settings are: (0%o) ", cflag);
show_settings(cflag);
}
prompt();
}
}
}
void
prompt()
{
printf("\n");
printf("1 = SET DTR \n");
printf("2 = CLEAR DTR \n");
printf("3 = SET RTS \n");
printf("4 = CLEAR RTS \n");
printf("5 = SHOW SETTINGS \n");
printf("0 = EXIT \n");
}
void
show_settings(int flag)
{
if (flag & TIOCM_LE)
printf("LE ");
if (flag & TIOCM_DTR)
printf("DTR ");
if (flag & TIOCM_RTS)
printf("RTS ");
if (flag & TIOCM_ST)
printf("ST ");
if (flag & TIOCM_SR)
printf("SR ");
if (flag & TIOCM_CTS)
printf("CTS ");
if (flag & TIOCM_CD)
printf("CD ");
if (flag & TIOCM_RI)
printf("RI ");
if(flag & TIOCM_DSR)
printf("DSR ");
printf("\n");
return;
}
[Posted by WWW Notes gateway]
|
9132.10 | | NETRIX::"[email protected]" | paradis | Wed Mar 19 1997 08:41 | 9 |
| .8
It depends, if your program is keeping the device open then yes. However
if your program is simply opening the device, issuing the ioctl and exiting
then no. Once the device is closed it's reset to it's defaults values however
some attributes are retained on a close. icanon is not.
--dennis
[Posted by WWW Notes gateway]
|
9132.11 | | JRDV04::SURUGA | | Mon Mar 24 1997 01:53 | 13 |
| >.8
>
>It depends, if your program is keeping the device open then yes. However
>if your program is simply opening the device, issuing the ioctl and exiting
>then no. Once the device is closed it's reset to it's defaults values however
>some attributes are retained on a close. icanon is not.
There was a bug in the program which made icanon to act differently.
It now works as expected.
Thanks,
K. Suruga
|
9132.12 | | JRDV04::SURUGA | | Mon Mar 24 1997 02:38 | 30 |
| The usage of TIOCM_DTR and TIOCM_RTS you posted in .9 is what I
have been looking for. I need to wait few more days to see whether
this is what the partner wanted or not.
Based on the sample program, and stty usage, I have few questions.
When I set/clear DTR or RTS, I can check by calling TIOCMGET routine
in the sample program. However, when I issue stty -f /dev/tty00 -a from
another window or include this line in the program, the setting is cleared
or reset to the default value. Is this expected behavior ?
/* Write the new settings back out. */
if ((status = ioctl(fd, TIOCMSET, &nflag)) < 0)
printf("Cannot set modem bits\n");
system("stty -f /dev/tty00 -a"); <<< added this line
/* Now read them back in and display them. */
if ((status = ioctl(fd, TIOCMGET, &cflag)) < 0)
printf("Cannot get modem bits\n");
It seems to me that whatever the setting should be varfied by stty command.
Also when I issue stty -f /dev/tty00 -a, the last line shows like follows.
dtr = on; dsr = off; rts = on; cts = on; dcd = off
When I cleared DTR, how can I check (dtr = off) by using stty command ?
Thanks,
K. Suruga
|
9132.13 | | NETRIX::"[email protected]" | paradis | Mon Mar 24 1997 08:03 | 5 |
| You can't. When the device is opened the driver turns DTR and RTS on. So when
stty opens the device those two signals get turned back on.
--dennis
[Posted by WWW Notes gateway]
|