Pointer ARRAY BYTE to ARRAY BOOL

Paul
2008-06-05
2008-06-06
  • Paul - 2008-06-05

    Hi,

    I have

    buffer: ARRAY [1..1024] OF BYTE;
    

    and need bit access in to small part this array, I created this:

    Jednotky : POINTER TOΒ  ARRAY[1..20] OF BOOL;
    jednotkyΒ  Β : ARRAY[1..20] OF BOOL;
    pJednotky := ADR(buffer);
    Jednotky := pJednotky^;
    

    At view array jednotky :

    Jdnotka[1] : BOOL := INVALID 16#F0

    Jdnotka[2] : BOOL := INVALID 16#F3

    Jdnotka[3] : BOOL := false;

    It's number contains in buffer. But i Think that CoDeSys partitions on 20 singl bits. Way? How to repair?

     

    Related

    Talk.ru: 1
    Talk.ru: 2
    Talk.ru: 3

  • Ralph Holz - 2008-06-06

    Hi Paul,

    Thats a quite normal behavior in CoDeSys. A boolean needs a byte of memory space so your pointer points to the 20 first bytes. Whats about typing ```

    buffer[1].0

    ```? This code accesses the first bit of first index.

    regards

    Ralph

     

    Related

    Talk.ru: 1

  • Paul - 2008-06-06

    But I need access over some variable. Buffer[0].somevar is not possible.

     
  • spfeif - 2008-06-06

    What specifically are you trying to accomplish? Maybe there is a better way of doing it. Also CoDeSys is not case sensitive, it appears to me that you have the same variable defined twice.

     
  • hugo - 2008-06-06

    True you can only reference a bit by a constant not ba a variable

    a simple trick is to do the following:

    tmp := shr(INbyte, N);

    Bit := tmp.0;

    in the open source library OSCAT.LIB you can find functions like this to get a bit referenced by a variable.

    w www.oscat.de w

     

Log in to post a comment.