bapilot54 Posted March 30, 2009 Report Posted March 30, 2009 Hi, I am new to this programming game but what the hell, i`ll give it a try :) I have figured out the basics, but I want to write to offset ( 310A .2) Rudder disconnect. It should write (4) to this offset to disable it via a check box, and then repeat every 9 seconds until the check has been taken out of the check box. Thanks for your help this is what I have so far : Dim RudderDisable As Offset(Of BitArray) = New FSUIPC.Offset(Of BitArray)(&H310A, 1) Private Sub Rudder_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rudder.CheckedChanged Me.RudderDisable.Value(2) = IIf(Me.Rudder.Checked, 1, 0) End Sub I do have other stuff in between on a timer which works fine, it`s just that every time I write it uses a 1 and I can`t get it to write 4.
Paul Henty Posted March 30, 2009 Report Posted March 30, 2009 Hi, I think you've run into a problem with the way my DLL handles BitArrays. The write only happens when the data in the BitArray is changed from the last value written or read. I'll investigate this in more detail using your example and I'll come up with a way of making the DLL work properly with these type of offsets. (Those where you have to keep writing the same value and you are using a 'reference' data type like a BitArray). For now, if you declare this offset as a 'Byte' instead of a BitArray, make it readonly (very important), and just assign 4 (or whatever other values you need) then it should work as you expect. ('Value' types like Byte won't have the same problem because they write when assigned to (even if you assign the same value)). Let me know if you still cannot make it work using Byte. Paul
bapilot54 Posted March 31, 2009 Author Report Posted March 31, 2009 Hi, thanks for your quick response and helpful information. I am struggling though (being new to programming) to write the byte value as (4). I basically need to write a (4) from offset 0x310A .2 (bit 2). Could you possibly help wih this matter, thanks again and regards Chris.
Paul Henty Posted March 31, 2009 Report Posted March 31, 2009 I've changed your posted code to use a Byte type instead of a BitArray: ' Declare our interest in offset 310A, which is a byte in length (and write only) Dim RudderDisable As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)(&H310A, True) Private Sub Rudder_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rudder.CheckedChanged ' If the checkbox is checked we write 4 to this offset to set bit 2, else we write 0 to clear bit 2. Me.RudderDisable.Value = IIf(Me.Rudder.Checked, 4, 0) End Sub You do need to write to this offset regularly or it will 'time out' after 10 seconds. I suggest you move the line in the checkbox change event to your normal process loop, or setup another timer to handle this every 5 seconds or so. If you want to do it properly I suggest putting this offset in it's own group, the you can process this group independently of the other offsets. Here is the code to do this with another Timer called Timer2 (you'll need to adjust the interval on Timer2): ' Declare our interest in offset 310A, which is a byte in length (and write only) ' and put it in it's own group so we can deal with it seperately. Dim RudderDisable As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("Rudder", &H310A, True) Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick ' If the checkbox is checked we write 4 to this offset to set bit 2, else we write 0 to clear bit 2. Me.RudderDisable.Value = IIf(Me.Rudder.Checked, 4, 0) ' Now process the group with the Rudder control in FSUIPCConnection.Process("Rudder") End Sub If you need any more help just ask... Paul
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