import serial
ser = serial.Serial("/dev/ttyUSB0", timeout=2.0)
while 1:
    atCommand = input('Enter AT Command:  ')
    atCommandFormated = atCommand + '\r'
    atCommandEncoded = atCommandFormated.encode("ascii")
    atCommandEncoded
    print(type(atCommandEncoded))
    ser.write(atCommandEncoded)
    print("AT Command was Sent.\n waiting for OK\n")
    out = ser.read(10000)
    print("Type is:  ", type(out))
    #print("raw  ", ser.read(100))
    print("out  :", out.decode("ascii"))
    #print(out)
    #print(out.decode("utf-8"))
    print("raw out  :",out)
    #print("ascii  :", out.decode("ascii"))
    #print(bytearray.fromhex(out).decode())
    print("unicode_escape   :", out.decode("unicode_escape"))
    #print(out.decode("hex"))
    ser.close()
    ser.write('AT+CGMM\r'.encode("ascii"))
    ser.write('AT+CENG=?\r'.encode("ascii"))
    ser.write('AT+CENG=?\r'.encode('ascii'))
    ser.write('AT+CIMI=?;\r'.encode('ascii'))
    ser.write('AT+CMGF=?:\r'.encode('ascii'))
    ser.write('AT+CENG=1,1\r'.encode('ascii'))
    ser.write('AT+CENG?\r'.encode('ascii'))
    ser.read(250)
    ser.write('AT+GCAP\r'.encode('utf-8'))
    ser.write('AT\r'.encode('utf-8'))
