pragma bitaccess ...

wollvieh
2016-01-03
2016-01-08
  • wollvieh

    wollvieh - 2016-01-03

    is the pragma bitaccess no more available in CODESYS3 ?
    It was for me very usefull in V2, but i didn't find it ?

     
  • Anonymous - 2016-01-07

    Originally created by: scott_cunningham

    You can bit access variables by default:

    PROGRAM PLC_PRG
    VAR
       Test   : BYTE;
    END_VAR
    IF Test.0 THEN
       Test.1 := NOT(Test.1);
    END_IF
    Test.0 := NOT(Test.0);
    

    There is also the BIT data type replaces it. It's not allowed in arrays, references or pointers, but allowed for structures. It should work for you. The help warns that BIT data access is slower than BOOL access, so only use it when you really want to (as opposed to C programmers that love to bit-code variables...).

    From the Help:

    Zitat:
    Bit access in structures
    The datatype BIT is a special datatype which can only be defined in structures. It consumes memory space of one bit and allows to address single bits of a structure by name.

    TYPE <structurename>:
    STRUCT
        <bitname bit1> : BIT;
        <bitname bit2> : BIT;
        <bitname bit3> : BIT;
        ...
        <bitname bitn> : BIT;
    END_STRUCT
    END_TYPE
    
     
  • wollvieh

    wollvieh - 2016-01-08

    Thank's Scott,

    i now that.
    But with the pragma bitaccess it was much more convinent.

    Example :
    without the pragma :
    Controlword.0
    Controlword.1

    with pragma
    Controlword.enableConverter
    Controlword.driveEnable

    both methods access the same bit, but for me it makes sense (because it is much better to understand),
    to use the method with the pragme bitacces.

    ... and i have some function blocs from CoDeSys2.x, which i'd like to use in CODESYS3.

    Anyway, thank you for your answer, the People in Kempten didn't.
    Winner find's a way, looser find's a reason.

    So, it seems, we are now able to have OOP for PLC, but we lost some nice features.

    Walk unafraid.

     
  • Anonymous - 2016-01-08

    Originally created by: scott_cunningham

    Ah, yes, I know these control words (I have products that use them) and never liked using the bit #s - because it's nice to see "enable" or "reset" like you are looking for.

    What you could do is create a FB with properties called enableConverter, driveEnable, etc. Have the FB have an output called BitCode. And then instead of defining a variable called ControlWord : INT, you would use ControlWord : FbControlWord. Then map "ControlWord.BitCode" to your drive... (this is how I do it because then I can have a drive object contain a control word object...)

    Then your existing code still works:
    Controlword.enableConverter := TRUE;
    Controlword.driveEnable := FALSE;

    It is a couple more steps for you, but at least you can reuse all of your code without much editing (only the VAR declaration and a mapping).

     

Log in to post a comment.