.. _flange_serial_open: flange_serial_open ------------------------------------------ This function opens the **flange serial transfer port** in the robot controller. **Definition** |br| ``DRFLEx.h`` within class `CDRFLEx`, public section .. code-block:: cpp bool flange_serial_open( int nPort, int baudrate = 115200, BYTE_SIZE eByteSize = BYTE_SIZE_EIGHTBITS, PARITY_CHECK eParity = PARITY_CHECK_NONE, STOP_BITS eStopBits = STOPBITS_ONE) { return _flange_serial_open(_rbtCtrl, nPort, baudrate, eByteSize, eParity, eStopBits); }; **Parameter** .. list-table:: :widths: 20 20 20 40 :header-rows: 1 * - **Parameter Name** - **Data Type** - **Default Value** - **Description** * - nPort - int - - - **Serial port index** |br| 1: X1, 2: X2 (X2 only on M/H models) * - baudrate - int - 115200 - Baudrate setting for serial communication. |br| Supported values: 2400, 4800, 9600, 19200, 38400, 57600, 115200, etc. * - eByteSize - :ref:`BYTE_SIZE ` - BYTE_SIZE_EIGHTBITS - Data bit length * - eParity - :ref:`PARITY_CHECK ` - PARITY_CHECK_NONE - Parity configuration * - eStopBits - :ref:`STOP_BITS ` - STOPBITS_ONE - Stop bit configuration .. Note:: On a rev2 flange, only nPort is used; baudrate, eByteSize, eParity and eStopBits are ignored. On a rev1 flange, nPort is ignored. **Return** .. list-table:: :widths: 25 75 :header-rows: 1 * - **Value** - **Description** * - 0 - Error: failed to open serial port. * - 1 - Success: serial port successfully opened. .. note:: The flange board revision used by the flange serial and flange I/O functions is read at open_connection. **Example** .. code-block:: cpp char buf[] = "test123"; Drfl.flange_serial_open(1, 115200); Drfl.flange_serial_write(7, buf, 1); LPFLANGE_SER_RXD_INFO_EX temp = Drfl.flange_serial_read(4.5, 1); printf("Serial read : %.*s\n", temp->_iSize, (const char*)temp->_cRxd); printf("Serial cnt : %d\n", temp->_iSize); Drfl.flange_serial_close(1); This example opens flange serial port 1 (X1) at **115200 baud**, sends a 7-byte test string, reads back the response, and closes the serial connection.