S7-1500 combining and converting characters

adfox

Member
Join Date
Jun 2006
Location
Poland
Posts
334
Hi, I have a functions which extends codes generation for RFID tags.
Basically it takes a char and splits it's hex value over 2 chars.

MXg0a1t.png


I cannot modify it and change it, my task is to reverse this, as I want to write my own string. So I have to reverse this behavior and create a char from 2 values. It works... up to some point.

3EN0PKs.png



As You can see if second character contains 'a' - I've got a $0 in my output character - How can I get rid of this (The letter 'z' and 'Z') ?

qmgovOm.png


I've already tried HTA, but it doesnt work for me as it Outputs hex value as string.

Screens are here: https://imgur.com/a/HN0d8Ko
 
Last edited:
The STRG_VAL function is reading the string as a decimal number: it reads the '7', which is a decimal digit, but stops when it reads the 'a', which is not a decimal digit, and the end result is that it reads '7' as 7. Does STRG_VAL have an option, maybe in the FORMAT argument, to treat the characters in the string as hexadecimal digits? Or would prepending a prefix of '16#' to the two-character string make STRG_VAL, so the string is '16#7a', make it work as desired?

If not, write a function H2I, that takes hexadecimal characters, '0' to '9' and 'a' to 'f' or 'A' to 'F', and returns a value from 0 to 15, then the expression
#ch := WORD_TO_BYTE( (16 * H2I(#ch1)) + H2I(#ch2) )
Should provide the correct answer. How to handle non-hexadecimal characters in ch1 or ch2 is left as an exercise for the user.
 
Last edited:
But to understand what You did L D[AR2,P#0.0] - I need an afternoon in ventilated room.
Thank You drbitboy and L D[AR2,P#0.0] You saved my boiling head over this.
 
I am curious.
Which application is it that needs that you combine 2 ascii chars into a hexadecimal number value to find the character in the ascii table that has the position of the hex value ?
Whatever source this comes from, why not just send the ascii character in the first place ?
 
Hey JesperMP, just to explain, the RFDID chip which customer is using holds 5 bytes of data.
The ID system they use above is using 10 chars strings.
So to convert it, they use the method above to explode those 5 bytes into 10.
The problem arised when I had to feed their system with my tags.
That's why I needed to pack the bytes back and put them on RFID.
 
I don't know what @LD did, but it appears that TIA has a function for this already; see the second rung:
hex_to_char_00.png
But if you want to do it yourself, here is FC behind the first rung:
hex_to_char_01.png
 
Hi again, finally i was able to test provided solution with partner system connected and i'm completly confused.

No matter which solution provided by You guys I select - the result gets destroyed after letter G. The result is here:

XVDDWCq.png


I was able to get the STL source from partner which is converting back the bytes into chars. But my STL skills are to low to comprehend this.

I don't know if I can post it here but, i've hit a total dead end. Could You please kick me in the right direction ?

Code:
Edit : Ok thank You for help, 0-9 and A-F is more than enough for me ;)
Thank You again.
 
Last edited:
No matter which solution provided by You guys I select - the result gets destroyed after letter G.
...
Code:
Edit : ...0-9 and A-F is more than enough for me

FYI: the characters 'g' and beyond are not hexadecimal characters, which is why it fails.

So if the incoming exploder, that converts the RFID string from 5 byte characters to 10 hexadecimal digit characters, is working correctly, then it should only supply the characters 0-9, a-f and/or A-F, which seems to be the case.
 
Yep I came to that conclusion, each char is actually a nibble (4 bits) so that is 0-F 0000 - 1111 any above this is 8 bits.
 
If the tags are only 5 bytes then to get 10 chars they can only be 0-F so if I read this right the OP is trying to convert 0-9 and A-Z this cannot be converted into the 5 bytes in Hex as there is no Hex"G" or above there would have to be 7 or 8 bit ASCII so 10 words would be required.
 
If the tags are only 5 bytes then to get 10 chars they can only be 0-F so if I read this right the OP is trying to convert 0-9 and A-Z this cannot be converted into the 5 bytes in Hex as there is no Hex"G" or above there would have to be 7 or 8 bit ASCII so 10 words would be required.
You are describing HEX value converted to a STRING.
;)
 
I forgot about his first post.
What exactly does he want to do perhaps some ideas of what the strings will look like, what is this to be used for i.e. comparison of a RFID read or what.
for example the RFID read is 5 bytes in ascii this is converted to the Ascii representation of the hex values i.e. aAZ1G (note cannot see the last byte so put "G") into "6141533171"
So does he want something like "Qs45G" converting into "5173343571"
or does he want "5173343571" converting into "Qs45G"
It seems on the surface that the RFID code is a 10 digit 0-9 code but reduced to 5 byte code but this is not clear, the screen shots show a monitor screen where he is trying to convert the letters "G" onwards into hex code but in ascii i.e. "7","1" given this then is his code conversion really 5 bytes or 10
for example "Qs45G" converted into the ascii representation of the hex codes is 10 so this is not reduced to 5 bytes. What is this Ascii string that will be put in via some form of HMI is it the real ascii chars or the ascii representation of the hex values. I'm definitely getting confused.
 

Similar Topics

I have been working on this for a while now and I can't seem to get it. I was finally able to view the 1500 on the PanelView under the serial...
Replies
1
Views
25
Hello, I have a 1764 1500 LSP Series A that keeps failing with DTL_E_FAIL I/O error. Searching around it seems there's a weird issue specifically...
Replies
2
Views
98
Hi all Trying to remotely connect to a TIA Portal PLC. I can ping it without a problem but can't get my software to connect. I've opened port...
Replies
8
Views
317
Been fighting all morning with a stubborn HMI. It just won´t connect with the plc. attaching from settings. Have i missed anything? Both plc and...
Replies
5
Views
282
Hi there, Maybe I am overthinking this issue, but here is what I have going on. I have a program running for a water valve on a DI system. We...
Replies
4
Views
443
Back
Top Bottom