Struct containing BOOLs

Sekhmet
2010-12-17
2010-12-29
  • Sekhmet - 2010-12-17

    Hi
    I'm quite new here so please excuse me if this sounds stupid or anything.
    I've just yesterday come across the Struct-Type for working with input-data sent from my hardware via profibus.
    The Struct-Type was once automatically added by some Script or something, not sure, it works really nice and generates me a struct with 6 bytes in it.
    So i thought, thats nice i'm gonna convert myself a WORD im beeing sent from an other device to 16 BOOL because each BOOL signals something different.
    so now i set this up like the working one but instead of the 6 byte-vars i put 16 bool vars there.
    But when i Compiled and uploaded to my CPU the Data was really weird. It looked like the CPU tried to write the whole WORD into the first BOOL (Signaled by 16#23 or something).
    My question now is: Is that some kind of Bug or did i just do something wrong?
    I don't have the exact qc here right now, its on the working-pc and i'm at home but i'll post it tomorrow.

    thanks in advance
    Sek

     
  • maauto - 2010-12-20

    As far as I know a struct of 16 bools (or an array of 16 bools) does not get addresed as a word. Instead, each bool in the structure (or array) uses up a byte (if you have "Byte addressing". At least that's how it works on my target platform.

     
  • Sekhmet - 2010-12-20

    Sounds Logical but unfortunate
    Is there any reasonable way to map a Word to a Struct 16 individual Bool-Variables besides the long way?
    I'm not very familiar with the inner logic of Variable-space association.

    thanks in advance
    Sek

     
  • shooter - 2010-12-22

    yes you can
    use pack and unpack this will make a word of a lot of bits.
    and a bool is 1 byte.

     
  • Sekhmet - 2010-12-22

    shooter hat geschrieben:
    yes you can
    use pack and unpack this will make a word of a lot of bits.
    and a bool is 1 byte.

    yeah atm i'm using pack and unpack.
    but as far as i understand it, i can't use those functions inside a struct to assign the values to specific elements of the struct.
    if that is incorrect, please explain how.

    thanks in advance
    Sek

     
  • shooter - 2010-12-29

    no you can not use functions inside structures however you can use unpack on part of a struc

    and no you can not change a bool in a byte however you can change a bit inside a byte and test on it.
    if bit5 of byte is true then bool5 is true
    if bool5 then byte = byte or bit5 bit5 is a byte with bit5 set on so (0001 0000) =32
    (make bit0 to bit7)

     

Log in to post a comment.