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 Tue Feb 19, 2019 4:16 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Fri May 25, 2018 9:43 am 
Offline

Joined: Tue Apr 10, 2018 7:53 am
Posts: 11
Hey guys,

I'm having some trouble declaring the variables in my project.
I want to be able to set/reset the bits in a word and be able to reset the whole word at once.
So far i got it working fine at %MW0, but when I try the same at any other adress it wont work.

Can somebody help me a bit?


You do not have the required permissions to view the files attached to this post.


Last edited by bisquit on Tue May 29, 2018 9:35 am, edited 1 time in total.

Top
   
PostPosted: Sat May 26, 2018 9:00 pm 
Offline
Frequent User
Frequent User

Joined: Wed May 04, 2016 6:00 pm
Posts: 263
Try:

MyMW:pointer to dword;


MyMW:=adr(mx0);

MyMW[0] is mx0
MyMW[1] is mx1
.
.
.

Setting full

MyMW[1]:=16#B1

For example

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


Top
   
PostPosted: Sun May 27, 2018 10:26 am 
Offline

Joined: Sun Jun 28, 2015 12:23 pm
Posts: 77
I think a Union of 16 BITs (not BOOL) and a WORD is a better way to achieve this.


Top
   
PostPosted: Mon May 28, 2018 10:06 am 
Offline

Joined: Tue Apr 10, 2018 7:53 am
Posts: 11
Josep M. Rams wrote:
Try:

MyMW:pointer to dword;


MyMW:=adr(mx0);

MyMW[0] is mx0
MyMW[1] is mx1
.
.
.

Setting full

MyMW[1]:=16#B1

For example

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


ph0010421 wrote:
I think a Union of 16 BITs (not BOOL) and a WORD is a better way to achieve this.


Thank you for the suggestions guys! A union seems to work quite well.


How do I add a comment to a bit in a union?

For example: bit 1 in union 1 should be called "valve 5". And bit 1 in union 2 should be named different.


Top
   
PostPosted: Mon May 28, 2018 10:59 am 
Offline

Joined: Sun Jun 28, 2015 12:23 pm
Posts: 77
Include a STRUCT in your union with the names you need. It sounds like this can replace the BITs


Top
   
PostPosted: Mon May 28, 2018 11:18 am 
Offline

Joined: Tue Apr 10, 2018 7:53 am
Posts: 11
ph0010421 wrote:
Include a STRUCT in your union with the names you need. It sounds like this can replace the BITs


When I re-use a union by declaring the same union under different name. Then the bits will have the same name, right?

Maybe my intentions aren't clear:

For my program i need my bits in groups of 16, like a word. I want to set/reset these bits individually or all at once.
I need a whole bunch of these groups. I'd like to add a comment to every individual bit in a group. (With different comments in different groups)
A fixxed adress is not necessary.

I need a fast/simple method of creating these groups

This is what I've done so far:
Code:
TYPE STR_BITS :
STRUCT
   x00 : BIT;
   x01 : BIT;
   x02 : BIT;
   x03 : BIT;
   x04 : BIT;
   x05 : BIT;
   x06 : BIT;
   x07 : BIT;
   x08 : BIT;
   x09 : BIT;
   x10 : BIT;
   x11 : BIT;
   x12 : BIT;
   x13 : BIT;
   x14 : BIT;
   x15 : BIT;
END_STRUCT
END_TYPE

Code:
TYPE UNION_BITS_WORD :
UNION
   strBits : STR_BITS;
   wWord : WORD;
END_UNION
END_TYPE

Code:
VAR
   union1 : UNION_BITS_WORD;   
   union2 : UNION_BITS_WORD;   
END_VAR


Top
   
PostPosted: Tue May 29, 2018 7:38 am 
Offline

Joined: Tue Apr 10, 2018 7:53 am
Posts: 11
I like the way how its working now with the struct and the union.
Can somebody explain how I add a comment to one specific bit in one specific word?

Something along the lines of this?
Code:
GVL.W120.Wstruct.x00 // Word 120, Bit 00, Valve 5


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 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