Page 3 of 8 FirstFirst 12345678 LastLast
Results 21 to 30 of 76

Thread: Sdk?

  1. #21
    Constant Bitrate mx270a's Avatar
    Join Date
    Aug 2003
    Location
    Iowa
    Posts
    167
    The FUSB_Free(0) command always returns 50. I can run it before the init, after the init, twice in a row, etc. Haven't gotten it to return anything other than 50. My understanding is that this should be the very first command that is run, correct?

    When I run FUSB_Initialize(0, thefbinstid, 0) with the correct USB string, it returns 'True'. If I run it again, it will return 'False'. If I run the command with a different USB string, it returns 'False' both times.

    I set 61 to 255, but that hasn't changed anything. I think my problem lies in getting a connection open to the FB, so whatever the data stream is doesn't matter yet.

  2. #22
    Variable Bitrate Arrow's Avatar
    Join Date
    Feb 2006
    Location
    West Lafayette, IN
    Posts
    288
    I'm doing something very similar, but FUSB_Free was returning 0 for me. I would initialize just fine as soon as my program started but there was still no response from the board. Now after playing with it for a bit, I launched the Control Centre to make sure that it was even able to control the boad. It was. The when I went back to my app, FUSB_Free started returning 50 every time. Can't get it to go back to zero. I'm still able to initialize, but still nothing works.

  3. #23
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    Try to unplug/replug. If the file handle didn't clear, then only the program that started it, will be able to use it. So if you unplug it, window's automatic garbage collection will destroy the handle, and you can make a new one.

    And @mx, no it is the last command you run. It frees the handle. You initialize, you do your communicating, then you free it.

    Also I just saw in your code, you have Initialize(0,id,0). The dll is trying to pass in a file handle pointer to "0" (the first parameter). You cannot do that. That first parameter is the pointer you must use throughout the rest of the communications.
    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

  4. #24
    Variable Bitrate Arrow's Avatar
    Join Date
    Feb 2006
    Location
    West Lafayette, IN
    Posts
    288
    Now I have something working, but I need to mess with my data because it's turning All the outputs on and off. The trick is to initialize, send data, then free. Do this every time you send data.

  5. #25
    Variable Bitrate Arrow's Avatar
    Join Date
    Feb 2006
    Location
    West Lafayette, IN
    Posts
    288
    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(10) 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&39E0BBF6&0&1"
    Code:
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            'Turn Output on
            OnOffBit(0) = 1
            SendDataBlock()
        End Sub
    
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            'Turn Output off
            OnOffBit(0) = 0
            SendDataBlock()
        End Sub
    
        Public Sub SendDataBlock()
    
            'Initialize Device
            If USBIO.FUSB_Initialize(Uint0, VIDPID, Uint0) Then
                Debug.WriteLine("Initialized")
            Else
                Debug.WriteLine("Error Initializing")
            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)
    
            OutChunks(0) = Convert.ToByte(0 & KeepAlive & OnOffBit(0))
            OutChunks(1) = Convert.ToByte(0 & KeepAlive & OnOffBit(0))
            OutChunks(2) = Convert.ToByte(0 & KeepAlive & OnOffBit(0))
            OutChunks(3) = Convert.ToByte(0 & KeepAlive & OnOffBit(0))
            OutChunks(4) = Convert.ToByte(0 & KeepAlive & OnOffBit(0))
            OutChunks(5) = Convert.ToByte(0 & KeepAlive & OnOffBit(0))
            OutChunks(6) = Convert.ToByte(0 & KeepAlive & OnOffBit(0))
            OutChunks(7) = Convert.ToByte(0 & KeepAlive & OnOffBit(0))
            OutChunks(8) = Convert.ToByte(0 & KeepAlive & OnOffBit(0))
            OutChunks(9) = Convert.ToByte(0 & KeepAlive & OnOffBit(0))
            OutChunks(10) = Convert.ToByte(0 & KeepAlive & OnOffBit(0))
            OutChunks(11) = Convert.ToByte(0 & KeepAlive & OnOffBit(0))
            OutChunks(61) = Convert.ToByte(255)
            USBIO.FUSB_Send(Uint0, OutChunks)
    
            'Flip keepalive bit
            FlipFlop = Not FlipFlop
    
            Debug.WriteLine(OutChunks(0))
            Debug.WriteLine("USBFREE: " & USBIO.FUSB_Free(Uint0).ToString & "; USBStatus: " & USBIO.FUSB_GetFUSBstatus(Uint0).ToString)
    
        End Sub
    Using only the above code, I was able to get some things working, but as posted above this turns ALL the outputs on and off.. Still need to figure out why.

  6. #26
    Variable Bitrate Arrow's Avatar
    Join Date
    Feb 2006
    Location
    West Lafayette, IN
    Posts
    288
    Oh.. Duh! I never changed the index numbers of the OnOffBit array when I copied/pasted them in each line!

    Here.. This code works!

    Code:
    Public Class USBIO
        <System.Runtime.InteropServices.DllImport("FusionUSB.dll")> _
        Public Shared Function FUSB_Initialize(ByRef pFusionUSB As UInt32, ByVal deviceID As String, ByVal instanceNumber As UInt32) As Boolean
        End Function
    
        <System.Runtime.InteropServices.DllImport("FusionUSB.dll")> _
        Public Shared Function FUSB_Receive(ByVal pFusionUSB As UInt32, ByVal buffer As Byte()) As Boolean
        End Function
    
        <System.Runtime.InteropServices.DllImport("FusionUSB.dll")> _
        Public Shared Function FUSB_Send(ByVal pFusionUSB As UInt32, ByVal buffer As Byte()) As Boolean
        End Function
    
        <System.Runtime.InteropServices.DllImport("FusionUSB.dll")> _
        Public Shared Function FUSB_Free(ByRef pFusionUSB As UInt32) As UInt32
        End Function
    
        <System.Runtime.InteropServices.DllImport("FusionUSB.dll")> _
        Public Shared Function FUSB_printf(ByVal pFusionUSB As UInt32) As Boolean
        End Function
    
        <System.Runtime.InteropServices.DllImport("FusionUSB.dll")> _
        Public Shared Function FUSB_GetWinUSBerror(ByVal pFusionUSB As UInt32) As UInt32
        End Function
    
        <System.Runtime.InteropServices.DllImport("FusionUSB.dll")> _
        Public Shared Function FUSB_GetFUSBstatus(ByVal pFusionUSB As UInt32) As UInt32
        End Function
    
        <System.Runtime.InteropServices.DllImport("FusionUSB.dll")> _
        Public Shared Function FUSB_GetDeviceInstanceID(ByVal pFusionUSB As UInt32) As String
        End Function
    End Class
    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&39E0BBF6&0&1"
    Code:
    Public Sub SendDataBlock()
    
            'Initialize Device
            If USBIO.FUSB_Initialize(Uint0, VIDPID, Uint0) Then
                Debug.WriteLine("Initialized")
            Else
                Debug.WriteLine("Error Initializing")
            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)
    
            OutChunks(0) = Convert.ToByte(0 & KeepAlive & OnOffBit(0))
            OutChunks(1) = Convert.ToByte(0 & KeepAlive & OnOffBit(1))
            OutChunks(2) = Convert.ToByte(0 & KeepAlive & OnOffBit(2))
            OutChunks(3) = Convert.ToByte(0 & KeepAlive & OnOffBit(3))
            OutChunks(4) = Convert.ToByte(0 & KeepAlive & OnOffBit(4))
            OutChunks(5) = Convert.ToByte(0 & KeepAlive & OnOffBit(5))
            OutChunks(6) = Convert.ToByte(0 & KeepAlive & OnOffBit(6))
            OutChunks(7) = Convert.ToByte(0 & KeepAlive & OnOffBit(7))
            OutChunks(8) = Convert.ToByte(0 & KeepAlive & OnOffBit(8))
            OutChunks(9) = Convert.ToByte(0 & KeepAlive & OnOffBit(9))
            OutChunks(10) = Convert.ToByte(0 & KeepAlive & OnOffBit(10))
            OutChunks(11) = Convert.ToByte(0 & KeepAlive & OnOffBit(11))
            OutChunks(61) = Convert.ToByte(255)
            USBIO.FUSB_Send(Uint0, OutChunks)
    
            'Flip keepalive bit
            FlipFlop = Not FlipFlop
    
            USBIO.FUSB_Free(Uint0)
    
        End Sub
    Just set your OnOffBit variables to 1 or 0 then call SendDataBlock. All the corresponding 1s will turn on and the 0s will turn off.

    I'm so happy right now! Thank you again Toaster for your amazing work!

  7. #27
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    OnOffBit(0) should be OnOffBit(i)
    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

  8. #28
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    Quote Originally Posted by Arrow View Post
    Oh.. Duh! I never changed the index numbers of the OnOffBit array when I copied/pasted them in each line!
    I guess you found it.


    Also If you initialize and free everytime, it is a lot of wasted time. Keep a global pointer to it. So initialize once, then do everything and free once. Much faster.
    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

  9. #29
    Variable Bitrate Arrow's Avatar
    Join Date
    Feb 2006
    Location
    West Lafayette, IN
    Posts
    288
    Not sure what you mean. Are you saying I could initialize, trigger separate outputs at separate times, then free it when I'm done?

  10. #30
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    I mean just like in the changedevice() in my program.

    Everytime call some function to check your instance pointer. If it is 0, then not initialized, so initialize it. If it is not 0, then it has been initialized, so do nothing.

    Then read/write whenever.

    Make an event for when the program closes, to free it.

    Those windows handles are slow to initialize, and it is slower the more USB devices connected, because it has to check each one to see which is the Brain and which is your printer or whatever.
    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

Page 3 of 8 FirstFirst 12345678 LastLast

Similar Threads

  1. iGuidance SDK
    By Quattro in forum GPS
    Replies: 57
    Last Post: 06-23-2006, 08:37 AM
  2. SDK commands over the serial port ????
    By tolisn in forum Road Runner
    Replies: 4
    Last Post: 12-14-2005, 01:03 PM
  3. Developing Touchscreen SDK -- need feedback!
    By kevlar in forum Software & Software Development
    Replies: 3
    Last Post: 07-14-2005, 06:55 PM
  4. Replies: 9
    Last Post: 03-31-2005, 03:40 AM
  5. Destinator 3 SDK features working
    By loscooby in forum GPS
    Replies: 4
    Last Post: 09-21-2004, 01:46 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
  •