[Solved]16.10.1 ioctl ttyHS0 CTS is an output but can I control it like this?

#1

Hi

I’m trying to use legacy serial port code within a Legato app. I need to be able to control the state of the CTS OP pin (on a PC or USB tty this would be RTS out).

ctx->s is a FILE pointer to /dev/ttyHS0

static void set_OpLocal_cbh(modbus_t *ctx , int on)
{
int fd = ctx->s;
int flags;

LE_INFO("CTS set : %d", on);
LE_INFO("device  %s", ctx->device);

ioctl(fd, TIOCMGET, &flags);
if (on) {
    flags |= TIOCM_CTS;
} else {
    flags &= ~TIOCM_CTS;
}
ioctl(fd, TIOCMSET, &flags);

}

HS0 is opening fine - other code is writing and reading from it OK.

The code above is running

But set_OpLocal_cbh() isn’t able to set the state of the CTS pin (it’s stuck high).

I also tried TIOCM_RTS just in case CTS isn’t really it’s name

Any ideas?

  • should this work?
  • any workarounds to manually drive the CTS whilst HSO is opened by the app?
0 Likes

#2

Worked it out - a previous answer to a similar question on the mangoh forum was leading me astray. It talked about using stty -F /dev/ttyHS0 crtscts to enable disable 4 wire UART. This is not correct

From the linux manual

  • [-]crtscts
    enable RTS/CTS handshaking

By setting (back to defaut)
stty -F /dev/ttyHS0 -crtscts

Then code like this

ioctl(fd, TIOCMGET, &flags);
if (on) {
    flags |= TIOCM_RTS;
} else {
    flags &= ~TIOCM_RTS;
}
ioctl(fd, TIOCMSET, &flags);

Success

Note that TIOCM_RTS actually drives the physical CTS pin on the WP85 module

0 Likes