Here is the code I'm using in VB2008 Express.
Code:<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 Public VIDPID As String = "" Dim Uint0 As UInt32 = Convert.ToUInt32(0) 'Uint representing zero Private KeepAliveBit As Integer Private OutputArray(64) As Byte Private InputArray(64) As Byte Private DigOut(12) As Integer Public AnalogIn(10) As Integer Public Sub LoadVIDPIDfromRegistry(ByRef textbox As TextBox) Dim location As String = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinUSB\Enum" Dim storedvidpid As String = My.Computer.Registry.GetValue(location, "0", Nothing) If storedvidpid = Nothing Then MsgBox("VID/PID for device #0 not found in the registry. Are the Fusion Brain drivers loaded?") Else MsgBox("The following VID/PID was found:" & vbCrLf & vbCrLf & storedvidpid) VIDPID = storedvidpid End If End Sub Public Sub FB_Connect() 'Check the status to see if it is already connected Try If FUSB_GetFUSBstatus(Uint0) = 0 Then 'Status is 0, meaning it is already connected. Can't connect it again. Else 'Status isn't 0, lets try to connect to the Fusion Brain FUSB_Free(Uint0) If FUSB_Initialize(Uint0, VIDPID, Uint0) Then 'Init was successful For i = 0 To 63 OutputArray(i) = CByte(0) Next OutputArray(61) = CByte(255) 'This is needed to wake up the FB, for firmwares after November 2007 For i = 0 To 11 DigOut(i) = 0 Next FUSB_Send(Uint0, OutputArray) If (FUSB_Receive(Uint0, InputArray)) Then lblFirmwareVersion.Text = InputArray(63).ToString & "." & InputArray(62).ToString End If KeepAliveBit = 1 'Start the timer for sending data to the FB Timer.Start() Else MsgBox("Failed to initialize that Fusion Brain. Make sure it is connected and that you are specifying the correct USB VID/PID number." & vbCrLf & vbCrLf & "The VID/PID specified was: " & VIDPID) End If End If Catch ex As Exception MsgBox("Error: DLL not found. Are you sure the fusion brain drivers are installed and the FusionUSB.dll file is in the same folder as the .exe?" & vbCrLf & vbCrLf & "The reported error is:" & vbCrLf & ex.ToString) End Try End Sub Public Sub FB_Disconnect() 'This gets called from the MyBase.FormClosed event as the app closes 'Disable timer, Set all outputs to off, send data to the FB one last time, then disconnect from the FB Timer.Stop() For i = 0 To 11 DigOut(i) = 0 OutputArray(i) = Convert.ToByte(0 & KeepAliveBit & 0) Next FUSB_Send(Uint0, OutputArray) FUSB_Free(Uint0) End Sub Public Sub FB_SendReceive() 'This sub is called from a Timer_Tick event, which runs at 10Hz. DigOut(0) = 1 DigOut(1) = 0 DigOut(2) = 0 DigOut(3) = 0 DigOut(4) = 0 DigOut(5) = 0 DigOut(6) = 0 DigOut(7) = 0 DigOut(8) = 0 DigOut(9) = 0 DigOut(10) = 0 DigOut(11) = 0 For i = 0 To 11 OutputArray(i) = Convert.ToByte(0 & KeepAliveBit & DigOut(i)) Next FUSB_Send(Uint0, OutputArray) 'Now, get the info from the fusion brain If (FUSB_Receive(Uint0, InputArray)) Then 'It retured true, meaning it got data. Process it. For i = 0 To 9 AnalogIn(i) = CInt(InputArray(i * 2 + 12)) 'Uses only the first byte 0-255 (8 bits) 'AnalogIn(i) = (CInt(InputArray(i * 2 + 12)) * 4) + CInt(InputArray(i * 2 + 13) / 64) 'Uses both bytes 0-1023 (10 bits) 'Range of 0-255, so divide by 255 to get a percent, then multiply by 5 to get volts. 'AnalogIn(i) = (totalin / 1023) * 5 Next End If 'Toggle the keepalive bit for nexttime. If KeepAliveBit = 0 Then KeepAliveBit = 1 Else KeepAliveBit = 0 End If End Sub



LinkBack URL
About LinkBacks
Reply With Quote


But it works as long as you dont hang it.
:



Bookmarks