<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_string(self, registeraddress, textstring, numberOfRegisters=16):
 """Write a string to the slave. Each 16-bit register in the slave are interpreted as two characters (1 byte = 8 bits). For example 16 consecutive registers can hold 32 characters (32 bytes). Uses Modbus function code 16. Args: * registeraddress (int):
 The slave register start address (use decimal numbers, not hex). * textstring (str):
 The string to store in the slave * numberOfRegisters (int):
 The number of registers allocated for the string. If the textstring is longer than the 2*numberOfRegisters, an error is raised. Shorter strings are padded with spaces. Returns: None Raises: ValueError, TypeError, IOError """

        _checkInt(numberOfRegisters, minvalue=1, description='number of registers for write string')
        _checkString(textstring, 'input string', minlength=1, maxlength=2 * numberOfRegisters)
        self._genericCommand(16, registeraddress, textstring, \
            numberOfRegisters=numberOfRegisters, payloadformat='string')