def _reset_serial(out, serial_port, wait_for_upload_port=False):
    ''' Code original from https://github.com/Robot-Will/Stino/tree/master/app
        adapted to biicode to reset Arduino ports

        Reset any serial port.
            parameters:
                out: bii.user_io.out
                serial_port: current serial port detected
                wait_for_upload_port: True if board == 'leonardo'
            return:
                selected port
    '''
    caterina_serial_port = ''
    before_serial_list = _detect_arduino_port()
    if serial_port in before_serial_list:
        non_serial_list = before_serial_list[:]
        non_serial_list.remove(serial_port)

        out.success('Forcing reset using 1200bps open/close on port %s' % serial_port)
        _touch_serial_port(serial_port, 1200)

        if not wait_for_upload_port:
            time.sleep(0.4)
            return serial_port

        # Scanning for available ports seems to open the port or
        # otherwise assert DTR, which would cancel the WDT reset if
        # it happened within 250 ms. So we wait until the reset should
        # have already occurred before we start scanning.
        time.sleep(3 if OSInfo.is_win() else 0.3)

        # Wait for a port to appear on the list
        elapsed = 0
        while (elapsed < 10000):
            now_serial_list = _detect_arduino_port()
            diff_serial_list = [v for v in now_serial_list if non_serial_list not in v]

            out.success('Ports {%s}/{%s} => {%s}'
                                % (before_serial_list, now_serial_list, diff_serial_list))
            if len(diff_serial_list) > 0:
                caterina_serial_port = diff_serial_list[0]
                out.success('Found new upload port: %s' % caterina_serial_port)
                break

            # Keep track of port that disappears
            # before_serial_list = now_serial_list
            time.sleep(0.25)
            elapsed += 250

            # On Windows, it can take a long time for the port to disappear and
            # come back, so use a longer time out before assuming that the selected
            # port is the bootloader (not the sketch).
            if (((not OSInfo.is_win() and elapsed >= 500)
                or elapsed >= 5000) and (serial_port in now_serial_list)):
                out.success('Uploading using selected port: %s' % serial_port)
                caterina_serial_port = serial_port
                break

        if not caterina_serial_port:
            out.error("Couldn't find a Leonardo on the selected port. "
                      "Check that you have the correct port selected. "
                      "If it is correct, try pressing the board's reset"
                      " button after initiating the upload.")
    return caterina_serial_port or 'None'
dataset/ETHPy150Open biicode/client/dev/hardware/arduino/arduino_port_utils.py/_reset_serial/swapped operands of `not in`