Jump to content
The simFlight Network Forums

VB6 Programming Dummy - FSUIPC_Write


Recommended Posts

I figured out how to read the FSUIPC offsets, specifically all the Com/Nav Active/Standby Frequencies. I was trying to access offset 3123 to "swap" the frequencies from standby to active but am having no such luck.

I saw some examples of how to write to an offset, but they didn't talk about writing to a specific bit.

Could someone post an example of how I write "bits" to the offset to control these and many of the other offsets available also.

If there is an example already somewhere that I missed, I would appreciate that also.

My programming experience is limited to VBA code from my database writing days.

Link to comment
Share on other sites

I was trying to access offset 3123 to "swap" the frequencies from standby to active but am having no such luck.

I saw some examples of how to write to an offset, but they didn't talk about writing to a specific bit.

Could someone post an example of how I write "bits" to the offset to control these and many of the other offsets available also.

Well, with most things you would have the read it, change the bit (or bits), then write it back. There's no other way.

However, for this particular offset, the documentation does explicitly say "Write bits to operate toggles. Don’t bother to read it, there’s no meaning to anything read." Here it just means write a value with the required bits set and the others not set.

So, just write a 1 byte value with the appropriate bit or bits set. i.e. for, say, NAV1 (bit 2^1), write a 1 byte value of 2 (because 2^1 = 2). If you want to operate all four swap buttons together you could do by sending 15 (2^3 + 2^2 + 2^1 + 2^0).

In general, though (not in this case), you'd need to read the value first. The light switches at offset 0D0C are like that -- they are 1 when on, 0 when off. To turn one on you'd read the 16-bit word, logically OR in the bit value for the light you want to turn on, and write the 16-bit word back. To turn one off you'd do it similarly, but AND the value read with the "NOT" of the bit -- i.e. with a pattern containing all bits set except that one.

I cannot give you VB examples, I don't know VB, but check in your VB manuals of documentation and find the logical bit operations. All programming languages provide OR, AND, NOT and even exclusive OR (XOR) which I won't explain here, as well as shifts left and right. They just use different symbols or names. In C the logical bit AND is &, OR is |, NOT is ~, and XOR is ^, whilst shifts are << (left) and >> (right). But they'll be different in VB.

Regards,

Pete

Link to comment
Share on other sites

Thanks Pete, I appreciate your quick reply. I'm still a little confused by it all. I'll have to do some serious research i guess. I'm really in way over my head. perhaps if you posted an example in C, maybe I can decipher it. Or better yet, if anyone else out there reading this post can offer up some VB specific assistance.

Would it be something like:

-------------------------------------------------------------

Dim Nav1Swap As Byte

Nav1Swap = 2^1

FSUIPC_Write(&H3123,2,VarPtr(Nav1Swap),dwResult)

--------------------------------------------------------------

That's what I tried but I get a compile error: ByRef argument type mismatch

Link to comment
Share on other sites

Would it be something like:

-------------------------------------------------------------

Dim Nav1Swap As Byte

Nav1Swap = 2^1

FSUIPC_Write(&H3123,2,VarPtr(Nav1Swap),dwResult)

--------------------------------------------------------------

That's what I tried but I get a compile error: ByRef argument type mismatch

Hmmm. What does 2^1 mean in VB? In C it would give 3, as ^ is the "exclusive OR" symbol. In my document it is just used as a power indicator, "2 to the power of 1". As I said in my last message, that is 2, so just set it to 2.

To work out powers of 2, take 2^0 as 1 then multiply by 2 for each power higher. So, for instance, 2^3 is 1 x 2 x 2 x 2 = 8. The sequence goes 1,2,4,8,16,32, etc.

Your FSUIPC_Write is wrong as well. You didn't read my last message very well I'm afraid. I said you write 1 byte, not 2 as you have there.

As for that VarPtr stuff, sorry, that's a VB peculiarity which I have no idea about. I would have thought you'd have to derive the address somehow -- look in your VB books. The error "ByRef ..." sounds as if it is to do with that. How did you manage to read or write the other stuff you said you'd handled?

As for providing it in C, that would most certainly confuse you even more judging by the VB example! :wink: Sorry. I'd better butt out now and leave it to VB folks!

Regards,

Pete

Link to comment
Share on other sites

See the subject heading says it all -- "DUMMY" I'll admit that! I'll try to absorb all this information a little more. Appreciate your input!

Well, I didn't get any writes to work at all earlier, but I got the reads to work somehow. Below is an example of how I did that. I know you don't do VB, but it used that VarPtr thingamajig. It came from the FSUIPC_VB.zip or whatever it was named example file in the SDK.

-----------------------------------------

Dim dwResult As Long

Dim Com1Act As Integer

Dim Com2Act As Integer

Dim Com1Sby As Integer

Dim Com2Sby As Integer

Dim Nav1Act As Integer

Dim Nav2Act As Integer

Dim Nav1Sby As Integer

Dim Nav2sby As Integer

Call FSUIPC_Read(&H34E, 2, VarPtr(Com1Act), dwResult)

Call FSUIPC_Read(&H3118, 2, VarPtr(Com2Act), dwResult)

Call FSUIPC_Read(&H311A, 2, VarPtr(Com1Sby), dwResult)

Call FSUIPC_Read(&H311C, 2, VarPtr(Com2Sby), dwResult)

Call FSUIPC_Read(&H350, 2, VarPtr(Nav1Act), dwResult)

Call FSUIPC_Read(&H352, 2, VarPtr(Nav2Act), dwResult)

Call FSUIPC_Read(&H311E, 2, VarPtr(Nav1Sby), dwResult)

Call FSUIPC_Read(&H3120, 2, VarPtr(Nav2sby), dwResult)

Call FSUIPC_Process(dwResult)

lblCom1Act.Caption = "1" & Format(Hex(Com1Act) / 100, "00.00")

lblCom1Sby.Caption = "1" & Format(Hex(Com1Sby) / 100, "00.00")

lblNav1Act.Caption = "1" & Format(Hex(Nav1Act) / 100, "00.00")

lblNav1Sby.Caption = "1" & Format(Hex(Nav1Sby) / 100, "00.00")

lblCom2Act.Caption = "1" & Format(Hex(Com2Act) / 100, "00.00")

lblCom2Sby.Caption = "1" & Format(Hex(Com2Sby) / 100, "00.00")

lblNav2Act.Caption = "1" & Format(Hex(Nav2Act) / 100, "00.00")

lblNav2Sby.Caption = "1" & Format(Hex(Nav2sby) / 100, "00.00")

-----------------------------------------------------------------------------

Link to comment
Share on other sites

Hi Pete -

Yes I did. And it also made more sense when you said write a value of 1,2,4,8, etc... All the 2^0 stuff confused me because I wasn't looking at it as a mathematical equation.

I'm looking forward to playing with all the other offsets to see what other trouble I can get into.

Thanks again,

Brian

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.