RSLogix - DEC value to HEX string

JohanM

Member
Join Date
Sep 2015
Location
Terchová
Posts
53
Hi guys.

Sorry if I am asking for something solved, but I cant find any useful and easy information for me. I am looking for some solution how to convert decimal value in byte to hexadecimal representation in string in RSLogix..o_O I need it for FactoryTalk visualization, because I am not able to find how to show decimal value as hex... Do yo know some sample? or something?.. A lot of thanks..:geek:
 
Since you didn't specify which RSLogix I'll answer in a general form.

Extract each of the two 4 bit nibbles from the byte into the low bits its own byte.

For each byte add 48 (30 hex) to the value
If the result is greater than 57 (39 hex) then add 7 more to the value
The result is the ASCII representation (0-9 A-F) of each nibble.
 
Code:
myUSINT = 5AH;

String.LEN := 2;
tempUSINT := ((myUSINT & F0H) / 8);
IF tempUSINT > 9 THEN
  String.Data[0] := tempUSINT + 55;
ELSE
  String.Data[0] := tempUSINT + 48;
End_IF;
tempUSINT := (myUSINT & 0FH);
IF tempUSINT > 9 THEN
  String.Data[1] := tempUSINT + 55;
ELSE
  String.Data[1] := tempUSINT + 48;
End_IF;
 
Dynamically sized AOI

I made an AOI based on AustralIan's code
AOI export is attached.

Create a SINT array sized to fit (if you want to create a generic array and specify lenght, you need to modify the AOI)
Copy data to SINT array (remember COP length is destination element size, so a DINT to SINT copy is x4 the length of the DINT array)
COP HMI_PLCVersion_LINT HMI_PLCVersion_SINT[0] 8 DTOS_Hex DTOS_Hex HMI_PLCVersion_SINT HMI_PLCVersion



Parameters:
Code:
Byte    InOut    SINT[1]
HexString    InOut    STRING
Structured Text Logic:
Code:
//Determine the size of the passed in array
size(Byte,0,Byte_Size);

HexString.LEN := Byte_Size*2;
for i := 0 to (Byte_Size - 1) do
    TempDINT := ((Byte[i] & 16#F0) / 8);
    IF TempDINT > 9 THEN
      HexString.DATA[i*2] := TempDINT + 55;
    ELSE
      HexString.DATA[i*2] := TempDINT + 48;
    End_IF;
    TempDINT := (Byte[i] & 16#0F);
    IF TempDINT > 9 THEN
      HexString.DATA[i*2 + 1] := TempDINT + 55;
    ELSE
      HexString.DATA[i*2 + 1] := TempDINT + 48;
    End_IF;
end_for;
 
Last edited:
I'm attempting to use your AOI but I'm sure I'm doing something wrong. I'm new to RSLogix and have not learned the verbiage just yet. I'm getting error messages and I know I have to fill the functions with something but not sure what.

capture.PNG
 
You need to create and instance of the AIO to use in the AOI calls.
Stick a tag name in the DTOS_Hex field and create a tag of the type DTOS_Hex.
You can use the same instance for both calls because they have no state.
 

Similar Topics

Good morning, Still new-ish to Allen Bradley and hoping some of you seasoned folks out there could help me. I am setting up communication with...
Replies
5
Views
2,773
Hi Everyone, I am not proficient in RSLogix 500 so I have a question regarding the evaluation of N7:0 data as an input. So as I understand in...
Replies
1
Views
81
Hi folks, in the alarm manager of Rslogix 5000, the tag-based alarm has been created. But when I tried to change the condition, it was found the...
Replies
2
Views
151
I have a little bit of experience with Allen-Bradley. I have a Micrologix 1500 (RSLogix 500) and a PanelView Plus 7 (FactoryTalk View Studio ME)...
Replies
3
Views
161
Back
Top Bottom