Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Bits zählen über Modbus TCP

CodesysAm
2019-01-24
2019-04-15
  • CodesysAm - 2019-01-24

    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

     
  • Anonymous - 2019-01-25

    Originally created by: scott_cunningham

    Bit access by a variable is not supported. Try this instead:

    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!

     
  • dFx

    dFx - 2019-01-30

    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 :

     
  • Anonymous - 2019-01-31

    Originally created by: scott_cunningham

    @ dFx - I don't see how your code can compile/work.

    BIT can only be used in structure, not array:

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

    IMG: array

    IMG: bit

     
  • dFx

    dFx - 2019-02-01

    mybad.

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

     
  • CodesysAm - 2019-04-15

    Dear scott_cunningham,

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

    Thank you very much.

     

Log in to post a comment.