def METHOD_NAME(self, ser, message, file=None):
    # Check that the device is no longer sending bytes
    if ser.in_waiting:
        self.serial_read(ser, message, file)
    # Check that the serial connection is open
    if ser.writable():
        # special handling for sending a file
        if "sz " in message:
            temp_written = ser.write(bytearray("rz\r\n".encode('ascii')))
            os.system(message)
            # check for completion
            output = ser.readline(ser.in_waiting)
            output = output.decode(encoding='utf-8', errors='ignore')
            # print(output)
            start_time = time.time()
            while ("Transfer" not in output) and (time.time() - start_time) < serial_settings.wait_for_flash:
                time.sleep(.01)
                output = ser.readline(ser.in_waiting)
                output = output.decode(encoding='utf-8', errors='ignore')
                if "incomplete" in output:
                    serial_settings.tests_run = True
                    azure_test_firmware_errors.SDK_ERRORS += 1
                    return 0
            if "incomplete" in output:
                serial_settings.tests_run = True
                azure_test_firmware_errors.SDK_ERRORS += 1
                return 0
            return temp_written
        # special handling for receiving a file, Note: input file should use rz <filepath> when a file from the RPi is desired
        elif "rz " in message:
            os.system('rz')
            message.replace('rz ', 'sz ')
        buf = bytearray((message).encode('ascii'))
        print(buf)
        bytes_written = ser.write(buf)
        return bytes_written
    else:
        try:
            time.sleep(2)
            ser.open()
            self.METHOD_NAME(ser, message, file)
        except:
            return 0