<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(self, cmd='AT'):
 """write string to modem, returns number of bytes written."""

        self.cmd_response = ''
        self.cmd_responselines = []
        if self.ser is None:
            return 0
        cmd += '\r\n'
        return self.ser.write(cmd.encode())