mroschk Posted February 7, 2020 Report Posted February 7, 2020 Hello, i have this little function in a LUA Script to check/set the DoorSTate. function DoorState() ipc.display("Doors", 3) ipc.setbitsUB(0x5302, 0) ipc.setbitsUB(0x5302, 1) end as you can see, i have testet if this script-function is called, and it is. But the Offset is not set after the function is called. Have you any idea why ? Thanks Matthias
spokes2112 Posted February 8, 2020 Report Posted February 8, 2020 For kicks just tested. It seems to work fine. I used - ipc.setbitsUB(0x5302, 1) ipc.setbitsUB(0x5302, 2) And the monitored, expected output was correct.. 3 The mask is the integer equivalent of the bit, not the zero based location of the bit.
mroschk Posted February 8, 2020 Author Report Posted February 8, 2020 Hello, but i testet also ipc.setbitsUB(0x5302, 1) but it seams not to work here. I will test it again this night. Thanks for the Answer and for testing that Matthias
mroschk Posted February 9, 2020 Author Report Posted February 9, 2020 Hello, i dont know why it is not working: function DoorState() local flag = 0 --if doorflag0 == 1 then flag = flag + 1 end --if doorflag1 == 1 then flag = flag + 2 end --if doorflag2 == 1 then flag = flag + 4 end --if doorflag3 == 1 then flag = flag + 8 end --if doorflag4 == 1 then flag = flag + 16 end --if doorflag5 == 1 then flag = flag + 32 end --if doorflag6 == 1 then flag = flag + 64 end if doorflag0 == 1 then ipc.setbitsUB(0x5400, 1) end if doorflag1 == 1 then ipc.setbitsUB(0x5400, 2) end if doorflag2 == 1 then ipc.setbitsUB(0x5400, 3) end if doorflag3 == 1 then ipc.setbitsUB(0x5400, 4) end if doorflag4 == 1 then ipc.setbitsUB(0x5400, 5) end if doorflag5 == 1 then ipc.setbitsUB(0x5400, 6) end if doorflag6 == 1 then ipc.setbitsUB(0x5400, 7) end --ipc.display("DoorState " ..flag, 3) ipc.writeUB(0x5400, flag) end The ipc.setbits is not working. The version with the "--" is working fine. I know it is doing the same, but it would be nice to know why the setbits is not working? Matthias
mroschk Posted February 9, 2020 Author Report Posted February 9, 2020 Oh je, my mistake, sorry.... As you can see, i forgot to remove the "ipc.writeUB" in the last line...sorry, it works now "" Thanks Matthias
Pete Dowson Posted February 15, 2020 Report Posted February 15, 2020 If you want the byte in 5400 to contain a different integer depending on those doorflags then you should use "ipc.writeUB". Your code using "ipc.setbitsUB" will OR bits in on each use. For instance, if all 7 doorflags are set the result in 5400 with your code will just be '7'. It looks really as if you want a different bit to be set in 5400 for each doorflag. In that case the values should be 1, 2, 4, 8, 16, 32 and 64. Just remember: "setbits" means set the bits in the supplied value, OR'ing them into whatever is there. "clearbits" does trhe reverse, removing those bits (i.e. changing them to zero). This method can set and clear mutiple bits in one instruction. You seem to be thinkning that the functions use bit numbers (0-7) which it does not. Pete
mroschk Posted February 15, 2020 Author Report Posted February 15, 2020 Hello, yes, i do it like you say. I add to the flag variable 1,2,4,8,16,32,64 if the doorflag is set an use writeUB to set the bits. Thanks Matthias
Pete Dowson Posted February 15, 2020 Report Posted February 15, 2020 1 hour ago, mroschk said: I add to the flag variable 1,2,4,8,16,32,64 if the doorflag is set an use writeUB to set the bits. No! writeUB will set the VALUE, not the BITS! Use setbitsUB to set the bits, with those variables, as I said!! Pete
mroschk Posted February 15, 2020 Author Report Posted February 15, 2020 but it works and i dont need to OR the bits. ipc.setbitsUB(0x5400, 1) is not setting bit 1 to 1 and ipc.setbitsUB(0x5400, 2) is not setting bit 2 to 1. Matthias
Pete Dowson Posted February 16, 2020 Report Posted February 16, 2020 17 hours ago, mroschk said: but it works and i dont need to OR the bits. ipc.setbitsUB(0x5400, 1) is not setting bit 1 to 1 and ipc.setbitsUB(0x5400, 2) is not setting bit 2 to 1. Matthias Sorry, it appears you still do not understand! Value 1 is bit 0 and value 2 is bit 1. The values of the bits are as i said: bit value 0 1 1 2 2 4 3 8 4 16 5 32 6 64 7 128 The setbits and clrbits functions use the values, not the bit numbers, because they are designed to allow multiple bits to be set or cleared. Pete
mroschk Posted February 16, 2020 Author Report Posted February 16, 2020 now i am completely confused. So, easy question, what must i do to set ( as example ) bit 5 of Offset 5400 to 1 ? Matthias
spokes2112 Posted February 17, 2020 Report Posted February 17, 2020 Make bit 5 to 1 (SET) --> ipc.setbitsUB(0x5400, 32) Make bit 5 to 0 (CLEAR) --> ipc.clearbitsUB(0x5400, 32) Setting or clearing multiple bits, add them up.. Make bits 1,5 & 7 to 1 (SET) --> ipc.setbitsUB(0x5400, 162) < 2 + 32 + 128 > Make bits 1,5 & 7 to 0 (CLEAR) --> ipc.clearbitsUB(0x5400, 162) Roman
mroschk Posted February 17, 2020 Author Report Posted February 17, 2020 ahhh, thats the way.... Now i understand I come from C#, and here you set/clear the Bit via the BitNumber directly. Thanks very much Matthias
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