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 Wed Dec 11, 2019 1:13 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Jun 27, 2019 6:02 pm 
Offline

Joined: Wed Apr 03, 2019 4:54 pm
Posts: 2
Hello,

I want to pack two INT variable into One DINT variable. The other PLC sending DINT data to Modbus device though Modbus TCPIP which is splitting data into Two INT.

How would i do Packing of Two INT into One DINT on Codesys.

please share thoughts.


Top
   
PostPosted: Thu Jun 27, 2019 6:39 pm 
Offline
Frequent User
Frequent User

Joined: Wed May 04, 2016 6:00 pm
Posts: 283
Create an union with an array of two ints and one dint.

Write in the two ints of the union, and in the dint you will have the value.

Salut!

Sent from my Moto G (5S) Plus using Tapatalk


Top
   
PostPosted: Fri Jun 28, 2019 3:36 pm 
Offline

Joined: Wed Apr 03, 2019 4:54 pm
Posts: 2
Thank you Josep.
First of all, I didn't mentioned..I am working on IEC61311-3 platform for PLC programming. so more comfortable with LD,FBD,ST language.

The problem solved with MEM Library Block "Mem.PackWordsTODWord". the Block Expected Words as Input and DWORD as Output Result. But as Word and DWORD are Unsigned it can only take Positive numbers. what i wanted to have is to get any Integer number -2147483648..+2147483647.

i would like to mentioned i got result just putting DINT type variable as Output and giving correct result. However it shows warning as Implicit Conversion from unsigned type 'DWORD' to Signed Type 'DINT': Possible change of Sign.

However still working on TWO WORD or INT to One Real conversion.

Please share thought if any.


Top
   
PostPosted: Fri Jun 28, 2019 8:28 pm 
Offline

Joined: Thu Jul 09, 2015 9:55 pm
Posts: 35
Can also do:
Code:
{warning disable C0308}
diHighLow := iLow OR SHL(iHigh, 16);
{warning restore C0308}


Top
   
PostPosted: Sun Jun 30, 2019 4:20 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 309
Alternative to disabling a compiler warning is to specifically tell the compiler you want to do that. Use conversion DWORD_TO_DINT():

MyVar := DWORD_TO_DINT(dwVar).

No compiler warning and it is very clear to anyone looking at your code that you wish to get the signed value back.

_________________
Scott Cunningham
KEB America, Inc.
www.kebblog.com
www.kebamerica.com


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

All times are UTC+01:00


Who is online

Users browsing this forum: Andreas Kehrer and 7 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