pmundt
pmundt

Reputation: 137

How to send a char array over serial which includes a NULL char?

I am using WiringPi-Python to send data over serial and trying to send a char array. My problem is; I cannot send the data if the array includes a 0 (NULL char).

bytes = [112, 52, 0, 18]
send = "".join(map(chr, bytes))
wiringpi.serialPuts(serial, send)

How can I pass a NULL contained char array to serialPuts?

Upvotes: 0

Views: 652

Answers (1)

Thomas Weller
Thomas Weller

Reputation: 59410

IMHO the problem is in bindings.i of the library:

serialPuts() is defined as

extern void serialPuts (const int fd, const char *s) ;

and in C, strings (char*) are terminated by the \0 character. I consider that a bug of the library. It should be

extern void serialPuts (const int fd, const char *s, int strlen) ;

Try wiringpi.serialPutchar() in a loop.

Upvotes: 2

Related Questions