如何解释以下代码中返回的4
,该代码试图通过串行AT端口/dev/ttyUSB3
向我的SIMCom 7600A调制解调器发送一个基本的AT
消息
from serial import Serial
# If a "port" is given, then the port will be opened immediately.
ser = Serial(port="/dev/ttyUSB3", timeout=2, write_timeout=2)
# The following prints as "True"
print(ser.is_open)
# Turn GPS on
ser.write(b"AT\r\n")
>>> 4
这是我请求“查看GPS信息”时的另一个示例,它返回13
ser.write(b"AT+CGPSINFO\r\n")
>>> 13
最后一个示例是当我请求激活GPS时,它也返回13
ser.write(b"AT+CGPS=1,1\r\n")
>>> 13
谢谢!-Sean
发布于 2020-12-01 19:43:48
它返回写入的数据的长度。下面是write函数的the source:
def write(self, data):
"""Output the given string over the serial port."""
if not self.is_open:
raise PortNotOpenError()
#~ if not isinstance(data, (bytes, bytearray)):
#~ raise TypeError('expected %s or bytearray, got %s' % (bytes, type(data)))
try:
# must call overloaded method with byte array argument
# as this is the only one not applying encodings
self._port_handle.Write(as_byte_array(data), 0, len(data))
except System.TimeoutException:
raise SerialTimeoutException('Write timeout')
return len(data)
https://stackoverflow.com/questions/65097224
复制相似问题