Home/Support/Support Forum/micropython machine uart.write() limit
New and improved user forum site coming soon

micropython machine uart.write() limit

0 votes
I am using a Xbee3 LTE-m Module with micropython scripts. I am running into a strange issue where I can only send 255 bytes of a 348 byte string through the secondary UART. I have verified with a logic analyzer that only 255 leave the module. I can print the string, and I can also print two halves separately. I also verified that I still have enough RAM available. I am stumped!! Here is an example of what doesn't work:


Example string:
TestString = '{"a":"1234563400417E2B63",
"b":"0100FCFFF10000008403010001111100",
"c":"0100020001000200000020C1000020410000C8C20000C8420000
0100020001000200000020C1000020410000C8C20000C842000001000
20001000200000020C1000020410000C8C20000C84200000100020001
000200000020C1000020410000C8C20000C84200FF010002000100020
0000020C1000020410000C8C20000C8420000",
"d": "2C012C01"}'


Test Code:
self.secUart = UART(1, 115200)
self.secUart.init(115200, bits=8, parity=None, stop=1, timeout=1, timeout_char = 1)
print("TestString: ",TestString)
print(" len: ",len(TestString))
bcount = self.secUart.write(TestString)
print("bytesSent: ", bcount)
bcount = self.secUart.write(TestString)
print("bytesSent: ", bcount)


OUTPUT:

TestString: {"a":"1234563400417E2B63",
"b":"0100FCFFF10000008403010001111100",
"c":"0100020001000200000020C1000020410000C8C20000C8420000
0100020001000200000020C1000020410000C8C20000C842000001000
20001000200000020C1000020410000C8C20000C84200000100020001
000200000020C1000020410000C8C20000C84200FF010002000100020
0000020C1000020410000C8C20000C8420000",
"d": "2C012C01"}
len: 348
bytesSent: 255
bytesSent: 0
asked Sep 28 in MicroPython by ajsPillar New to the Community (7 points)

Please log in or register to answer this question.

1 Answer

+1 vote
I found a work around, its not great, but works for what i need:

def psuedoFlush(self, bytes):
delayms = int((bytes * 10000)/self.baud) + 1
utime.sleep_ms(delayms)

def testPrint(self):
datalen = len(TestString)
bcount = 0

if datalen > 255:
bcount += self.secUart.write(TestString[:250])
self.psuedoFlush(bcount)
bcount += self.secUart.write(TestString[250:])
else:
bcount = self.secUart.write(TestString)


PS: for some reason the forum post keeps killing my tabs/spaces
answered Sep 29 by ajsPillar New to the Community (7 points)
...