我想通过pyserial发送一个简单的命令,但是我发现当我在pyserial.write
中发送""
符号时,它会变成另一种格式。你知道吗
我可以知道如何使用pyserial发送""
符号吗?你知道吗
import serial
import time
import sys
class SIMComModem(object):
def __init__(self):
self.open()
def open(self):
self.ser = serial.Serial('COM9', 115200, timeout=5)
print("Send AT OK command \n ")
self.SendCommand('AT\r')
time.sleep(0.5)
def SendCommand(self, command, getline=True):
self.ser.flushInput()
self.ser.flushOutput()
print(command.encode())
self.ser.write(command.encode())
data = ''
if getline:
data = self.ReadLine()
return data
def ReadLine(self):
data = self.ser.readline()
data = self.ser.readline()
print(data)
return data
def SetGPS(self):
pass
def GetGpsOne(self):
print("Set APN")
self.SendCommand('AT+CGSOCKCONT=1,”IP”,”mobile”\r')
time.sleep(0.5)
print("Donwnload GpsOneData")
self.SendCommand('AT+CGPSXD=0\r')
time.sleep(0.5)
self.SendCommand('AT+CHTPSERV=\\”ADD\\”,\\”www.google.com\\”,80,1\r')
time.sleep(0.5)
print("Update Time zone")
self.SendCommand('AT+CTZU=1\r')
time.sleep(0.5)
self.SendCommand('AT+CCLK?\r')
time.sleep(0.5)
我希望当我调用GetGpsOne函数时,它会将AT+CGSOCKCONT=1,"IP","mobile"
发送到COM端口,但结果如下:
b'AT\r'
b'OK\r\n'
Set APN
b'AT+CGSOCKCONT=1,\xe2\x80\x9dIP\xe2\x80\x9d,\xe2\x80\x9dmobile\xe2\x80\x9d\r'
您需要的是"straight" quotes,而不是当前使用的”typographical” quotes。你知道吗
试试看
相反。你知道吗
为了澄清,以下是您的排版引用的错误之处:
相关问题 更多 >
编程相关推荐