def notification(self, plc_datatype=None):<EOL>
def notification_decorator(func):<EOL><INDENT>def func_wrapper(notification, data_name):<EOL><INDENT>contents = notification.contents<EOL>data = contents.data<EOL>data_size = contents.cbSampleSize<EOL>datatype_map = {<EOL>PLCTYPE_BOOL: "<STR_LIT>",<EOL>PLCTYPE_BYTE: "<STR_LIT>",<EOL>PLCTYPE_DINT: "<STR_LIT>",<EOL>PLCTYPE_DWORD: "<STR_LIT>",<EOL>PLCTYPE_INT: "<STR_LIT>",<EOL>PLCTYPE_LREAL: "<STR_LIT>",<EOL>PLCTYPE_REAL: "<STR_LIT>",<EOL>PLCTYPE_SINT: "<STR_LIT>",<EOL>PLCTYPE_UDINT: "<STR_LIT>",<EOL>PLCTYPE_UINT: "<STR_LIT>",<EOL>PLCTYPE_USINT: "<STR_LIT>",<EOL>PLCTYPE_WORD: "<STR_LIT>",<EOL>}  <EOL>if plc_datatype == PLCTYPE_STRING:<EOL><INDENT>dest = (c_ubyte * data_size)()<EOL>memmove(addressof(dest), addressof(data), data_size)<EOL>value = bytearray(dest).split(b"<STR_LIT>", <NUM_LIT:1>)[<NUM_LIT:0>].decode("<STR_LIT:utf-8>")<EOL><DEDENT>elif issubclass(plc_datatype, Structure):<EOL><INDENT>value = plc_datatype()<EOL>fit_size = min(data_size, sizeof(value))<EOL>memmove(addressof(value), addressof(data), fit_size)<EOL><DEDENT>elif plc_datatype not in datatype_map:<EOL><INDENT>value = data<EOL><DEDENT>else:<EOL><INDENT>value = struct.unpack(<EOL>datatype_map[plc_datatype], bytearray(data)[:data_size]<EOL>)[<NUM_LIT:0>]<EOL><DEDENT>dt = filetime_to_dt(contents.nTimeStamp)<EOL>return func(contents.hNotification, data_name, dt, value)<EOL><DEDENT>return func_wrapper<EOL><DEDENT>return notification_decorator<EOL>
Decorate a callback function.

        **Decorator**.

        A decorator that can be used for callback functions in order to
        convert the data of the NotificationHeader into the fitting
        Python type.

        :param plc_datatype: The PLC datatype that needs to be converted. This can
        be any basic PLC datatype or a `ctypes.Structure`.

        The callback functions need to be of the following type:

        >>> def callback(handle, name, timestamp, value)

        * `handle`: the notification handle
        * `name`: the variable name
        * `timestamp`: the timestamp as datetime value
        * `value`: the converted value of the variable

        **Usage**:

            >>> import pyads
            >>>
            >>> plc = pyads.Connection('172.18.3.25.1.1', 851)
            >>>
            >>>
            >>> @plc.notification(pyads.PLCTYPE_STRING)
            >>> def callback(handle, name, timestamp, value):
            >>>     print(handle, name, timestamp, value)
            >>>
            >>>
            >>> with plc:
            >>>    attr = pyads.NotificationAttrib(20,
            >>>                                    pyads.ADSTRANS_SERVERCYCLE)
            >>>    handles = plc.add_device_notification('GVL.test', attr,
            >>>                                          callback)
            >>>    while True:
            >>>        pass