I am trying to get a signal when the DCD (Carrier Detect) line changes. The
documentation says I can get a SIGHUP when the carrier goes away, but it
doesn’t seem to be working. I can poll the status and detect a change, but
I don’t get a signal. Below is a snippet of code. I get an ENOTTY from the
DCMD_CHR_LINESTATUS, which the docs say would indicate that /dev/ser1 is not
a terminal. An old version of tinit seems to support creating a terminal,
attaching it to a serial port and running a process. The current version
does not seem to do that. Any idea as to what I can do here to make it work
would be greatly appreciated.
pid_t self = setpgrp();
fd = open("/dev/ser1", O_RDWR);
if (fd == -1)
{
perror(“open:”);
return -1;
}
if (tcsetpgrp(fd, self) != 0)
{
perror(“tcsetpgrp:”);
printf(“Errno is 0x%x\n”, errno);
// return -1;
}
signal(SIGHUP, Handler);
for (int i=0; i<60; i++)
{
if (devctl(fd, DCMD_CHR_LINESTATUS, &data, sizeof(data), NULL) != 0)
{
perror(“devctl:”);
return -1;
}
printf(“Linestatus is 0x%x\n”, data);
sleep(1);
}