当我在 Python 中向我的调制解调器发送串行端口消息时,整数 return 值是什么意思?

What does the integer return value mean, when I send a serial port message to my modem in Python?

如何解释以下代码中返回的 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 信息”时,returns 13:

ser.write(b"AT+CGPSINFO\r\n")
>>> 13

还有最后一个例子,当我请求激活 GPS 时,它也 returns 13:

ser.write(b"AT+CGPS=1,1\r\n")
>>> 13

谢谢! -肖恩

返回写入数据的长度。这是写函数的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)