CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Fri Dec 06, 2019 11:48 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Tue Apr 30, 2019 10:25 am 
Offline

Joined: Wed Jul 11, 2018 10:44 am
Posts: 24
Hello,

I have 157 2 byte arrays and i want to convert those to uint values and then save all of them to one array.

I have (those are measured values presenting distances when converted).
aValue1 : ARRAY [0..1] OF BYTE := [07,DE];
.
.
aValue157 : ARRAY[0..1] OF BYTE := [00, 8F];

I want:
aValues : ARRAY [0..156] OF UINT :=[2014,...143];

has anyone any idea? i converted aValue1 to HEXSTRING because i though i can use HEXCHRNIBBLE_TO_BYTE, but this function is only for string(1) and i have after conversion '07 DE'.


Top
   
PostPosted: Tue Apr 30, 2019 5:37 pm 
Offline
Frequent User
Frequent User

Joined: Tue Dec 03, 2013 11:52 pm
Posts: 125
How about using a UNION?

Example:
Code:
TYPE COMBINEDBYTES
UNION
    abyValue : ARRAY[0..156,0..1] OF BYTE;
    auiValue : ARRAY[0..156] OF UINT;
END_UNION
END_TYPE

PROGRAM PLC_PRG
VAR
    union_CombinedValues : COMBINEDBYTES;
END_VAR

union_CombinedValues[0,0] := 16#DE; //Assign value of 222 to union member
union_CombinedValues[0,1] := 16#07; //Assign value of 7 to union member
//Result (auiValue[0] = 2014);

union_CombinedValues[1,0] := 16#DF; //Assign value of 223 to union member
union_CombinedValues[1,1] := 16#07; //Assign value of 7 to union member
//Result (auiValue[1] = 2015);


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 2 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited