Print character by ASCII code

10 years 8 months ago #29528385 by sd1074
As part of my research project, I want to implement my own controller algorithm which is too heavy to run on the motor controller. So I can run it on an external machine, but then the external machine has to receive current sensor values and output new motor power command every T ms. In this case the communication between the motor controller and the external machine becomes the main bottleneck of the system. I calculated that if I compress the numeric values into something similar to base64, I can reduce the communication overhead almost by a factor of 2.

The problem now, however, is that it seems like there is no way to print a character by its ASCII code. In fact, Could not find a way to print a character different from '0'..'9' unless its value is hardcoded in the script(as a string).

I looked into the compiled code. It seems like there are two internal calls: PRINTSTRING and PRINTVAL. The first one prints bytes as they are hardcoded in the script, and the second one, I assume, converts the number into an ASCII byte sequence and then prints them. This makes me hope that there is an internal function which would print a character just by its ASCII code.

So my question: is there any way/workaround to send a character to the serial port by its ASCII code. That is something like this:
which should output:

At this point, the only solution to implement a base64-like encoding I can find is a multilevel nested IF with print("X") in each leaf.


Please Log in or Create an account to join the conversation.

10 years 8 months ago #29528387 by Griffin Baker
Replied by Griffin Baker on topic Print character by ASCII code
Maybe give this a shot.

Hexadecimal Escape Sequence

Hexadecimal escape sequence is represented in a set of hexadecimal digits (0-9, A-F) preceded by \x in the string (such as \x10 for character with ASCII 16).

Since a hexadecimal escape sequence can have a variable number of hex digits, the string literal "\x123" contains a single character with hex value 123. To create a string containing the character with hex value 12 followed by the character 3, one could write "\x00123".

Please Log in or Create an account to join the conversation.

Time to create page: 0.057 seconds