Page 1 of 4 1234 LastLast
Results 1 to 10 of 38

Thread: FB v6 & Visual Basic

  1. #1
    Constant Bitrate
    Join Date
    Jun 2004
    Posts
    152

    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. #2
    Mo' Programming Mo' Problems
    Auto Apps:loading...
    Sonicxtacy02's Avatar
    Join Date
    Sep 2004
    Location
    Woodbridge, VA
    Posts
    8,169
    Blog Entries
    53
    Quote 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.)
    Find my plugins on the MP3Car App Store!
    Follow Me on Twitter or Facebook
    Live mp3Car Facebook Chat

  3. #3
    Constant Bitrate
    Join Date
    Jun 2004
    Posts
    152
    Quote 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.

  4. #4
    Mo' Programming Mo' Problems
    Auto Apps:loading...
    Sonicxtacy02's Avatar
    Join Date
    Sep 2004
    Location
    Woodbridge, VA
    Posts
    8,169
    Blog Entries
    53
    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.)
    Find my plugins on the MP3Car App Store!
    Follow Me on Twitter or Facebook
    Live mp3Car Facebook Chat

  5. #5
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    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

  6. #6
    Mo' Programming Mo' Problems
    Auto Apps:loading...
    Sonicxtacy02's Avatar
    Join Date
    Sep 2004
    Location
    Woodbridge, VA
    Posts
    8,169
    Blog Entries
    53
    Quote 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.)
    Find my plugins on the MP3Car App Store!
    Follow Me on Twitter or Facebook
    Live mp3Car Facebook Chat

  7. #7
    Constant Bitrate
    Join Date
    Jun 2004
    Posts
    152
    Quote 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.

    Quote 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.

  8. #8
    Mo' Programming Mo' Problems
    Auto Apps:loading...
    Sonicxtacy02's Avatar
    Join Date
    Sep 2004
    Location
    Woodbridge, VA
    Posts
    8,169
    Blog Entries
    53
    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 Attached Files
    Last edited by Sonicxtacy02; 12-20-2011 at 10:24 AM.
    mp3Car.com Senior Tech Blogger (Want a product reviewed? Contact me.)
    Find my plugins on the MP3Car App Store!
    Follow Me on Twitter or Facebook
    Live mp3Car Facebook Chat

  9. #9
    Constant Bitrate
    Join Date
    Jun 2004
    Posts
    152
    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.

  10. #10
    Mo' Programming Mo' Problems
    Auto Apps:loading...
    Sonicxtacy02's Avatar
    Join Date
    Sep 2004
    Location
    Woodbridge, VA
    Posts
    8,169
    Blog Entries
    53
    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.

    Quote 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.)
    Find my plugins on the MP3Car App Store!
    Follow Me on Twitter or Facebook
    Live mp3Car Facebook Chat

Page 1 of 4 1234 LastLast

Similar Threads

  1. Visual Basic on a Mac
    By sdashiki in forum MacCar
    Replies: 6
    Last Post: 06-08-2005, 04:08 PM
  2. OBD-II and Visual Basic
    By nicgalla in forum Engine Management, OBD-II, Engine Diagnostics, etc.
    Replies: 10
    Last Post: 05-16-2005, 06:46 PM
  3. Visual Basic & LCD
    By farolfo in forum Software & Software Development
    Replies: 2
    Last Post: 04-28-2004, 01:03 PM
  4. Wmp for Visual Basic
    By Bj in forum Software & Software Development
    Replies: 0
    Last Post: 11-10-2003, 09:07 AM
  5. Visual Basic?
    By pinkysqueaks in forum Software & Software Development
    Replies: 2
    Last Post: 06-25-2001, 12:08 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •