// WARNING: Please don't edit this file. It was generated by Python/WinRT v3.2.1

#include "py.Windows.Devices.SerialCommunication.h"

namespace py::cpp::Windows::Devices::SerialCommunication
{
    // ----- ErrorReceivedEventArgs class --------------------

    static PyObject* _new_ErrorReceivedEventArgs(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/) noexcept
    {
        static_assert(py::py_type<winrt::Windows::Devices::SerialCommunication::ErrorReceivedEventArgs>::type_name);
        py::set_invalid_activation_error(py::py_type<winrt::Windows::Devices::SerialCommunication::ErrorReceivedEventArgs>::type_name);
        return nullptr;
    }

    static void _dealloc_ErrorReceivedEventArgs(py::wrapper::Windows::Devices::SerialCommunication::ErrorReceivedEventArgs* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* ErrorReceivedEventArgs_get_Error(py::wrapper::Windows::Devices::SerialCommunication::ErrorReceivedEventArgs* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.ErrorReceivedEventArgs", L"Error");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.Error();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _assign_array_ErrorReceivedEventArgs(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Devices::SerialCommunication::ErrorReceivedEventArgs>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_ErrorReceivedEventArgs(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        try
        {
            auto return_value = py::convert_to<winrt::Windows::Foundation::IInspectable>(arg);
            return py::convert(return_value.as<winrt::Windows::Devices::SerialCommunication::ErrorReceivedEventArgs>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_ErrorReceivedEventArgs[] = {
        { "_assign_array_", _assign_array_ErrorReceivedEventArgs, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_ErrorReceivedEventArgs), METH_O | METH_STATIC, nullptr },
        { }};

    static PyGetSetDef _getset_ErrorReceivedEventArgs[] = {
        { "error", reinterpret_cast<getter>(ErrorReceivedEventArgs_get_Error), nullptr, nullptr, nullptr },
        { }};

    static PyType_Slot _type_slots_ErrorReceivedEventArgs[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_ErrorReceivedEventArgs) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_ErrorReceivedEventArgs) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_ErrorReceivedEventArgs) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_ErrorReceivedEventArgs) },
        { }};

    static PyType_Spec type_spec_ErrorReceivedEventArgs = {
        "winrt._winrt_windows_devices_serialcommunication.ErrorReceivedEventArgs",
        sizeof(py::wrapper::Windows::Devices::SerialCommunication::ErrorReceivedEventArgs),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_ErrorReceivedEventArgs};

    // ----- PinChangedEventArgs class --------------------

    static PyObject* _new_PinChangedEventArgs(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/) noexcept
    {
        static_assert(py::py_type<winrt::Windows::Devices::SerialCommunication::PinChangedEventArgs>::type_name);
        py::set_invalid_activation_error(py::py_type<winrt::Windows::Devices::SerialCommunication::PinChangedEventArgs>::type_name);
        return nullptr;
    }

    static void _dealloc_PinChangedEventArgs(py::wrapper::Windows::Devices::SerialCommunication::PinChangedEventArgs* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* PinChangedEventArgs_get_PinChange(py::wrapper::Windows::Devices::SerialCommunication::PinChangedEventArgs* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.PinChangedEventArgs", L"PinChange");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.PinChange();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _assign_array_PinChangedEventArgs(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Devices::SerialCommunication::PinChangedEventArgs>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_PinChangedEventArgs(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        try
        {
            auto return_value = py::convert_to<winrt::Windows::Foundation::IInspectable>(arg);
            return py::convert(return_value.as<winrt::Windows::Devices::SerialCommunication::PinChangedEventArgs>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_PinChangedEventArgs[] = {
        { "_assign_array_", _assign_array_PinChangedEventArgs, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_PinChangedEventArgs), METH_O | METH_STATIC, nullptr },
        { }};

    static PyGetSetDef _getset_PinChangedEventArgs[] = {
        { "pin_change", reinterpret_cast<getter>(PinChangedEventArgs_get_PinChange), nullptr, nullptr, nullptr },
        { }};

    static PyType_Slot _type_slots_PinChangedEventArgs[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_PinChangedEventArgs) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_PinChangedEventArgs) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_PinChangedEventArgs) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_PinChangedEventArgs) },
        { }};

    static PyType_Spec type_spec_PinChangedEventArgs = {
        "winrt._winrt_windows_devices_serialcommunication.PinChangedEventArgs",
        sizeof(py::wrapper::Windows::Devices::SerialCommunication::PinChangedEventArgs),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_PinChangedEventArgs};

    // ----- SerialDevice class --------------------

    static PyObject* _new_SerialDevice(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/) noexcept
    {
        static_assert(py::py_type<winrt::Windows::Devices::SerialCommunication::SerialDevice>::type_name);
        py::set_invalid_activation_error(py::py_type<winrt::Windows::Devices::SerialCommunication::SerialDevice>::type_name);
        return nullptr;
    }

    static void _dealloc_SerialDevice(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* SerialDevice_Close(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 0)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"Close", 0);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

                {
                    auto _gil = release_gil();
                    self->obj.Close();
                }

                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* SerialDevice_FromIdAsync(PyObject* /*unused*/, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 1)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"FromIdAsync", 1);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

                auto param0 = py::convert_to<winrt::hstring>(args, 0);

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return winrt::Windows::Devices::SerialCommunication::SerialDevice::FromIdAsync(param0);
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* SerialDevice_GetDeviceSelector(PyObject* /*unused*/, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 0)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"GetDeviceSelector", 0);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return winrt::Windows::Devices::SerialCommunication::SerialDevice::GetDeviceSelector();
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* SerialDevice_GetDeviceSelectorFromPortName(PyObject* /*unused*/, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 1)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"GetDeviceSelector", 1);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

                auto param0 = py::convert_to<winrt::hstring>(args, 0);

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return winrt::Windows::Devices::SerialCommunication::SerialDevice::GetDeviceSelector(param0);
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* SerialDevice_GetDeviceSelectorFromUsbVidPid(PyObject* /*unused*/, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 2)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"GetDeviceSelectorFromUsbVidPid", 2);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(2);
                    return nullptr;
                }

                auto param0 = py::convert_to<uint16_t>(args, 0);
                auto param1 = py::convert_to<uint16_t>(args, 1);

                return py::convert([&]()
                {
                    auto _gil = release_gil();
                    return winrt::Windows::Devices::SerialCommunication::SerialDevice::GetDeviceSelectorFromUsbVidPid(param0, param1);
                }());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* SerialDevice_get_IsDataTerminalReadyEnabled(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"IsDataTerminalReadyEnabled");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.IsDataTerminalReadyEnabled();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int SerialDevice_put_IsDataTerminalReadyEnabled(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!arg)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"IsDataTerminalReadyEnabled");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return -1;
            }

            auto param0 = py::convert_to<bool>(arg);

            {
                auto _gil = release_gil();
                self->obj.IsDataTerminalReadyEnabled(param0);
            }

            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* SerialDevice_get_DataBits(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"DataBits");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.DataBits();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int SerialDevice_put_DataBits(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!arg)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"DataBits");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return -1;
            }

            auto param0 = py::convert_to<uint16_t>(arg);

            {
                auto _gil = release_gil();
                self->obj.DataBits(param0);
            }

            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* SerialDevice_get_Handshake(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"Handshake");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.Handshake();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int SerialDevice_put_Handshake(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!arg)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"Handshake");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return -1;
            }

            auto param0 = py::convert_to<winrt::Windows::Devices::SerialCommunication::SerialHandshake>(arg);

            {
                auto _gil = release_gil();
                self->obj.Handshake(param0);
            }

            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* SerialDevice_get_BreakSignalState(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"BreakSignalState");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.BreakSignalState();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int SerialDevice_put_BreakSignalState(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!arg)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"BreakSignalState");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return -1;
            }

            auto param0 = py::convert_to<bool>(arg);

            {
                auto _gil = release_gil();
                self->obj.BreakSignalState(param0);
            }

            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* SerialDevice_get_BaudRate(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"BaudRate");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.BaudRate();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int SerialDevice_put_BaudRate(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!arg)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"BaudRate");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return -1;
            }

            auto param0 = py::convert_to<uint32_t>(arg);

            {
                auto _gil = release_gil();
                self->obj.BaudRate(param0);
            }

            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* SerialDevice_get_WriteTimeout(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"WriteTimeout");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.WriteTimeout();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int SerialDevice_put_WriteTimeout(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!arg)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"WriteTimeout");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return -1;
            }

            auto param0 = py::convert_to<winrt::Windows::Foundation::TimeSpan>(arg);

            {
                auto _gil = release_gil();
                self->obj.WriteTimeout(param0);
            }

            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* SerialDevice_get_StopBits(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"StopBits");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.StopBits();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int SerialDevice_put_StopBits(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!arg)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"StopBits");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return -1;
            }

            auto param0 = py::convert_to<winrt::Windows::Devices::SerialCommunication::SerialStopBitCount>(arg);

            {
                auto _gil = release_gil();
                self->obj.StopBits(param0);
            }

            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* SerialDevice_get_ReadTimeout(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"ReadTimeout");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.ReadTimeout();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int SerialDevice_put_ReadTimeout(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!arg)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"ReadTimeout");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return -1;
            }

            auto param0 = py::convert_to<winrt::Windows::Foundation::TimeSpan>(arg);

            {
                auto _gil = release_gil();
                self->obj.ReadTimeout(param0);
            }

            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* SerialDevice_get_Parity(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"Parity");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.Parity();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int SerialDevice_put_Parity(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!arg)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"Parity");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return -1;
            }

            auto param0 = py::convert_to<winrt::Windows::Devices::SerialCommunication::SerialParity>(arg);

            {
                auto _gil = release_gil();
                self->obj.Parity(param0);
            }

            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* SerialDevice_get_IsRequestToSendEnabled(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"IsRequestToSendEnabled");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.IsRequestToSendEnabled();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int SerialDevice_put_IsRequestToSendEnabled(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!arg)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"IsRequestToSendEnabled");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return -1;
            }

            auto param0 = py::convert_to<bool>(arg);

            {
                auto _gil = release_gil();
                self->obj.IsRequestToSendEnabled(param0);
            }

            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* SerialDevice_get_BytesReceived(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"BytesReceived");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.BytesReceived();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* SerialDevice_get_CarrierDetectState(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"CarrierDetectState");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.CarrierDetectState();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* SerialDevice_get_ClearToSendState(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"ClearToSendState");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.ClearToSendState();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* SerialDevice_get_DataSetReadyState(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"DataSetReadyState");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.DataSetReadyState();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* SerialDevice_get_InputStream(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"InputStream");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.InputStream();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* SerialDevice_get_OutputStream(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"OutputStream");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.OutputStream();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* SerialDevice_get_PortName(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"PortName");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.PortName();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* SerialDevice_get_UsbProductId(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"UsbProductId");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.UsbProductId();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* SerialDevice_get_UsbVendorId(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"UsbVendorId");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.UsbVendorId();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* SerialDevice_add_ErrorReceived(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* arg) noexcept
    {
        try
        {
            static std::optional<bool> is_event_present{};

            if (!is_event_present.has_value())
            {
                is_event_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"ErrorReceived");
            }

            if (!is_event_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "event is not available in this version of Windows");
                return nullptr;
            }

            auto param0 = py::convert_to<winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Devices::SerialCommunication::SerialDevice, winrt::Windows::Devices::SerialCommunication::ErrorReceivedEventArgs>>(arg);

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.ErrorReceived(param0);
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* SerialDevice_remove_ErrorReceived(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* arg) noexcept
    {
        try
        {
            static std::optional<bool> is_event_present{};

            if (!is_event_present.has_value())
            {
                is_event_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"ErrorReceived");
            }

            if (!is_event_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "event is not available in this version of Windows");
                return nullptr;
            }

            auto param0 = py::convert_to<winrt::event_token>(arg);

            {
                auto _gil = release_gil();
                self->obj.ErrorReceived(param0);
            }

            Py_RETURN_NONE;
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* SerialDevice_add_PinChanged(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* arg) noexcept
    {
        try
        {
            static std::optional<bool> is_event_present{};

            if (!is_event_present.has_value())
            {
                is_event_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"PinChanged");
            }

            if (!is_event_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "event is not available in this version of Windows");
                return nullptr;
            }

            auto param0 = py::convert_to<winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Devices::SerialCommunication::SerialDevice, winrt::Windows::Devices::SerialCommunication::PinChangedEventArgs>>(arg);

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.PinChanged(param0);
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* SerialDevice_remove_PinChanged(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* arg) noexcept
    {
        try
        {
            static std::optional<bool> is_event_present{};

            if (!is_event_present.has_value())
            {
                is_event_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.Devices.SerialCommunication.SerialDevice", L"PinChanged");
            }

            if (!is_event_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "event is not available in this version of Windows");
                return nullptr;
            }

            auto param0 = py::convert_to<winrt::event_token>(arg);

            {
                auto _gil = release_gil();
                self->obj.PinChanged(param0);
            }

            Py_RETURN_NONE;
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _assign_array_SerialDevice(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Devices::SerialCommunication::SerialDevice>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_SerialDevice(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        try
        {
            auto return_value = py::convert_to<winrt::Windows::Foundation::IInspectable>(arg);
            return py::convert(return_value.as<winrt::Windows::Devices::SerialCommunication::SerialDevice>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _enter_SerialDevice(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* /*unused*/) noexcept
    {
        return Py_NewRef(self);
    }

    static PyObject* _exit_SerialDevice(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice* self, PyObject* /*unused*/) noexcept
    {
        try
        {
            {
                auto _gil = py::release_gil();
                self->obj.Close();
            }

            Py_RETURN_FALSE;
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_SerialDevice[] = {
        { "close", reinterpret_cast<PyCFunction>(SerialDevice_Close), METH_VARARGS, nullptr },
        { "add_error_received", reinterpret_cast<PyCFunction>(SerialDevice_add_ErrorReceived), METH_O, nullptr },
        { "remove_error_received", reinterpret_cast<PyCFunction>(SerialDevice_remove_ErrorReceived), METH_O, nullptr },
        { "add_pin_changed", reinterpret_cast<PyCFunction>(SerialDevice_add_PinChanged), METH_O, nullptr },
        { "remove_pin_changed", reinterpret_cast<PyCFunction>(SerialDevice_remove_PinChanged), METH_O, nullptr },
        { "_assign_array_", _assign_array_SerialDevice, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_SerialDevice), METH_O | METH_STATIC, nullptr },
        { "__enter__", reinterpret_cast<PyCFunction>(_enter_SerialDevice), METH_NOARGS, nullptr },
        { "__exit__", reinterpret_cast<PyCFunction>(_exit_SerialDevice), METH_VARARGS, nullptr },
        { }};

    static PyGetSetDef _getset_SerialDevice[] = {
        { "is_data_terminal_ready_enabled", reinterpret_cast<getter>(SerialDevice_get_IsDataTerminalReadyEnabled), reinterpret_cast<setter>(SerialDevice_put_IsDataTerminalReadyEnabled), nullptr, nullptr },
        { "data_bits", reinterpret_cast<getter>(SerialDevice_get_DataBits), reinterpret_cast<setter>(SerialDevice_put_DataBits), nullptr, nullptr },
        { "handshake", reinterpret_cast<getter>(SerialDevice_get_Handshake), reinterpret_cast<setter>(SerialDevice_put_Handshake), nullptr, nullptr },
        { "break_signal_state", reinterpret_cast<getter>(SerialDevice_get_BreakSignalState), reinterpret_cast<setter>(SerialDevice_put_BreakSignalState), nullptr, nullptr },
        { "baud_rate", reinterpret_cast<getter>(SerialDevice_get_BaudRate), reinterpret_cast<setter>(SerialDevice_put_BaudRate), nullptr, nullptr },
        { "write_timeout", reinterpret_cast<getter>(SerialDevice_get_WriteTimeout), reinterpret_cast<setter>(SerialDevice_put_WriteTimeout), nullptr, nullptr },
        { "stop_bits", reinterpret_cast<getter>(SerialDevice_get_StopBits), reinterpret_cast<setter>(SerialDevice_put_StopBits), nullptr, nullptr },
        { "read_timeout", reinterpret_cast<getter>(SerialDevice_get_ReadTimeout), reinterpret_cast<setter>(SerialDevice_put_ReadTimeout), nullptr, nullptr },
        { "parity", reinterpret_cast<getter>(SerialDevice_get_Parity), reinterpret_cast<setter>(SerialDevice_put_Parity), nullptr, nullptr },
        { "is_request_to_send_enabled", reinterpret_cast<getter>(SerialDevice_get_IsRequestToSendEnabled), reinterpret_cast<setter>(SerialDevice_put_IsRequestToSendEnabled), nullptr, nullptr },
        { "bytes_received", reinterpret_cast<getter>(SerialDevice_get_BytesReceived), nullptr, nullptr, nullptr },
        { "carrier_detect_state", reinterpret_cast<getter>(SerialDevice_get_CarrierDetectState), nullptr, nullptr, nullptr },
        { "clear_to_send_state", reinterpret_cast<getter>(SerialDevice_get_ClearToSendState), nullptr, nullptr, nullptr },
        { "data_set_ready_state", reinterpret_cast<getter>(SerialDevice_get_DataSetReadyState), nullptr, nullptr, nullptr },
        { "input_stream", reinterpret_cast<getter>(SerialDevice_get_InputStream), nullptr, nullptr, nullptr },
        { "output_stream", reinterpret_cast<getter>(SerialDevice_get_OutputStream), nullptr, nullptr, nullptr },
        { "port_name", reinterpret_cast<getter>(SerialDevice_get_PortName), nullptr, nullptr, nullptr },
        { "usb_product_id", reinterpret_cast<getter>(SerialDevice_get_UsbProductId), nullptr, nullptr, nullptr },
        { "usb_vendor_id", reinterpret_cast<getter>(SerialDevice_get_UsbVendorId), nullptr, nullptr, nullptr },
        { }};

    static PyType_Slot _type_slots_SerialDevice[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_SerialDevice) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_SerialDevice) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_SerialDevice) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_SerialDevice) },
        { }};

    static PyType_Spec type_spec_SerialDevice = {
        "winrt._winrt_windows_devices_serialcommunication.SerialDevice",
        sizeof(py::wrapper::Windows::Devices::SerialCommunication::SerialDevice),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_SerialDevice};

    static PyGetSetDef getset_SerialDevice_Static[] = {
        { }};

    static PyMethodDef methods_SerialDevice_Static[] = {
        { "from_id_async", reinterpret_cast<PyCFunction>(SerialDevice_FromIdAsync), METH_VARARGS, nullptr },
        { "get_device_selector", reinterpret_cast<PyCFunction>(SerialDevice_GetDeviceSelector), METH_VARARGS, nullptr },
        { "get_device_selector_from_port_name", reinterpret_cast<PyCFunction>(SerialDevice_GetDeviceSelectorFromPortName), METH_VARARGS, nullptr },
        { "get_device_selector_from_usb_vid_pid", reinterpret_cast<PyCFunction>(SerialDevice_GetDeviceSelectorFromUsbVidPid), METH_VARARGS, nullptr },
        { }};

    static PyType_Slot type_slots_SerialDevice_Static[] = 
    {
        { Py_tp_base, reinterpret_cast<void*>(&PyType_Type) },
        { Py_tp_getset, reinterpret_cast<void*>(getset_SerialDevice_Static) },
        { Py_tp_methods, reinterpret_cast<void*>(methods_SerialDevice_Static) },
        { }
    };

    static PyType_Spec type_spec_SerialDevice_Static = {
        "winrt._winrt_windows_devices_serialcommunication.SerialDevice_Static",
        static_cast<int>(PyType_Type.tp_basicsize),
        static_cast<int>(PyType_Type.tp_itemsize),
        Py_TPFLAGS_DEFAULT,
        type_slots_SerialDevice_Static};

    // ----- Windows.Devices.SerialCommunication Initialization --------------------

    PyDoc_STRVAR(module_doc, "Windows.Devices.SerialCommunication");

    static PyModuleDef module_def = {
        PyModuleDef_HEAD_INIT,
        "_winrt_windows_devices_serialcommunication",
        module_doc,
        0,
        nullptr,
        nullptr,
        nullptr,
        nullptr,
        nullptr};
} // py::cpp::Windows::Devices::SerialCommunication

PyMODINIT_FUNC PyInit__winrt_windows_devices_serialcommunication(void) noexcept
{
    using namespace py::cpp::Windows::Devices::SerialCommunication;

    if (py::import_winrt_runtime() == -1)
    {
        return nullptr;
    }

    py::pyobj_handle module{PyModule_Create(&module_def)};

    if (!module)
    {
        return nullptr;
    }

    auto inspectable_meta_type = py::get_inspectable_meta_type();
    if (!inspectable_meta_type)
    {
        return nullptr;
    }

    auto object_type = py::get_object_type();
    if (!object_type)
    {
        return nullptr;
    }

    py::pyobj_handle object_bases{PyTuple_Pack(1, object_type)};

    if (!object_bases)
    {
        return nullptr;
    }

    py::pytype_handle ErrorReceivedEventArgs_type{py::register_python_type(module.get(), &type_spec_ErrorReceivedEventArgs, object_bases.get(), inspectable_meta_type)};
    if (!ErrorReceivedEventArgs_type)
    {
        return nullptr;
    }

    py::pytype_handle PinChangedEventArgs_type{py::register_python_type(module.get(), &type_spec_PinChangedEventArgs, object_bases.get(), inspectable_meta_type)};
    if (!PinChangedEventArgs_type)
    {
        return nullptr;
    }

    py::pyobj_handle SerialDevice_Static_bases{PyTuple_Pack(1, reinterpret_cast<PyObject*>(inspectable_meta_type))};
    if (!SerialDevice_Static_bases)
    {
        return nullptr;
    }

    py::pyobj_handle type_SerialDevice_Static{PyType_FromSpecWithBases(&type_spec_SerialDevice_Static, SerialDevice_Static_bases.get())};
    if (!type_SerialDevice_Static)
    {
        return nullptr;
    }

    py::pytype_handle SerialDevice_type{py::register_python_type(module.get(), &type_spec_SerialDevice, object_bases.get(), reinterpret_cast<PyTypeObject*>(type_SerialDevice_Static.get()))};
    if (!SerialDevice_type)
    {
        return nullptr;
    }


    return module.detach();
}
