HEX to ASCII conversion in a Click PLC

graygnads

Member
Join Date
Sep 2016
Location
Victoria
Posts
4
Hi,
I am using a Click PLC for MODBUS communication with a range of gas sensors - everything is going reasonably well in that I can read / write registers with no issues until it comes to reading serial number information from the sensor.
The first character is supposed to be read as an ASCII character - I read 0054h from the register which should equate to 'T' - all good until I copy this to a text memory address where the click returns '8' (the text viewer tells me this address has a hex value of 38 stored).
Is someone able to tell me where I'm going wrong? i.e why does 54h, copied to a text location, return a '8' and not 'T'?
Any help would be greatly appreciated.
 
54 in HEX = 84 in Decimal and 84 in Decimal = T in ASCII

"h" is not a valid character in HEX. I am not a click user but I think you could try HEX to Decimal then Decimal to Text to see if you get a different result.
 
Thanks for your reply but, the 'h' just designates it as being Hex; the value I have in the Click Hex memory location "DH" is 54. I have tried converting to decimal, and get the result of 84 but when I copy this value to a TXT location I also get a return of '8'.
I don not get any 'out of range' error flags either.
 
It sounds like some mystery conversion taking place. Is it possible to program a text-to-integer copy to see what comes out? If this would work you may be able to suss out converting in the desired direction.
 
You may need to swap the bytes to get the correct value. I have had that type of error before where I had to swap the bytes to get the correct value. 2nd byte 1st and 1st byte 2nd. Here is comment I entered in to my program to explain the byte sway.
When Camera Results Acknowledged Then Divide Serial Number into Single Digits And Swap Bytes.
BarCode.DATA Is SINT(small Integer = 8 bits) Anybus Data is an INT(Integer = 16 bits)
Therefore We Use The Bit Field Distribute Instruction To Copy SINT Bits Into INT Bits. We Swap By Sending Bit Pattern From First Digit To The Second 8 Bits of The Integer And the Second 8 Bits To The First 8 Bits Of the Integer.
This Is Repeated For All Digits Of The Bar Code Data
 
54 Hex = 84 Dec = 'T' ASCII = 01010100 Binary
In the Click software you can look at the help menu and search for ASCII. It will call up several relevant articles depending on what you want to do.

I would copy the registers to the TXT registers and then use Text View in the software to read the values.

Hope this helps you out.
Regards,
 
What the CLICK is doing is EXPLICITLY copying EACH CHARACTER of the VALUE (54H / 84D) to a single character in the TXT datatable.
If you copy 54H to TXT1, then you should have 5 in TXT1 and 4 in TXT2.
If you copy 84D to TXT11, then you should have 8 in TXT11 and 4 in TXT12.

also posted in the AD forum in case you don't find this here.
 
Thanks Kwade - testing shows me that this is exactly what's going on.
Looks like I can't read a MODBUS register and convert to text, though I can change it in the text viewer.

Thanks to those that replied.
Cheers
 
All is not lost. If you need to convert, you can apply the ugly workaround hinted at in the AD forum.
 

Similar Topics

Hi All, have a quick one new enough to this type of programming, I am using a Allen Bradley point IO with 1734-232ASC card to send out data, I...
Replies
5
Views
2,599
Hi there, How to do HEX conversion to ASCII in Rockwell software? In Siemens there is HTA instruction. Any advice's? I have RFID scanner I...
Replies
2
Views
2,199
Hi, Guys I'm trying to upgrade a device witch comms is thru a RS232. The PLC is a Compactlogix L16ER to a remote PIO 1734-AENT then on this PIO a...
Replies
22
Views
8,241
Hey, i've been working on getting some add-on instructions defaulted in the company i work in. i am currently trying to create a string which...
Replies
7
Views
3,054
Hello everyone, I'm working in RSLogix 5000. I have an ASCII string of letters & numbers (call it String_3) which I have used INSERT to add a...
Replies
3
Views
2,322
Back
Top Bottom