Writing raw bytes to stdio
threadz
Posts: 56
Is there a way to write raw bytes to the UART port on the propellers pins 30 and 31 without having any characters escaped?
Whenever I try to write the value 10 using any of these:
it gets escaped to the two character sequence 0x0b 0x0a.
I believe these are the \n and \r characters, which would constitute a standard line break for windows systems, so I understand why this escaping would be helpful in some instances. Is there a way to turn this off or otherwise work around this problem? Preferably without involving another cog or any spin code.
Thanks in advance
EDIT: writing to different pins would also work
Whenever I try to write the value 10 using any of these:
printf("%c", (char) val);
putchar(val);
char output[2]; output[0] = val; puts(output);
it gets escaped to the two character sequence 0x0b 0x0a.
I believe these are the \n and \r characters, which would constitute a standard line break for windows systems, so I understand why this escaping would be helpful in some instances. Is there a way to turn this off or otherwise work around this problem? Preferably without involving another cog or any spin code.
Thanks in advance
EDIT: writing to different pins would also work
Comments
This reply is incorrect. See PropGCC's raw/cooked modes as mentioned in posts 4 and 5 of this thread.
Not with the Parallax-written utilities (that I know of). This was an insignificant pet-peeve of mine that I handled in PropWare (honestly thinking it was completely useless, and that no one would ever care about it). You can either download the source code for any existing serial device and modify it such that it doesn't replace all instances of "\n" with "\n\r" or use PropWare's UART & Printer implementations, which do not do any such magic without you knowing.
You can see on line 41 of this file how a string is concatenated with the macro "CRLF", which simply expands to "\n\r". If you don't want the "\r", simply add "\n" to the end of your string and forget about the CRLF macro.
In particular, you need to turn off "cooked" mode like this:
Yeah, I know it's ugly but it works.
Edit: Changed stdin to stdout because the original post was about writing to stdout.
I don't know if this has been implemented for the runtime library used by propeller gcc though.
Edit: David popped in with useful information about this while I was writing.
-Tor
A similar situation exists with stdin as well. Calling getchar() will not immediately return a keypress, but waits until the CR is pressed. Buffering would need to be turned off on stdin if you want to read one key at a time. And you would need to turn off the echo flag if you want to provide your own echoing.
I can imagine wanting to communicate with some external device over a raw binary untranslated serial link but would still like to have some buffering in there.