Page 1 of 2
chr(0) is a string
Posted:
Thu May 19, 2016 5:54 pm
by jlbachiochi
I'm building a string to send out the serial port, my solar controller will respond with a similar string. When I try to add chr(0) to a string it is ignored, however characters after it are added correctly. I suspect this might have to do with some stings being zero terminated. I changed to an array to proceed, but this seems unnecessary.
Also is there a way to enter values as HEX for instance 0x3000 instead of 12288?
Re: chr(0) is a string
Posted:
Fri May 20, 2016 4:27 am
by cicciocb
Internally the ESP Basic, the Strings are handled as C++ strings, so '\0' is ignored or considered as end of string.
To enter hex values you can use the function hextoint()
ex:
print hextoint("3000")
Re: chr(0) is a string
Posted:
Sat May 28, 2016 11:33 am
by jlbachiochi
OK, so instead of using a string to hold binary data I used an array. When the array is output using "serial2print chr(array(x))", any '0' is not output. ?!?
Re: chr(0) is a string
Posted:
Sat May 28, 2016 12:13 pm
by cicciocb
Yes I think this is an actual limitation due to the way the strings are internally handled.
This is inherited from the arduino Wstring library .
Probably a patch of the lib is required.