Legato TTY API sets ISTRIP for 8-bit parity framing with parity check

Topic : Legato TTY API sets ISTRIP for 8-bit parity framing with parity check

Tested on: FX30s (R13.1.001 & R14.04.002 firmware)

Legato versions: 16.10.1_eea67704afa1ebc0450d230baa84ac28_modified,

16.10.1.m3_f5d280aff1eaa96ea8459ca6effa50c5_modified

Description :

If serial device is opened in raw mode with 8bit parity checking with the Legato TTY api as in the below:

int SerialPortFd;

SerialPortFd = le_tty_Open( “/dev/ttyHSL0” , O_RDWR | O_NOCTTY | O_NDELAY );

le_tty_SetBaudRate(SerialPortFd, BAUD_RATE);

le_tty_SetRaw(SerialPortFd, 1, 0);

le_tty_SetFraming(SerialPortFd, ‘E’, 8, 1);

…it will cause ISTRIP to be set for the device, which means the high bit will be cleared in read input - for example, the byte 0xAB will read out as 0x2B

This has been tested with modbus device in RS485 mode on fx30s. The sequence in which framing and raw mode is set doesn’t seem to matter.

I am not aware of a way to work around this problem from the legato TTY API, outside manually setting -istrip for the device from the command line.

Steps to reproduce:

Problem was encountered reading modbus device from legato app, but for the purpose of reproducing, it should be enough to set framing 8, ‘E’, 1 and raw mode (as per above), and verify with “stty -F /dev/ttyHSL0 -a” that istrip is enabled.

Using “stty -F /dev/ttyHSL0 -istrip” from the command line will cause incorrect readings to be correct when my legato app is running.

Refer to code,
https://github.com/legatoproject/legato-af/blob/master/framework/liblegato/linux/tty.c

Seems like it set istrip whenever you set framing “E” or “O”.

case 'O':
case 'o':
    // Odd parity.
    portSettings->c_cflag |= (PARENB | PARODD);
    portSettings->c_iflag |= (INPCK | ISTRIP);
    break;

case 'E':
case 'e':
    // Even parity.
    portSettings->c_cflag |= PARENB;
    portSettings->c_iflag |= (INPCK | ISTRIP);
    break;

So probably you may modify the code and rebuild Legato for your needs, or call stty in app to change it back.

Thx

@torbendeleuran, I tested a @iotam workaround and it works well, but I wonder! maybe in others cases, ISTRIP will be useful !