Jump to content
The simFlight Network Forums

Recommended Posts

Posted

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

Posted

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.

Posted

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

Posted

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

Posted

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

 

 

Posted

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

Posted
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

 

Posted

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

Posted
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

 

Posted

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

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.