我正在使用python语言在RPi中实现SIM900接口.但是,在port.write()函数中发送字符串时出现问题.
这是我的代码:
# This line has to write on serial port port.write(b'AT+SAPBR=3,1,"APN","TATA.DOCOMO.INTERNET"\r\n')
以上行很好用......
现在我的要求是TATA.DOCOMO.INTERNET
必须从命令行读取的字符串,我需要附加该字符串b'AT+SAPBR=3,1,"APN","xxxx"\r\n'
.
但是当我试图将APN名称读入变量并且在追加它之后它不起作用时,代码行就是
# AP ="TATA.DOCOMO.INTERNET"-string read from serial input AP = gsm.read() t1 = "AT+SAPBR=3,1," t2 = '"APN",' t3 = AP t4 = '\r\n' t = t1 + t2 + t3 + t4
它在python中的输出如下:
AT+SAPBR=3,1,"APN","TATA.DOCOMO.INTERNET"\r\n'
它看起来像我需要的行,但是当我在gsm.write(t)中写入时它会出错,我甚至尝试过
gsm.write(byte(t)) gsm.write(t.encode())
但是,它仍然无效.