Announcement

Collapse
No announcement yet.

FB v6 & Visual Basic

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • FB v6 & Visual Basic

    Any chance of interfacing to the v6 with Visual Basic (and a 'how-to for dummies' writeup?)
    Work's a little slow this time of year & I have 2 v6 & a v3 sitting on my desk doing nothing. I've dinked around with FuseGL and while it seems like it will be nice when done, I just don't 'get' it.

    I know nothing when it comes to C#, looks like sandscrit to me-too abbreviated for me to figure out. (took a semester of C in college, waste of time & those brain cells were drowned long ago).
    I don't get XML most of the time (I understand a lot of it, but without any direction/comments, I'm doing way too much trial & error with the fuseGL config and frustrated easily. It's like a language I almost understand but screw up every time I try it).
    FuseGL looks pretty, but I don't need a pretty GUI, just functional. The standard windows controls in VB are great for me because I don't have to do much to create them, just use them.

    I know enough VB to be dangerous. Seriously, I have a VB program that launches exploding projectiles via a FB v4.
    Problem is, without some sample code from MX270a, it would have never happened. With no .dll for the v6, I have no idea where to start.
    VB is also good for learning as i go - it seems to be a language I at least know how to look for answers to my questions, C# just befuddles me. I don't have the time/motivation to learn it either.

    So I'm hoping someone is willing to show me / teach me how to interface the FBv6 with visual basic code. I just need to a) read inputs, b) set outputs, c) query output state (if possible). I can figure it out from there.

  • #2
    Originally posted by Iamthehor View Post
    Any chance of interfacing to the v6 with Visual Basic (and a 'how-to for dummies' writeup?)
    Work's a little slow this time of year & I have 2 v6 & a v3 sitting on my desk doing nothing. I've dinked around with FuseGL and while it seems like it will be nice when done, I just don't 'get' it.

    I know nothing when it comes to C#, looks like sandscrit to me-too abbreviated for me to figure out. (took a semester of C in college, waste of time & those brain cells were drowned long ago).
    I don't get XML most of the time (I understand a lot of it, but without any direction/comments, I'm doing way too much trial & error with the fuseGL config and frustrated easily. It's like a language I almost understand but screw up every time I try it).
    FuseGL looks pretty, but I don't need a pretty GUI, just functional. The standard windows controls in VB are great for me because I don't have to do much to create them, just use them.

    I know enough VB to be dangerous. Seriously, I have a VB program that launches exploding projectiles via a FB v4.
    Problem is, without some sample code from MX270a, it would have never happened. With no .dll for the v6, I have no idea where to start.
    VB is also good for learning as i go - it seems to be a language I at least know how to look for answers to my questions, C# just befuddles me. I don't have the time/motivation to learn it either.

    So I'm hoping someone is willing to show me / teach me how to interface the FBv6 with visual basic code. I just need to a) read inputs, b) set outputs, c) query output state (if possible). I can figure it out from there.
    You're asking for visual basic, I assume you mean vb.net? The v6 fusion brain requires the use of .net4.0, which of course means you have to have visual studio 2010. Assuming you have it, i can provide you with some easy to understand code for reading inputs and writing outputs.
    mp3Car.com Senior Tech Blogger (Want a product reviewed? Contact me.)
    Follow Me on Twitter or Facebook
    Live mp3Car Facebook Chat

    Comment


    • #3
      Originally posted by Sonicxtacy02 View Post
      You're asking for visual basic, I assume you mean vb.net? The v6 fusion brain requires the use of .net4.0, which of course means you have to have visual studio 2010. Assuming you have it, i can provide you with some easy to understand code for reading inputs and writing outputs.
      yes, vb.net, and I have 2010express (only vb installed, gave up on c# before this last round). I would greatly appreciate any pointers/help. I haven't used .net much yet, but the jump from VB6 to 2k8 was pleasantly easy - what I remembered was still valid, and the things I didn't know (or had forgot) were easily found.

      Comment


      • #4
        Give me a day or so and i'll provide you a set of functions that will do what you want.
        mp3Car.com Senior Tech Blogger (Want a product reviewed? Contact me.)
        Follow Me on Twitter or Facebook
        Live mp3Car Facebook Chat

        Comment


        • #5
          To be brutally honest, if you are wanting to code and are in that quasi-state of knowing enough to be dangerous but not enough to rule the world, you should really be using a C based language like C#. VB is dead. The only reason VB.NET is there is because it compiles down to the same code as C# compiles down to. It will be discontinued in the near future.

          C# is really straightforwards once you get the basics.
          Fusion Brain Version 6 Released!
          1.9in x 2.9in -- 47mm x 73mm
          30 Digital Outputs -- Directly drive a relay
          15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
          Buy now in the MP3Car.com Store

          Comment


          • #6
            Originally posted by 2k1Toaster View Post
            To be brutally honest, if you are wanting to code and are in that quasi-state of knowing enough to be dangerous but not enough to rule the world, you should really be using a C based language like C#. VB is dead. The only reason VB.NET is there is because it compiles down to the same code as C# compiles down to. It will be discontinued in the near future.

            C# is really straightforwards once you get the basics.
            This is very true, but for people not trained in programming languages, VB.net is extremely useful in identifying what you're trying to do, as it is a text-based language. Still though, I've had to force myself to code in C# for my last few projects, even though the learning curve means its takes more time to produce.
            mp3Car.com Senior Tech Blogger (Want a product reviewed? Contact me.)
            Follow Me on Twitter or Facebook
            Live mp3Car Facebook Chat

            Comment


            • #7
              Originally posted by 2k1Toaster View Post
              To be brutally honest, if you are wanting to code and are in that quasi-state of knowing enough to be dangerous but not enough to rule the world, you should really be using a C based language like C#. VB is dead. The only reason VB.NET is there is because it compiles down to the same code as C# compiles down to. It will be discontinued in the near future.

              C# is really straightforwards once you get the basics.

              Originally posted by Sonicxtacy02 View Post
              This is very true, but for people not trained in programming languages, VB.net is extremely useful in identifying what you're trying to do, as it is a text-based language. Still though, I've had to force myself to code in C# for my last few projects, even though the learning curve means its takes more time to produce.
              I took a little time today & you know what, you're both right. C# (which i learned is C-sharp, not C-pound, that's how dumb i was) is very similar to VB, at least at the lower level. My problem has always been looking at high-level (at least for me) code & not having a damn clue what was going on or any way to decipher it (including the code snippets in the FuseGL beta thread - no primer, if you will). VB kindof leads you through things, even without comments.

              Sonic, if you've got the time & this is easy to do, please continue. Once I can connect/read/send outputs to the v6, I'll write a small example & share it.
              Then, hopefully, I can do the same with C# and start to to improve my skills.

              Comment


              • #8
                Ok.. first things first, load a new project. Right click the project name and hit properties. Then click Compile tab, then the Advanced Compile Options button. on the bottom of that screen, set your target framework to .net4.0.

                Next, you'll need to add references to the 2 fusion brain .dll files which are attached below. Just unzip to folder, then in VB studio click Project/Add Reference/Browse Tab and select those two files from the location you unzipped them to.

                With that out of the way, are are a set of functions that will connect, read, and write to the v6

                Imports:
                Code:
                Imports System.Windows.Forms
                Some base variables to understand my work:

                Code:
                Private FBReadTmr As System.Windows.Forms.Timer 'analog input read timer
                Private AnalogInRaw(4, 15) As Long 'will store analog input Raw value
                Private AnalogInVoltage(4, 15) As String ' will store analog input Voltage value
                Dim _AllAnalogues(64) As Byte 'will hold the information received from fusion brain in byte form
                Private TotalInstances as Integer 'will hold the number of fusion brains connected
                Private DigitalOutStatus(4, 30) as Boolean 'will hold the status of fusion brain digital output ports as you toggle then on/off
                Initiation and connect code:

                Code:
                Public Sub New()
                FusionBrain_WinUSB.MainUSBClass.FindAllFusionBrains() ' as it says, finds all fusion brains connected
                TotalInstances = FusionBrain_WinUSB.MainUSBClass.allFusionBrains.Count ' gets count of all fusion brains connected
                FBReadTmr = New System.Windows.Forms.Timer ' initialize the timer which will read analog ports
                AddHandler FBReadTmr.Tick, AddressOf FBReadTmr_Tick ' create event handler for the above timer
                FBReadTmr.Interval = 250 ' set the interval for the timer to loop at 250ms
                
                If TotalInstances > 0 Then 'if a fusion brain is found, start the read timer
                           FBReadTmr.Enabled = True
                End If
                end sub
                Timer code that reads analog inputs:

                Code:
                Private Sub FBReadTmr_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
                        For x = 1 To TotalInstances ' loops through all FB instances connected
                            FusionBrain_WinUSB.MainUSBClass.allFusionBrains(FusionBrain_WinUSB.MainUSBClass.allFusionBrains.Count - 1).ReadDataFromFusionBrain(_AllAnalogues, &H2)
                            Dim i As Integer
                            For a As Integer = 0 To 15 * 2 - 1 Step 2
                                Dim aValue_INT As Integer = ((_AllAnalogues(a) And &H3) << 8) + _AllAnalogues(a + 1)
                                ' The raw 0 through 1023 digital value
                                ' Converting that value to a real voltage and storing in some temp List
                
                                AnalogInRaw(x, i) = aValue_INT 'provides the raw data analog input values from VB
                                AnalogInVoltage(x, i) = (3.3 * CDbl(aValue_INT) / 1023.0) 'converts the raw data to voltage form
                                i = i + 1
                            Next
                        Next
                    End Sub
                And the code to toggle a digital output:

                Code:
                Public Shared Sub SetDigitalOutput(ByVal TheInstance As Integer, ByVal ThePort As Integer, ByVal TheOutcome As Boolean)
                        If FusionBrain_WinUSB.MainUSBClass.allFusionBrains(TheInstance - 1).fusionBrain_version.version = 6 Then
                            Dim _code As Integer = &H3
                            Dim _length As Integer = 1
                            Dim port As Integer = ThePort
                            Dim _toSendArray As Byte() = New Byte(1 + ((_length * 2) - 1)) {}
                            _toSendArray(0) = CByte((_code << 5) + _length)
                            _toSendArray(1) = CByte((port) << 3)
                            If TheOutcome = True Then
                                _toSendArray(2) = &HFF
                                DigitalOutStatus(TheInstance, ThePort) = True
                            Else
                                _toSendArray(2) = &H0
                                DigitalOutStatus(TheInstance, ThePort) = False
                            End If
                            FusionBrain_WinUSB.MainUSBClass.allFusionBrains(TheInstance - 1).SendDataToFusionBrain(_toSendArray, &H1)
                        End if
                    End Sub
                
                   'turn digital output 0 on for the first(only) fusion brain instance, run the function SetDigitalOutput(1,0,True)
                   'turn digital output 0 off for the first(only) fusion brain instance, run the function SetDigitalOutput(1,0,False)
                I think that includes everything you need, put all that in your class file, then build your project and test it out. If you get build errors or something doesnt work let me know and i'll work it out.
                Attached Files
                Last edited by Sonicxtacy02; 12-20-2011, 10:24 AM.
                mp3Car.com Senior Tech Blogger (Want a product reviewed? Contact me.)
                Follow Me on Twitter or Facebook
                Live mp3Car Facebook Chat

                Comment


                • #9
                  Sonic, you are my hero. Just for my info - where do you find a list of the functions available from the .dll(s)? Can you open them? VB2k8 used to have a side bar that would show the references you were using & I think I could see them there, but 2010 express doesn't have that.

                  I ran into 1 problem with your code:
                  Code:
                  Public Shared Sub SetDigitalOutput(ByVal TheInstance As Integer, ByVal ThePort As Integer, ByVal TheOutcome As Boolean)
                  Gave me a runtime error for DigitalOutStatus - something about needing an explicit call to the class or something. googled it, without finding a definite answer, but "Shared" seemed to be the issue - Removed Shared & problem went away (may be an issue with multiple forms later, I'll deal with that when it comes up.

                  I'm having a little trouble with the analog inputs.
                  In the timer_tick, I'm updating 2 labels using label1.text=cstr(analogInRaw(1, 0)) (instance, port). When I start the program, the label cycles between 0 and a random number (Seemingly at the 250ms timer rate) for 4-5 cycles, then settles at 0 (sometimes it stays at 0 from the beginning, sometimes it will re-cycle if I jiggle the connector).
                  I've tried 3 different temp sensors (2 that came with my v6 brain & 1 that came with v4 - I know it's for 5V) and shorting between +++ and AIN+. I've tried (0,0) (0,1) & (1,1) and I've tested the 1st 2 ports on each side of the group (I thought port0 was closest to USB connector, but I can't tell the difference due to how it's acting). I had a similar issue trying to read an analog in with FuseGL, so it could be a hardware problem, but I still suspect ID10T error.

                  Comment


                  • #10
                    The full version of 2010 allows the same thing, but if you type "FusionBrain_WinUSB." a tooltip will show you all available options.

                    I had to change some of my code to make it work outside my application so if public works instead of public shared thats fine use that.

                    As for the analog input issue... when it cycles does it go 0... <randomnumber>... 0? I dont know how to help you with that, as it does sound like a hardware issue. The random number is the 0-1023 value that needs to converted via a formula to make the temp sensor show degrees. This is the formula

                    Code:
                    dim MyAnalog as long 'will display converted analog temperature value
                    If UCase(RRSDK.GetInfo("=$ISUNITS")) = "TRUE" Then
                                            MyAnalog = (((((((((AnalogInRaw(TheInstance, ThePort) / 1024) * 5) + -0.4) * 1000) / 19.53) * 1.8) + 32) - 32) * (5 / 9))
                                        Else
                                            MyAnalog = ((((((((AnalogInRaw(TheInstance, ThePort) / 1024) * 5) + -0.4) * 1000) / 19.53) * 1.8) + 32))
                                        End If
                    Where if RRSDK.GetInfo("=$ISUNITS") is true, celcius value will be displayed. If false, farenheit is displayed.

                    Originally posted by Iamthehor View Post
                    Sonic, you are my hero. Just for my info - where do you find a list of the functions available from the .dll(s)? Can you open them? VB2k8 used to have a side bar that would show the references you were using & I think I could see them there, but 2010 express doesn't have that.

                    I ran into 1 problem with your code:
                    Code:
                    Public Shared Sub SetDigitalOutput(ByVal TheInstance As Integer, ByVal ThePort As Integer, ByVal TheOutcome As Boolean)
                    Gave me a runtime error for DigitalOutStatus - something about needing an explicit call to the class or something. googled it, without finding a definite answer, but "Shared" seemed to be the issue - Removed Shared & problem went away (may be an issue with multiple forms later, I'll deal with that when it comes up.

                    I'm having a little trouble with the analog inputs.
                    In the timer_tick, I'm updating 2 labels using label1.text=cstr(analogInRaw(1, 0)) (instance, port). When I start the program, the label cycles between 0 and a random number (Seemingly at the 250ms timer rate) for 4-5 cycles, then settles at 0 (sometimes it stays at 0 from the beginning, sometimes it will re-cycle if I jiggle the connector).
                    I've tried 3 different temp sensors (2 that came with my v6 brain & 1 that came with v4 - I know it's for 5V) and shorting between +++ and AIN+. I've tried (0,0) (0,1) & (1,1) and I've tested the 1st 2 ports on each side of the group (I thought port0 was closest to USB connector, but I can't tell the difference due to how it's acting). I had a similar issue trying to read an analog in with FuseGL, so it could be a hardware problem, but I still suspect ID10T error.
                    mp3Car.com Senior Tech Blogger (Want a product reviewed? Contact me.)
                    Follow Me on Twitter or Facebook
                    Live mp3Car Facebook Chat

                    Comment


                    • #11
                      random is probably not the correct term to use.

                      I looks like it is reading a value, but it is not stable at all & A) jumps around, B) eventually settles to 0 (less than 2sec, sometimes less than 1 or immediately).

                      Either I'm interpreting what the Ain is sending (and recording in the array) OR there is something wrong with both of my v6 brains. I doubt #2, but I can't rule it out yet.
                      Multimeter needs a battery & I need to get some resistors from home to make a definite test & see what is going on.

                      Comment


                      • #12
                        Remember if there is nothing there, then the reading is undetermined for the analogue inputs. Once you connect something, it is different. But floating nodes are unpredictable by nature.
                        Fusion Brain Version 6 Released!
                        1.9in x 2.9in -- 47mm x 73mm
                        30 Digital Outputs -- Directly drive a relay
                        15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
                        Buy now in the MP3Car.com Store

                        Comment


                        • #13
                          Originally posted by 2k1Toaster View Post
                          Remember if there is nothing there, then the reading is undetermined for the analogue inputs. Once you connect something, it is different. But floating nodes are unpredictable by nature.
                          Just put FuseGL on work PC & it works as expected (assuming .8V is room temperature, it goes up if I the ssr up) & my port selection was correct.

                          I don't understand what is going on with this line:

                          Code:
                          Dim aValue_INT As Integer = ((_AllAnalogues(a) And &H3) << 8) + _AllAnalogues(a + 1)
                          doesn't seem to be picking anything up when I put a break there & step through the loop. when a=0, _AllAnalogues(a) = 128 & &H3=3 & a+0=0, but the result is aValue_INT=0 (I have no idea what most of this line says and 128 = .42V, FuseGL reports the temp ssr as .8v)

                          What does <<8 mean?
                          If i step through, _AllAnalogues(a) increments by 4 each time through the loop, but aValue_INT never gets a value other than 0

                          Comment


                          • #14
                            Originally posted by Iamthehor View Post
                            Just put FuseGL on work PC & it works as expected (assuming .8V is room temperature, it goes up if I the ssr up) & my port selection was correct.

                            I don't understand what is going on with this line:

                            Code:
                            Dim aValue_INT As Integer = ((_AllAnalogues(a) And &H3) << 8) + _AllAnalogues(a + 1)
                            doesn't seem to be picking anything up when I put a break there & step through the loop. when a=0, _AllAnalogues(a) = 128 & &H3=3 & a+0=0, but the result is aValue_INT=0 (I have no idea what most of this line says and 128 = .42V, FuseGL reports the temp ssr as .8v)

                            What does <<8 mean?
                            If i step through, _AllAnalogues(a) increments by 4 each time through the loop, but aValue_INT never gets a value other than 0
                            0.8v is slightly colder than room temp. (0.8-0.4) / 0.0195 ~= 20C or 68F-70F

                            "<<" is "left shift". So if you have 0b00000010 (0x02) and you left shift by 1 ( << 1), you will get 0b00000100 (0x04). Do it again and you get 0b00001000 (0x08). The ADC is 10bits in the Fusion Brain. A byte only holds 8bits. So you need to store 1 10 bit value in 2 bytes and then combine them.

                            My code for analogues:

                            Code:
                               int aValue_INT = ((readInArray[(i * 1) + (j * 2) + 0] & 0x03) << 8) + readInArray[(i * 1) + (j * 2) + 1];
                               double aValue_DBL = (this.fusionBrain_version.VREF * ((double)aValue_INT) / (double)this.fusionBrain_version.ANALOGUE_INPUT_MAXVAL);
                            Fusion Brain Version 6 Released!
                            1.9in x 2.9in -- 47mm x 73mm
                            30 Digital Outputs -- Directly drive a relay
                            15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
                            Buy now in the MP3Car.com Store

                            Comment


                            • #15
                              My brain just exploded. You lost me on the byte stuff (other than the 10bits can't fit in a byte....)

                              With this:
                              Code:
                                      For x = 1 To TotalInstances ' loops through all FB instances connected
                                          FusionBrain_WinUSB.MainUSBClass.allFusionBrains(FusionBrain_WinUSB.MainUSBClass.allFusionBrains.Count - 1).ReadDataFromFusionBrain(_AllAnalogues, &H2)
                                          Dim i As Integer
                                          For a As Integer = 0 To 15 * 2 - 1 Step 2
                                              Dim aValue_INT As Integer = ((_AllAnalogues(a) And &H3) << 8) + _AllAnalogues(a + 1)
                                              ' The raw 0 through 1023 digital value
                                              ' Converting that value to a real voltage and storing in some temp List
                              
                                              AnalogInRaw(x, i) = aValue_INT 'provides the raw data analog input values from VB
                                              AnalogInVoltage(x, i) = (3.3 * CDbl(aValue_INT) / 1023.0) 'converts the raw data to voltage form
                                              i = i + 1
                                          Next
                                      Next
                              
                                      Label3.Text = CStr(AnalogInRaw(1, 0))
                                      Label4.Text = Microsoft.VisualBasic.Left(CStr(AnalogInVoltage(1, 0)), 4)
                              After unplugging/reconnecting the brain, I get the correct raw & voltage (~0.81V) for ~10sec, then it steps to 0, holds for ~5sec, then returns to 0.81, then sometimes steps down & right back up)
                              there's a pattern there, I just don't know what it is. So something in the loop stepping must be off.
                              It also seems that the 'correct' reading doesn't change without resetting the brain - I can run the program, let it step up/down a couple times & put the ssr in my jacket & the 'correct' reading doesn't change. Unplug/reconnect & the next 'correct' reading is higher, and so on.

                              In the ReadDataFromFusionBrain, the end byte is &H2, but in the other line I don't get, the byte is &H3. Typo? Changing them to match didn't seem to affect it.

                              Comment

                              Working...
                              X