Ask our Experts
Didn't find what you are looking for? Ask our experts!
Launch of Consumer/Home Owner registration process! We are pleased to announce the commencement of the Consumer/Home Owner Registration Process on Community. Consumers/Home Owners may now proceed to register by clicking on Login/Register. The process is straightforward and designed to be completed in just a few steps.
This forum is addressing industrial automation design & engineering, operations, asset performance, cyber security and digital transformation for Plants & Machines.
Search in
Link copied. Please paste this link to share this article on your social media post.
Posted: 2022-09-11 01:51 PM
Hi !
I have a array of bytes that I would like to convert to a string in Control Expert. Each byte holds an ASCII code of a letter or a number. This seemingly basic operation has proven a bit more tricky than I expected. Actually, I have not found a solution I'm happy with.
On possible solution is to define a string with the same memory address as the array. However, the idea is to write a somewhat portable program unit and I would like to avoid direct memory addressing.
There have to be a correct and simple way to do this. Help would very much be appreciated !
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2022-09-12 02:31 AM
Thanks RaviNayak !
It's close enough, Not the most elegant code but it will do. For my 46 byte array bytes_recu I get.
FOR i := 1 TO 23 DO
int_recu[i] := BYTE_TO_INT(bytes_recu[i*2])+SHL(IN := BYTE_TO_INT(bytes_recu[i*2-1]), N := 8);
END_FOR;
string_recu := ASCII_TO_STRING (int_recu);
For something that should be a simple conversion it sure is a lot of operation for nothing.
Link copied. Please paste this link to share this article on your social media post.
You’ve reached the end of your document
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.