packing a uarray
Posted: Tue Mar 23, 2021 12:05 am
I'd like to efficiently (without memory allocation) send binary data over a uart.
This is what I came up with:
The for loop works fine, but the "more efficient (?)" 2nd option does not (neither in CPython). Is there a "clever" solution?
This is what I came up with:
Code: Select all
from array import array
from struct import pack
a = array('i', range(4))
# this works - is there a way to get rid of the loop?
# i.e. have C do the looping ...
for i in a:
print(pack('i', i))
# TypeError: can't convert array to int
print(pack('4i', a))