Jump to content
The simFlight Network Forums

Update a bit value


guda

Recommended Posts

hello Paul,

 

I've read the dynamic offset thread. it works fine for "classical" offsets (integer...) but not for bitarray.

 

In my case, the users decides that he wants to send "False" to the bit 3 of &H0D0C offset. (taxi light OFF).

 

By a standard way, I could do this:

Dim FS_lights As New Offset(Of BitArray)("Dynamic", &HD0C, 2, True) ' create the offset - Write only'
FS_lights.Value.Item(3) = False ' write bit 3'
FSUIPCConnection.Process("Dynamic") ' send '
FSUIPCConnection.DeleteGroup("Dynamic") ' remove '

Here, my issue is I don't know the offset size (in my example = 2). Do we have a mean to write directly a bit?

 

regards

 

Dan

Link to comment
Share on other sites

Hi Dan,

 

FSUIPC has no facilities to write to a bit directly. The BitArray is used by the dll to make things easier.

 

Normally you'd need to treat 0D0C offset as a short and perform bitwise operations to set the correct bit. e.g. to set bit x you would need to do this:

(This is 0 based, so the value of x for the least significant bit is 0 (as specified in the FSUIPC docs))

FS_lights.Value = FS_lights.Value Or (2 ^ x)

To reset the bit you do this:

FS_lights.Value = FS_lights.Value And (Not 2 ^ x)

To get a bit value you do this:

Dim bitValue As Boolean
bitValue = (FS_lights.Value And (2 ^ x)) > 0

This might help you because I presume you have some way of handling the different sizes of integer at the moment (1,2 and 4 bytes). So you can use the same method to declare the offsets (byte, short, integer), you just can't use the nice bitarray syntax, you must use the above maths.

 

Alternatively you could just ask the user to give you the length of the offset along with the offset address when they want to use a bit array.

 

Let me know if need any more help with this.

 

Paul

Link to comment
Share on other sites

Thank you Paul for your reply.

 

It works in one way : light off :

Dim FS_lights As New Offset(Of Short)("Dynamic", &HD0C) ' offset declaration '
FSUIPCConnection.Process("Dynamic") ' update the FS light value '
FS_lights.Value = FS_lights.Value And (Not 2 ^ 3) ' only light off index #3 = Taxi Light '
FSUIPCConnection.Process("Dynamic") ' sent '

When I try to light On taxi I use this script

FS_lights.Value = FS_lights.Value And (2 ^ 3) ' Expected: only taxi light (3) should change (light ON) '
FSUIPCConnection.Process("Dynamic") ' sent '

Here the result is not OK => All lights are off. What is wrong?

 

Regards

 

Dan

Link to comment
Share on other sites

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.