Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Help with .net code for FB

  1. #1
    Low Bitrate erie's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    89

    Help with .net code for FB

    Using the .Net 2005 Studio and the code that I copied from Arrow, here) I can use the FUSB_Initialize command and I get a unique pointer, I can use the FUSB_Free command and I get a 0 if the device was opened, and a 50 if I click it again. So I know that I am talking to the device. But whenever I send the "USBIO.FUSB_Send(Uint0, OutChunks)" the program just hangs and I have to force it close. If I use FCC.exe I can turn on and off the DigOut ports, the board it tested OK. I'm at work right now so I cant post the code, but it is the same as Arrow's (thank you Arrow. I am using VS 2005 Sp1, XP Pro Sp2. I am a newb to .net, but I figured this is a great opportunity to learn
    06 Galaxy Gray Si #0308
    CarPc Progress -
    10%---------50%---------100%
    -[XXXXXXXXXXXXXXXXXXXXXX]-

  2. #2
    Variable Bitrate Arrow's Avatar
    Join Date
    Feb 2006
    Location
    West Lafayette, IN
    Posts
    288
    Sounds like you are able to establish a pointer, but not actually communicate properly with the board. There is one more step that was not included in my code. Maybe you are missing that. You need to have another routine somewhere that sets each of the onOffBit variables to either 1 or 0 and then calls SendDataBlock(). Maybe without that, the onOffBits are not the correct values and the Brain or drivers don't know what to do.

  3. #3
    Low Bitrate erie's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    89
    This should look familiar. Per your advice, on FormLoad I set all the values of OnOffBit(j) to 0. Still the same result. I've attached the code, hoping that you could spot my error. Thanks for your help

    Code:
        
        Dim FlipFlop As Boolean = True    'Keep-alive for brain
        Dim OutChunks(64) As Byte   'Bytes for 64bit data chunk being sent to brain
        Dim OnOffBit(12) As Integer 'Bit to turn on or off an output
        Dim Uint0 As UInt32 = Convert.ToUInt32(0)   'Uint representing zero
        Dim VIDPID As String = "USB\VID_04D8&PID_000C\5&2C65B59D&0&1"
    Code:
      
        Public Sub SendDataBlock()
    
            If Uint0 = 0 Then      'only Init once
                If USBIO.FUSB_Initialize(Uint0, VIDPID, Uint0) Then  'Initialize Device
                    Debug.WriteLine("Initialized: " & Convert.ToString(Uint0))
                Else
                    Debug.WriteLine("Error Initializing: " & Convert.ToString(Uint0))
                End If
            Else
                Debug.WriteLine("Already Initializing: " & Convert.ToString(Uint0))
            End If
    
            'Clear ByteBlock
            Dim cnt As Integer
            For cnt = 0 To 63
                OutChunks(cnt) = 0
            Next
    
            'Convert FlipFlop Boolean to an integer
            Dim KeepAlive As Integer = Convert.ToInt32(FlipFlop)
            Dim i As Integer
            For i = 0 To 11
                OutChunks(i) = Convert.ToByte(0 & KeepAlive & OnOffBit(i))
            Next
            OutChunks(61) = Convert.ToByte(255)     'wake up PIC
    
            USBIO.FUSB_Send(Uint0, OutChunks)
    
            FlipFlop = Not FlipFlop  'Flip keepalive bit
    
        End Sub
    
    
        Private Sub btn0on_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0on.Click
            OnOffBit(0) = 1 'Turn Output on
            SendDataBlock()
        End Sub
    
        Private Sub btn0off_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0off.Click
            OnOffBit(0) = 0 'Turn Output off
            SendDataBlock()
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim j As Integer
            For j = 0 To 11 'need to fill a value for all dig outs
                OnOffBit(j) = 0
            Next
        End Sub
    
        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            USBIO.FUSB_Free(Uint0)
        End Sub
    06 Galaxy Gray Si #0308
    CarPc Progress -
    10%---------50%---------100%
    -[XXXXXXXXXXXXXXXXXXXXXX]-

  4. #4
    Newbie
    Join Date
    Feb 2008
    Posts
    9
    It hangs because that DLL is borked. The second (and often first) call to FUSB_Send will hang, as you've said. All will work provided you first do a read first. Waste of time but at least it works. So before you start setting your On/Off bits on the array do a read and all will be ok. One additional cosmetic detail is that your array is actually 65 elements long. Won't hurt anything, just not tidy. Apparently in VB you declare last index of the array not length.

    HTH
    Also, I still don't know what that deal with this flippity floppy thing is, just set your keep-alive bit when you want the output on (together with bit 0 set to 1) and don't set it when turning output off. Otherwise if you get your order switched somehow and don't set the keepalive bit when the button is supposed to stay on, it won't.

  5. #5
    Low Bitrate erie's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    89
    AtomicMonkey - That was it, if I do a USBIO.FUSB_Receive first and all the USBIO.FUSB_Send commands complete without any problems. Thanks for the tip on the keep-alive. Its a good thing to able to talk to the brain. Thanks
    06 Galaxy Gray Si #0308
    CarPc Progress -
    10%---------50%---------100%
    -[XXXXXXXXXXXXXXXXXXXXXX]-

  6. #6
    Maximum Bitrate galvitron's Avatar
    Join Date
    Mar 2007
    Location
    Socal
    Posts
    719
    It hangs because that DLL is borked.
    Best line ever.
    2006 Lancer Evolution IX MR In-Dash PC Project - WIP

    Planning:
    [----------] 100%
    Purchasing:
    [----------] 90%
    Installation/Fab/Assembly (Revised v2):
    [----------] 90%


  7. #7
    Variable Bitrate Arrow's Avatar
    Join Date
    Feb 2006
    Location
    West Lafayette, IN
    Posts
    288
    Hmm... I flippity floppity that bit all day long and my stuff works like a charm.

  8. #8
    Variable Bitrate Arrow's Avatar
    Join Date
    Feb 2006
    Location
    West Lafayette, IN
    Posts
    288
    Actually, If i don't flippity floppity that bit, the brain works like it's supposed to and shuts itself off.

  9. #9
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    9,851
    Quote Originally Posted by Arrow View Post
    Actually, If i don't flippity floppity that bit, the brain works like it's supposed to and shuts itself off.


    That is the supposed function of the Fusion Brain.
    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

  10. #10
    Newbie
    Join Date
    Feb 2008
    Posts
    9
    Toaster I realize that is the function, what I'm saying this flipping does not appear necessary for the the function to function. The timer will shut the output off with or without the keep-alive set (matter of timing), though w/o it timer will not reset on subsequent same state write, but if always sending 3 + timer for ON and 0 + timer for OFF does the same exact thing: output will shut off after timer expired with no state confirmation sent.
    Ok, my apologies for spreading crap information. Appears the timer in fact will not reset if u sent same value before it expires.

Page 1 of 2 12 LastLast

Similar Threads

  1. GPS/MapPoint VB Source Code
    By stevieg in forum Software & Software Development
    Replies: 7
    Last Post: 01-28-2011, 04:59 PM
  2. Weird Registration Code and Hardware Code problem
    By lookinco in forum StreetDeck
    Replies: 2
    Last Post: 09-30-2006, 03:25 AM
  3. Replies: 0
    Last Post: 06-11-2006, 06:49 PM
  4. How do I use the Base plugin sources ?
    By guino in forum RR FAQ
    Replies: 1
    Last Post: 04-24-2006, 04:43 PM
  5. .NET code for OBD-II ?
    By Jeep in forum Engine Management, OBD-II, Engine Diagnostics, etc.
    Replies: 6
    Last Post: 05-09-2005, 11:44 AM

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
  •