Skip to content

How to use BIT_TO_WORD and WORD_TO_BIT

Hello,

I am using ladder logic in PLCnext and I get error CILG0030 saying i cant use them since they are in the safety program section but I need to convert a word into its bits and some bits into a word. How can I do this without access to the BIT_TO_WORD and WORD_TO_BIT commands?

Comments

  • There are a few alternatives I can think of:

    1. Use dot notation to get partial access to ANY_BIT variables, like WORD variables.
    2. Use the GET_BIT, SET_BIT and RESET_BIT functions on individual bits in the word.
    3. If there will be a lot of these types of operations, you could write your own function to do the same thing as the Safety FBs.
  • @Martin - PLCnext Technology Team, When I use dot notation for a word that is tied to my DI16/1 in a ST program, the bit values don't change. I can see the value change from 16#0000 to 16#0100 (DI/1) in my program variables, but at the bit level in my ST it will stay FALSE.

    IF xIODI.X0 THEN

      xIODO.X0 := TRUE;

      ELSE

      xIODO.X0 := FALSE;

      END_IF;


    xIODI is tied to di-1 / ~DI16.

    xIODO is tied to do-1 / ~DO16.

    It works fine if I assign a Bool var directly to DI/1 and use that, but not when trying to access the bit val of a Word.

    It seems to only be the DI Word that has an issue. If I use a bool val for DI/1 and leave the xIODO.X0, it will write a value to the bit of the DO word as I would expect.

    IF xIODI_1 THEN

      xIODO.X0 := TRUE;

      ELSE

      xIODO.X0 := FALSE;

      END_IF;


    Any ideas why this would be the case?

  • If xIODI = 16#0100

    then

    xIODI.X0 will be FALSE.

    xIODI.X8 will be TRUE.

    Does this explain what you're seeing?

Sign In or Register to comment.