Můžeme zkusit, jak se chová očesaný pokus:
#include <termios.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int fd;
int res;
struct termios options;
if (argc!=2) {
printf("Usage: %s <serial device>\n",argv[0]);
exit(1);
}
printf("Opening device %s\n",argv[1]);
fd = open(argv[1], O_RDWR | O_NOCTTY );
if (fd<0) {
perror("Error opening device");
exit(1);
}
if(tcgetattr(fd, &options)!=0) {
perror("Error getting port options");
exit(1);
}
// set baudrate
cfsetispeed(&options, B19200);
cfsetospeed(&options, B19200);
// set HW control - RTS/CTS
options.c_cflag |= CRTSCTS;
if (tcsetattr(fd, TCSANOW, &options)!=0) {
perror("Error setting port options");
exit(1);
}
if(res=write(fd, "XXXXXXXXXXXXXXXX", 16)<0){
perror("Error writing to port");
} else printf("%d of 16B written.\n",res);
if(close(fd)!=0) {
perror("Error closing port");
}
printf("FD closed.\n");
}