Showing results 1 to 4 of 4

Thread: Read/Write a single bit in a Byte/Word ?

  1. #1
    Join Date

    Default Read/Write a single bit in a Byte/Word ?

    I would like to use a button to alter a singular bit within a word, much the same way PLCs have been doing since forever. These are going to be a bank of 16 buttons, with 16 other bits to determine if they are even visible or not.

    This means I need to read and write single bits within a byte. I've tried searching for this and so far all I have found are some extremely long winded mechanisms that make me think that somebody somewhere didn't understand what question was being asked.

    I've tried making a 16 bit data type made of 16 bits, well it doesn't like that at all.
    I've tried just typing in ThisByte.ThisBit into the button selection variable element. Nope.

    So, if I want a button to be visible based on say "Bit 3" of a word, and if it is pushed it sets "Bit 3" of a different word, how am I going to do this?

  2. #2
    Join Date

    Default Re: Read/Write a single bit in a Byte/Word ?

    WORD is composed by 16 bits. If you want to set third bit, you have to set 8 (2^3) value in the variable.
    For example, setting 16 value in the variable corresponds to set fourth bit of the variable.

  3. #3
    Join Date

    Unglücklich Re: Read/Write a single bit in a Byte/Word ?

    That doesn't work.

    Bit 0 may well impart a value of 1, but if you check the whole word for value 1, you won't ever detect that Bit 0 is true unless all the other bits are false.

    What I want is far simpler than that. So simple it seems it is beneath Zenon's capabilities.

    I just want to read in a WORD and access its bits as bits. This is extremely common practise in PLCs since PLCs were invented, even Beckhoff PLCs will permit WORD.BIT access. I don't recall ever being denied WORD.BIT access before, it's new to me, so the mechanism by which I can simulate having WORD.BIT access is an exploratory endeavour because this is not a road I've had to tread before.

    I suppose I could use the built in Zenon logic to start unpacking bits etc, but then I could just unpack them in my PLC.

    I could use the built in Interlock system as that seems to have .BIT access where the rest of the system doesn't. But then I could just do it in the PLC again.

    Buttons aren't even capable of writing Values to Words let alone evaluating them. Even if it could determine the value, specific values don't work the same way as .BIT access works because of the inherent requirement for all other bits to be 0.

    I'm frankly shocked at losing what is one of the most basic functionality of computers. I can only imagine it's in there and I just cannot find it. I am not ready to believe it has been replaced with the most convoluted mechanisms to simulate it that I have seen in other threads that are all harder than doing it my own self in the PLC.

  4. #4
    Join Date

    Default Re: Read/Write a single bit in a Byte/Word ?

    I just stumbled upon this thread.

    Have you tried to create a BOOL for every Bit in that WORD?

    The BOOL needs the address information of that Word and with the parameter Bit number you should be able to target a specific Bit of it.

    That will probably not work with every driver but it's worth trying it.

Similar Threads

  1. Reading bit from word
    By kuki in forum zenon Service Engine Supervisor
    Replies: 2
    Last Post: 31st May 2015, 14:20
  2. Read and write variables from plc with VBA
    By cibertoni in forum VBA
    Replies: 1
    Last Post: 22nd September 2014, 16:36
  3. Add a variable type 'byte'
    By martijnvanspijk in forum Drivers
    Replies: 2
    Last Post: 28th May 2013, 11:00
  4. String in Byte-Array
    By rooswald in forum Drivers
    Replies: 2
    Last Post: 21st May 2013, 07:31
  5. Replies: 2
    Last Post: 22nd September 2011, 01:32

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts