libftdi Archives

Subject: ftdi_setflowctrl() incorrectly sets XON and XOFF character values

From: Pawel Jewstafjew <pawel.jewstafjew@xxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Sun, 10 Sep 2017 16:02:54 +0100
Dear libftdi Developers,

Present implementation of ftdi_setflowctrl() function incorrectly sets
both Start (XON) and Stop (XOFF) character values to zero.

int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl)
{
[…]
if (libusb_control_transfer(ftdi->usb_dev, FTDI_DEVICE_OUT_REQTYPE,
SIO_SET_FLOW_CTRL_REQUEST, >>0<<, (flowctrl | ftdi->index), NULL, 0,
ftdi->usb_write_timeout) < 0)
[…]

Obviously this makes using XON/XOFF flow control mode impossible with libftdi.

An example code setting Start/Stop character values:

int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl, uint8_t
xon_char, uint8_t xoff_char)
{
[…]
// note: xon_char and xoff_char values are only used in XON/XOFF mode
uint16_t value = (xoff_char << 8) | xon_char;
if (usb_control_msg(ftdi->usb_dev, FTDI_DEVICE_OUT_REQTYPE,
                        SIO_SET_FLOW_CTRL_REQUEST, value, (flowctrl |
ftdi->index),
                        NULL, 0, ftdi->usb_write_timeout) != 0)
[…]


Or, to preserve backward compatibility of the libftdi ABI, this can be
also done by adding a new function, for example:

int ftdi_setflowctrl_xonxoff(struct ftdi_context *ftdi, uint8_t xon,
uint8_t xoff)
{
[…]
uint16_t value = (xoff_char << 8) | xon_char;
if (usb_control_msg(ftdi->usb_dev, FTDI_DEVICE_OUT_REQTYPE,
                        SIO_SET_FLOW_CTRL_REQUEST, value,
(SIO_XON_XOFF_HS | ftdi->index),
                        NULL, 0, ftdi->usb_write_timeout) != 0)
[…]

Best Regards,
Pawel

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx

Current Thread