def adsSyncWriteControlReqEx(<EOL>port, address, ads_state, device_state, data, plc_data_type<EOL>):<EOL>
sync_write_control_request = _adsDLL.AdsSyncWriteControlReqEx<EOL>ams_address_pointer = ctypes.pointer(address.amsAddrStruct())<EOL>ads_state_c = ctypes.c_ulong(ads_state)<EOL>device_state_c = ctypes.c_ulong(device_state)<EOL>if plc_data_type == PLCTYPE_STRING:<EOL><INDENT>data = ctypes.c_char_p(data.encode("<STR_LIT:utf-8>"))<EOL>data_pointer = data<EOL>data_length = len(data_pointer.value) + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>data = plc_data_type(data)<EOL>data_pointer = ctypes.pointer(data)<EOL>data_length = ctypes.sizeof(data)<EOL><DEDENT>error_code = sync_write_control_request(<EOL>port,<EOL>ams_address_pointer,<EOL>ads_state_c,<EOL>device_state_c,<EOL>data_length,<EOL>data_pointer,<EOL>)<EOL>if error_code:<EOL><INDENT>raise ADSError(error_code)<EOL><DEDENT>
Change the ADS state and the machine-state of the ADS-server.

    :param int port: local AMS port as returned by adsPortOpenEx()
    :param pyads.structs.AmsAddr adr: local or remote AmsAddr
    :param int ads_state: new ADS-state, according to ADSTATE constants
    :param int device_state: new machine-state
    :param data: additional data
    :param int plc_data_type: plc datatype, according to PLCTYPE constants