MVP 2023 Flex727 Posted October 4, 2022 MVP 2023 Report Posted October 4, 2022 Can anyone think of a clever way to toggle every bit in a vector of 25 MBs in a single ladder rung and a single PLC scan?
MVP 2023 kratmel Posted October 4, 2022 MVP 2023 Report Posted October 4, 2022 Num to BIT i use for init some bit vector. Fast way - Vector copy from XB to MB. I use power on value for XB and copy this value to MB with one vector copy command.
MVP 2023 Flex727 Posted October 4, 2022 Author MVP 2023 Report Posted October 4, 2022 No, I need to TOGGLE each bit in the vector. Some of the bits are on and some are off. I need to flip each bit. It doesn't have to be immediate, just in a single scan. I can brute force it by copying each bit to another vector with an inverted contact and coil (x25), requiring 4 rungs, perhaps fewer, but I was just looking for a clever way to do it without all that typing. Or maybe I'm misunderstanding what you're suggesting. I'm thinking I can convert the vector to an integer, multiply by -1, then subtract 1, then convert back to a bit vector. I'll see if that works.
MVP 2023 Flex727 Posted October 4, 2022 Author MVP 2023 Report Posted October 4, 2022 22 minutes ago, Flex727 said: I'm thinking I can convert the vector to an integer, multiply by -1, then subtract 1, then convert back to a bit vector. I'll see if that works. This works perfectly. I think I learned this in middle school math and totally forgot. 1
MVP 2023 kratmel Posted October 4, 2022 MVP 2023 Report Posted October 4, 2022 Maybe I didn't understand the task at first and thought that you need to quickly turn the bits off or on. I liked your idea with the math. However, there was an idea in my head that the function could be done differently. The result is in this piece of code I will also add a test project for those who want to try to do this action in another way. TOGGLE.vlp
MVP 2023 Flex727 Posted October 4, 2022 Author MVP 2023 Report Posted October 4, 2022 I like your method, kratmel! Here's what I ended up doing: The original bit was an "enabled" bit that I needed to use to hide an HMI element, so it needed to be flipped. Normally that's not a problem, but when you have 25 of them it's a pain. I have begged Unitronics for a checkbox on the HMI element hide setting to allow either on or off to hide the element, but I'm sure we'll never see it.
MVP 2023 Ausman Posted October 5, 2022 MVP 2023 Report Posted October 5, 2022 I haven't tested this, but couldn't you use Toggle Bit in Vector for this? No other mucking around needed. cheers, Aus
MVP 2023 Flex727 Posted October 5, 2022 Author MVP 2023 Report Posted October 5, 2022 46 minutes ago, Ausman said: I haven't tested this, but couldn't you use Toggle Bit in Vector for this? I wanted to toggle ALL the bits. Toggle Bit in Vector only does one.
MVP 2023 Ausman Posted October 6, 2022 MVP 2023 Report Posted October 6, 2022 Ahh yes, sorry. I've used it within Vectors in the past and mis-remembered that it allowed a range to be done. I'm putting a trademark on mis-remembered. But I'll allow usage here on the forum. We can make it the person over 40s version of "mybad", which unfortunately covers a host of frustrating actions that have little responsibility attached. 🙂 cheers, Aus
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now