CODESYS - the IEC 61131-3 automation software
https://forum.codesys.com/

Bits zählen über Modbus TCP
https://forum.codesys.com/viewtopic.php?f=11&t=9470
Page 1 of 1

Author:  CodesysAm [ Thu Jan 24, 2019 5:17 pm ]
Post subject:  Bits zählen über Modbus TCP

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

Author:  scott_cunningham [ Fri Jan 25, 2019 5:42 am ]
Post subject:  Re: Bits zählen über Modbus TCP

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!

Author:  dFx [ Wed Jan 30, 2019 4:32 pm ]
Post subject:  Re: Bits zählen über Modbus TCP

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

Author:  scott_cunningham [ Thu Jan 31, 2019 1:14 pm ]
Post subject:  Re: Bits zählen über Modbus TCP

@ 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

Author:  dFx [ Fri Feb 01, 2019 8:30 am ]
Post subject:  Re: Bits zählen über Modbus TCP

mybad.

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

Author:  CodesysAm [ Mon Apr 15, 2019 11:40 am ]
Post subject:  Re: Bits zählen über Modbus TCP

Dear scott_cunningham,

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

Thank you very much.

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/