.. _auto_flange_serial_read: flange_serial_read (Auto Mode) ------------------------------------------ This section explains how to use :ref:`flange_serial_read ` during **Auto (Run)** operations to receive data from a device connected to the robot’s flange-mounted serial port. This function waits up to the given timeout for data on the given port and returns the received bytes and their count in a FLANGE_SER_RXD_INFO_EX structure, allowing the robot to process responses or sensor readings from the tool. **Typical usage** - Receive status feedback from a smart gripper. - Read barcode/QR scan data from a serial scanner. - Acquire sensor data from tool-mounted measurement devices. - Implement handshake/acknowledgment logic with external peripherals. .. Note:: - The serial port must be opened beforehand with ``flange_serial_open``. - Many devices require request–response timing considerations. - The flange board revision used by the flange serial and flange I/O functions is read at open_connection. **Example: Reading a Response From a Tool Device** .. code-block:: cpp // Open serial port drfl.flange_serial_open(1, 115200); // Wait up to 3 seconds for data on port 1 (X1) LPFLANGE_SER_RXD_INFO_EX rx = drfl.flange_serial_read(3.0f, 1); if (rx == nullptr || rx->_iSize <= 0) { printf("No data received.\n"); return -1; } printf("Received (%d bytes): %.*s\n", rx->_iSize, rx->_iSize, (const char*)rx->_cRxd); In this example, data is read from the tool after a previous write operation, allowing the robot to receive device responses in Auto mode. **Tips** - One read returns at most 256 bytes. - Some devices require a delay after write before attempting to read. - Use polling or loop-based reads for larger or streaming data. - Combine with serial-write to implement command–response or handshake protocols.