Jump to content
The simFlight Network Forums

Recommended Posts

Posted

I'm new to using offset and counting in binary, so my issue may be my full understanding of Hexidecimal and bits work. I'm trying to read the status of Fuel pump in FSX. with aircraft with 4 engines and I beleive that I am getting cthe orrect results when using offset 3104 which only appies to one engine as follows  n=ipc.readUB(3104).  I'm getting expected result of 1= on and 0 = off. My quetion is surrounding using same logic but now with offset 3125.  My understanding which may be flawed, is that memory location 3125 is an 8 byte location and I think that bit location 1 (2^0) has engine one information, bit location 2 (2^1) has engine two information, bit location 4 (2^2) as engine three information and finally bit location 16 (2^4) has engine four information?

   My questions are:

  1. My inital thought above was that I am dealing with an 8 byte memory location, but my engine 4 logic (2^4) is calculating a bit 16 location so I think my logic is flawed, how I'm I thinking wrong? 
  2. How do I fill out the ipc.readUB(offset) when only wanting one specific bit location? I think I need to use a mask, but not sure syntax to use? For engine three for example, would it be n=ipc.readUB(3125&04)?
  3. I'm I correct that I should expect to to get the same results as offset 3104 for each engine of 1= on and 0 = off?

Thanks

 

Posted
6 hours ago, oneaokguy said:

My inital thought above was that I am dealing with an 8 byte memory location, but my engine 4 logic (2^4) is calculating a bit 16 location so I think my logic is flawed, how I'm I thinking wrong? 

Its a 1-byte or 8-bit address. Bit 1 (counting from 1) holds pump1, bit 2 holds pimp2, etc

6 hours ago, oneaokguy said:

How do I fill out the ipc.readUB(offset) when only wanting one specific bit location? I think I need to use a mask, but not sure syntax to use? For engine three for example, would it be n=ipc.readUB(3125&04)?

You need to read as a byte and use the logic library, e.g.
     n=ipc.readUB(0x3125)
     pump1 = logic.And(n, 0x1) -- 2^0
     pump2 = logic.And(n, 0x2) -- 2^1
     pump3 = logic.And(n, 0x4) -- 2^2
     pump4 = logic.And(n, 0x8) -- 2^3

6 hours ago, oneaokguy said:
  1. I'm I correct that I should expect to to get the same results as offset 3104 for each engine of 1= on and 0 = off?

Offset 0x3104 only holds pump1, so that should match the state of the first bit in offset 0x3125.

6 hours ago, oneaokguy said:

I am getting cthe orrect results when using offset 3104 which only appies to one engine as follows  n=ipc.readUB(3104).

But that is not correct should be  n=ipc.readUB(0x3104). You need to precede offset values with 0x, or use the string form, i.e.  n=ipc.readUB("3104")

John

Posted

Thanks, I had totally missed the logic library and needed that missing piece. Let me add that logic and see if I have any follow-up questions.

As an aside, my documentation might be outdated and this might have already been corrected, but the callout on my FSUIPC Offset cheat sheet for 3125 looks wrong and should read 2^3 for engine #4 which makes more sense now with 8 bit address. If that has not been updated, suggest it be amended.

image.gif.8be90e00e1ced316276f258a983f1bad.gif

Posted

Follow-up question on the values I should expect for each engine pump. It was my understanding from documentation that a value of 1=on and 0=off should be expected for each but I'm getting the following

Pump1 - 0=off and 1=on

Pump2 - 0=off and 2=on

Pump3 - 0=off and 4=on

Pump4 - 0=off and 8=on

The On value seems wrong since we are dealing with one bit, so I must have an error again in my understanding and my logic for displaying the value after switch is on

I'm using the following display code to see the value for each pump before and after flipping switch in FSX using the earlier ipc.read and logic.and  code, the full function is listed below.

ipc.display(Pump2,3) 

 

 

Full Function

function Eng2_Fuel_Pump_On()
Pump2=ipc.readUB(0x3125)
Pump2x=logic.And(Pump2, 0x2)
ipc.display(Pump2x,1)
ipc.sleep(3000)
    ipc.control(66341)
    ipc.sleep(3000)
    Pump2a=ipc.readUB(0x3125)
    Pump2z=logic.And(Pump2a, 0x2)    
    ipc.display(Pump2z,5)    

end

 

As I shared earlier, I'm new in thinking on binary terms and I was trying to understand the highlighted example to better understand this logic routine, but I'm not understanding why the below holds true and may be where my error lies in thinking I can display this value. Are you able to explain why those two binary values = 0010? I'm I somehow adding bits when I am displayng the value for each pump?

image.gif.262221da21bffdda5dd3800f0137a7d1.gif

Posted
3 minutes ago, oneaokguy said:

As an aside, my documentation might be outdated and this might have already been corrected, but the callout on my FSUIPC Offset cheat sheet for 3125 looks wrong and should read 2^3 for engine #4 which makes more sense now with 8 bit address. If that has not been updated, suggest it be amended.

Yes, I noticed that as well and will update.

As a sided-note, its also more common/useful to start counting bits from 0, as then bit 0 is 2*0 (1), bit 1 is 2^1 (2), bit 2 is 2^2(4), etc, so the bit number corresponds to the power of 2 number.

Posted
37 minutes ago, oneaokguy said:

Follow-up question on the values I should expect for each engine pump. It was my understanding from documentation that a value of 1=on and 0=off should be expected for each but I'm getting the following

Pump1 - 0=off and 1=on

Pump2 - 0=off and 2=on

Pump3 - 0=off and 4=on

Pump4 - 0=off and 8=on

Yes, of course, as that is the bit value. 0 is always off, and::
    1 = 2^0 (bit 0)
    2 = 2^1 (bit 1)
    4 = 2^2 (bit 2)
    8 = 2^3 (bit 3)
    ...etc

But this shouldn't matter. When testing bits. you just want to know if its off (value = 0) or on (value != 0).

 

Posted
39 minutes ago, oneaokguy said:

As I shared earlier, I'm new in thinking on binary terms and I was trying to understand the highlighted example to better understand this logic routine, but I'm not understanding why the below holds true and may be where my error lies in thinking I can display this value. Are you able to explain why those two binary values = 0010? I'm I somehow adding bits when I am displayng the value for each pump?

image.gif.262221da21bffdda5dd3800f0137a7d1.gif

Compare each bit position:
   bit 0 - first number has 1 in this position, second has 0 - and (&) them and you get 0
   bit 1 -                             1                                             1                                               1
   bit 2 -                             0                                             0                                               0
   bit 3 -                             0                                             1                                               0
result: 0010

But this is not the place for a binary logic tutorial - please try google!

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.