0

I need help is using serial port, I have 3DR radio telemetry connected to my python and other side to my windows PC ,I have small python code which continiously writes the data to serial port and reads , reading might not be an issue, or it might be later anyway...

The issue is i am afraid the too many writes might cause some buffer overflow, every time i search the solution is to enable rts/cts flow control, I dont know how to use it ?? what will happen if i set these then pyserial will do what and how can i control my write ?? its really confusing ..

hardware flow ccontol, I am not sure it might work, becuase I have just connected rx tx ground and power to my raspberry pi, even if try to connect the other flow control pins to pi, i am not sure it works or supported by 3dr radio telemetry.. I believe software flow control will be good and simple solution for now.

here is my code ..

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

and the function to write to serial port

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
harsha
  • 61
  • 7
  • Hey... I found the problem, it was not the receiver in error, but some how the ascii \x11 and \x13 were not getting transmitted in serial port, here is my test results. Send::array('c', '\xff\x10\x14\x13w\xd8\xa6\x00R1g/aYu+R1k+grJ9') recv::array('c', '\xff\x10\x14 w\xd8\xa6\x00R1g/aYu+R1k+grJ9\xff') – harsha Feb 17 '14 at 21:04
  • I still dont know how to correct it .. any solutions ?? – harsha Feb 17 '14 at 21:29

0 Answers0