Need some assistance in formatting a string that I am getting from another device over OTG serial connection.
String: eGUtilities:eEeG Park ScopeeE
Hex Code:
1B4701015574696C69746965733A1B450102205061726B2053636F7065
ASCII
ESC G SOH SOH Utilities: ESC E SOH STX Park Scope ESC E
I would like to display it as:
Utilities:
Park Scope
Remote Device will always sends a two line answer to a command.
First line will always start with: ESC G SOH SOH
First line ends with: ESC E
Second Line start with: SOH STX
Second line ends with: ESC E
I send a command from App, remote device responds with one string, similar to the one in original request.
I would like to remove the special characters and format it into two lines as noted.
I do not have format control over remote device. I just connect to it over rs232 and send commands and it responds.
So the principle is to split the data string into hex pairs (each hex pair = 1 Ascii), then look-up each hex pair in a List to convert. It would be prettier to use a Dictionary but it would just take too long to make it
Thank you for you code, I did learn a lot from it. The string I'm getting is in ASCII, with the special characters that do not get rendered correctly thus I had to convert the string to Hex to know what those characters were using Realterm connected to the remote device.
What would the approach be dealing with the Ascii string.
At the moment, we are between a rock and a hard place because App Inventor cannot handle the non-printing characters (SOH, STX etc) - in fact, if you put them in a text block, next time around the Project will not load properly.
MIT Have a potential fix for this, it was reported back in November. I can't say for sure that it will be ready for the next release, or indeed when that release is due. The problem affects App Inventor offspring too, such as Kodular.
Is it possible to convert the String to Hex via Realterm and send the Hex to the App? Something like that would be the best work-around for now.
If this trick of the Web component works in this part of the ASCII table,
you should be able to generate low end strings at run time without threat to project structures
and without the need for extensions.
P.S. These blocks can be dragged directly into your Blocks Editor workspace.
I noticed that when I am in emulator mode the following code works in emulator mode but the project fails to build.
If you notice the AS2 String (red box) is rendering correctly....
Thanks for the test report.
These ASCII codes are hard to test without a data stream, and the web trick is very finicky, depending on the choice of codes.