我需要帮助是使用串行端口,我有 3DR 无线电遥测连接到我的 python 和我的 Windows PC 的另一端,我有小的 python 代码,它不断将数据写入串行端口并读取,读取可能不是问题,或者它反正以后可能...
问题是我担心写太多可能会导致一些缓冲区溢出,每次我搜索解决方案都是启用 rts/cts 流控制,我不知道如何使用它??如果我设置这些会发生什么,那么 pyserial 会做什么以及如何控制我的写入?它真的令人困惑..
硬件流控制,我不确定它是否可以工作,因为我刚刚将 rx tx 接地和电源连接到我的树莓派,即使尝试将其他流控制引脚连接到 pi,我也不确定它是否有效或受 3dr 支持无线电遥测..我相信软件流控制现在将是一个很好且简单的解决方案。
这是我的代码..
for channel in list(self.__channelDict.values()):
# Addition for channel priority later
# We check if the channels in the list is active
if channel.getChannelActive() is True:
# Check if we have reached the max count
if (messageCount >= (self.__NoOfMessagesInUARTStream - 1)) or UARTForceSend:
self.sendUARTStream(UARTCacheBuffer, messageCount, UARTStreamCRC)
# Reset
messageCount = 0
UARTStreamCRC = 0
UARTCacheBuffer.emptyBuffer()
message = channel.RetriveMessage(queueType = 1, raw = True)
# # there is no TX message in this channel
if message is None:
continue # continue with next channel
else:
UARTStreamCRC = binascii.crc32(message, UARTStreamCRC)
UARTCacheBuffer.append(message, raw = True)
messageCount +=1
以及写入串口的功能
def sendUARTStream(self, UARTCacheBuffer, messageCount, UARTStreamCRC):
# retrieve all the data from the buffer and create a stream packet
UARTFrame = None # Used to forward the data
UARTStreamHeader = None
# Create the message header
if messageCount == 0:
# looks like all channels are empty
return 0
else:
messageArray = UARTCacheBuffer.getBuffer()
print(messageArray)
print('messageCount = ' + str(messageCount) + 'crc = ' + str(UARTStreamCRC))
UARTFrame[:self.__UARTStreamHeaderFormat.size] = self.createHeader(messageCount, UARTStreamCRC)
UARTFrame[self.__UARTStreamHeaderFormat.size : self.__UARTStreamHeaderFormat.size + self.__messageFormat * messageCount] = messageArray
# Its time to finally send the data
print('UARTFrame = ##' + str(UARTFrame))
self.__txPort.write(UARTFrame)
return messageCount