Thanks, but what do you think about other conversion. I would like to change byte array :0x44, 0x44, 0x46, 0xFF, 0xFF
on string value :
'444446FFFF' ? How do this ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Please help me how create the function to convert STRING variable e.g:
'AFDA0909090909'
to byte array:
0xAF, 0xDA, 0x09, 0x09, 0x09, 0x09, 0x09
?
more posts ...
My temporary solution:
And function call:
byteMy:=ASCIIstring_TO_BYTE('A','F');
I need more profesional solution. :)
Last edit: damian177 2021-12-26
It seems your solution is KISS, it is readable, understandable and it works. Problem solved if you ask me π₯β¨πππͺ Happy Christmas βπ
I just knew people weren't going to let this go by :-)
The for loop solution js offcourse more elegant and shorter. Anyway Happy New Year!
Did you had a look at OSCATT lib ? HEX_TO_BYTE seems to apply.
Also there is WORD_AS_STRING in utils, but you need the exact opposite.
Last edit: dFx 2021-12-27
... This examle works:
byteMy:=ASCIIstring_TO_BYTE('A','F');
But in this example is problem:
The error is:
Cannot convert type 'BYTE' to type 'STRING(1)' ...
Function STRING_TO_BYTE not resolved problem. How do I pass one character from STRING to a function?
Last edit: damian177 2021-12-27
actually, looping from 0 to 10 is 11 loops on a string of 10 chars.
then if you want to get a byte value, don't concatenate 2 chars into a word. just take lower byte once at a time.
So how do I pass a single character from string to my function named: ASCIIstring_TO_BYTE?
So, maybe have you idea how convert this 1D Array :
ASCIIarray : STRING(255) := 'AFDFAFFFFF';
to 2D ARRAY:
ASCIIarray2 : ARRAY[0..0, 0..4] OF STRING := ['AF', 'DF', 'AF', 'FF', 'FF'];
?
OR
HEXinASCII_TO_BYTE is part of Util lib.
Sometimes things are easier than it first look.
Last edit: dFx 2021-12-29
Thanks, but what do you think about other conversion. I would like to change byte array :0x44, 0x44, 0x46, 0xFF, 0xFF
on string value :
'444446FFFF' ? How do this ?
Same lib. Please read a little the help.
Note for future me : do not spam the post button.
Last edit: dFx 2021-12-29