如何在pyseri中使用流控制

2024-10-01 19:26:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要的帮助是使用串行端口,我有3DR无线遥测连接到我的python,另一端连接到我的windows PC,我有小python代码,它不断地将数据写入串行端口并读取,读取可能不是问题,或者可能会在以后。。。在

问题是我担心写太多可能会造成一些缓冲区溢出,每次我搜索的解决方案都是启用rts/cts流量控制,我不知道怎么使用它??如果我设置了这些会发生什么,那么pyserial会做什么以及如何控制我的写操作??真让人困惑。。在

硬件流量控制器,我不确定它是否可以工作,因为我刚刚把rx-tx接地和电源连接到我的raspberry-pi,即使尝试将其他流量控制管脚连接到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

以及写入串口的功能

^{pr2}$

Tags: the端口inselftruemessageifis

热门问题