Hi, jyijyi
Thank you for kind explanation.
I could solve how to control RS232C’s pin about DTR, DSR, DCD and RI.
But CTS and RTS remain.
At first, I checked CTS control by reference to the following topic.
However, I could not see changing voltage of CTS output.
Could you check my program?
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <string.h>int fd;
void ttyHS0_Init()
{
struct termios options;fd = open(“/dev/ttyHS0”, O_RDWR | O_NOCTTY);
if(fd < 0) {
printf(“open /dev/ttyHS0 ERROR…\n”);
}fcntl (fd, F_SETFL, 0);
tcgetattr (fd, &options);
options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
options.c_cflag &= ~CRTSCTS;
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
options.c_iflag &= ~(INLCR | ICRNL | IGNCR);
options.c_oflag &= ~OPOST;
options.c_oflag &= ~OLCUC;
options.c_oflag &= ~ONLRET;
options.c_oflag &= ~ONOCR;
options.c_oflag &= ~OCRNL;
tcsetattr (fd, TCSANOW, &options);
}void set_CTS_High()
{
int serialStatus = 0;ioctl(fd, TIOCMGET, &serialStatus);
serialStatus |= TIOCM_RTS;
ioctl(fd, TIOCMSET, &serialStatus);
}void set_CTS_Low()
{
int serialStatus = 0;ioctl(fd, TIOCMGET, &serialStatus);
serialStatus &= ~TIOCM_RTS;
ioctl(fd, TIOCMSET, &serialStatus);
}int main(void) {
// 5s CTS high low change
while(1) {
ttyHS0_Init();
set_CTS_High();
printf(“============[HIGH] CTS========================\n”);
printf(“[HIGH → LOW] after 5s\n”);
sleep(5);
close(fd);
ttyHS0_Init();
set_CTS_Low();
printf(“============[LOW] CTS=========================\n”);
printf(“[LOW → HIGH] after 5s\n”);
sleep(5);
close(fd);
}
return 0;
}
BR,
Tanoue