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 Jul 23, 2019 3:46 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Jan 24, 2019 5:17 pm 
Offline

Joined: Fri Dec 14, 2018 1:28 pm
Posts: 6
Guten Abend liebe Community,

ich hab ein klein großes Problem. Es geht darum ,dass ich über Codesys eine Tabelle erstellen muss.
Die Kommunikation läuft über MODBUS TCP und ich müsste die channel so wie bei bits hochzählen und auf TRUE abfragen. Aber es kommt immer der Fehler: 'Bitzugriff benötigt ein Literal oder eine symbolische ganzzahlige Konstante'.
Mein Programmteil sieht im moment so aus:
FOR i:= 0 TO 99 BY 1 DO
FOR j:= 0 TO 15 BY 1 DO
IN_DIAG_ID[i].j;
IF IN_DIAG_ID[i].j = TRUE AND safety_repeat[i,j] = 0 THEN
safety_repeat[i,j] := 1;
EXIT;
END_IF
END_FOR
END_FOR
über Hilfe wäre ich sehr dankbar.

Schönen Abend noch

MfG


Top
   
PostPosted: Fri Jan 25, 2019 5:42 am 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 304
Bit access by a variable is not supported. Try this instead:

Code:
FOR i:= 0 TO 99 BY 1 DO
   Temp := IN_DIAG_ID[i];
   FOR j:= 0 TO 15 BY 1 DO
      IF Temp.0 = TRUE AND safety_repeat[i,j] = 0 THEN
         safety_repeat[i,j] := 1;
         EXIT;
      END_IF
      Temp:= SHR(Temp,1);
   END_FOR
END_FOR


Not tested - I answered while traveling!

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


Top
   
PostPosted: Wed Jan 30, 2019 4:32 pm 
Offline
Frequent User
Frequent User

Joined: Fri Feb 23, 2018 3:41 pm
Posts: 144
Following is wrong

You could either use a UNION datatype, using a word and an array of bits (not bool).
This way you could achieve your nice indexed loop.

So, assuming IN_DIAG_ID is an array of your union :
Code:
FOR i:= 0 TO 99 BY 1 DO
  FOR j:= 0 TO 15 BY 1 DO
    IF IN_DIAG_ID[i].BitArray[j] = TRUE AND safety_repeat[i,j] = 0 THEN
      safety_repeat[i,j] := 1;
      EXIT;
    END_IF
  END_FOR
END_FOR


Last edited by dFx on Fri Feb 01, 2019 8:30 am, edited 1 time in total.

Top
   
PostPosted: Thu Jan 31, 2019 1:14 pm 
Offline
Frequent User
Frequent User

Joined: Fri Sep 02, 2011 8:02 pm
Posts: 304
@ dFx - I don't see how your code can compile/work.

BIT can only be used in structure, not array:

Attachment:
array-no-bit.png


At least through CoDeSys 3.5.12, help states BIT datatype can only be used with STRUCTUREs.

Attachment:
bit-struct-only.png


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

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


Top
   
PostPosted: Fri Feb 01, 2019 8:30 am 
Offline
Frequent User
Frequent User

Joined: Fri Feb 23, 2018 3:41 pm
Posts: 144
mybad.

I beg your slice is the best solution as of now.


Top
   
PostPosted: Mon Apr 15, 2019 11:40 am 
Offline

Joined: Fri Dec 14, 2018 1:28 pm
Posts: 6
Dear scott_cunningham,

first iam very sorry for the wrong post in the wrong forum.
Your solution works well ! :D

Thank you very much.


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 1 guest


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