Thank you -- that is EXACTLY what I was looking for![]()
Ok, the credit goes to Brain Wendt who was kind enough last July to ask me all sorts of questions and compile this excellent document on the low level protocol. I think he is planning something big with his own software so he has been in the dark recently, but thank him for this
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
Thank you -- that is EXACTLY what I was looking for![]()
I'd like to access the fusion brain directly from a program I'm developing in Visual Basic 2008 Express. I've found that VB doesn't like the FusionUSB.dll file. If I try to add it as a reference, I get an error that it can't be added saying to make sure that it is "a valid assembly or COM component". Do you have any ideas what I have for options to make this work. Thanks.
Dont add it as a reference. Just call it.
Here is the sample code for all calls to the dll incase you dont have it:
Code:[System.Runtime.InteropServices.DllImport("FusionUSB.dll")] public static extern bool FUSB_Initialize(ref UInt32 pFusionUSB, String deviceID, UInt32 instanceNumber); [System.Runtime.InteropServices.DllImport("FusionUSB.dll")] public static extern bool FUSB_Receive(UInt32 pFusionUSB, byte[] buffer); [System.Runtime.InteropServices.DllImport("FusionUSB.dll")] public static extern bool FUSB_Send(UInt32 pFusionUSB, byte[] buffer); [System.Runtime.InteropServices.DllImport("FusionUSB.dll")] public static extern UInt32 FUSB_Free(ref UInt32 pFusionUSB); [System.Runtime.InteropServices.DllImport("FusionUSB.dll")] public static extern bool FUSB_printf(UInt32 pFusionUSB); [System.Runtime.InteropServices.DllImport("FusionUSB.dll")] public static extern UInt32 FUSB_GetWinUSBerror(UInt32 pFusionUSB); [System.Runtime.InteropServices.DllImport("FusionUSB.dll")] public static extern UInt32 FUSB_GetFUSBstatus(UInt32 pFusionUSB); [System.Runtime.InteropServices.DllImport("FusionUSB.dll")] public static extern String FUSB_GetDeviceInstanceID(UInt32 pFusionUSB);
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
Thanks for the speedy reply. I converted the code you posted to VB. For future reference for anyone else, here is what that looks like:
The functions look self explanatory as to what they do. The word document you put in reply # 11 explains the data stream to and from the FB. I am confused about the FUSB_GetDeviceInstanceID funtion though. When I run the above code, I get a message box saying "NULL", even with the FB is on. I presume this should be giving me the string I'll need to initialize the device with the FUSB_Initialize function.Code:Public Class UCSettingsIO <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 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim thefbinstid As String = FUSB_GetDeviceInstanceID(0) MsgBox(thefbinstid) End Sub End Class
if you bass in a pointer, as well as an UInt, it should give you the id of the Brain at instance number UInt#.
I actually dont use it. It was more for testing.
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
I'm confused. That function only has one argument, so how do I pass both a pointer and the UInt to it?
Oh, I am sorry. I was thinking of the wrong function.
Yes it returns a string which you pass into Initialize. The UInt you put in would be 0 for Brain #1 and 1 for Brain #2 and so on.
There is an old dll call that took in a pointer and it called the initialize automatically but was too hard to debug so it changed.
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
For now, I skipped the FUSB_GetDeviceInstanceID function since I do know the ID. I'm trying to make the software turn digital output #0 on and off. I have a form with 3 buttons. One initializes the FB, one sets digout0 to "1" and the other sets digout0 to "0". I have a timer running at 10Hz on another form that is calling the SendDataToFusionBrain() subroutine. Here's my code, excluding the code you previously posted that calls the DLL.
I am unable to get Digital Output #0 to turn on or off.Code:Private TimeForShutoff As String = "000000" Private KeepAliveBit As String Private DigOut0 As String Private OutputArray(64) As Byte Private Sub InitFB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InitFB.Click Dim thefbinstid As String = "USB\VID_04D8&PID_000C\4&338F3FFA&0&1" If FUSB_Initialize(0, thefbinstid, 0) Then MsgBox("Fusion Brain was initialized.") MainForm.SteeringControlEnabled = True Else MsgBox("Failed to initialize that Fusion Brain. Make sure it is connected and that you are specifying the correct USB ID number.") End If For i = 0 To 63 OutputArray(i) = CByte("00000000") Next KeepAliveBit = "1" DigOut0 = "1" End Sub Private Sub Turn0on_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Turn0on.Click DigOut0 = "1" End Sub Private Sub Turn0off_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Turn0off.Click DigOut0 = "0" End Sub Public Sub SendDataToFusionBrain() OutputArray(0) = CByte(TimeForShutoff & KeepAliveBit & DigOut0) OutputArray(1) = CByte(TimeForShutoff & KeepAliveBit & "0") OutputArray(2) = CByte(TimeForShutoff & KeepAliveBit & "0") OutputArray(3) = CByte(TimeForShutoff & KeepAliveBit & "0") OutputArray(4) = CByte(TimeForShutoff & KeepAliveBit & "0") OutputArray(5) = CByte(TimeForShutoff & KeepAliveBit & "0") OutputArray(6) = CByte(TimeForShutoff & KeepAliveBit & "0") OutputArray(7) = CByte(TimeForShutoff & KeepAliveBit & "0") OutputArray(8) = CByte(TimeForShutoff & KeepAliveBit & "0") OutputArray(9) = CByte(TimeForShutoff & KeepAliveBit & "0") OutputArray(10) = CByte(TimeForShutoff & KeepAliveBit & "0") OutputArray(11) = CByte(TimeForShutoff & KeepAliveBit & "0") FUSB_Send(0, OutputArray) 'Reset the keepalive bit for nexttime. If KeepAliveBit = "0" Then KeepAliveBit = "1" Else KeepAliveBit = "0" End If End Sub
If I run FUSB_GetFUSBstatus(0), it returns 1
If I run FUSB_Free(0) returns 50, it returns 50
I have downloaded your source code for the fusion control centre, and I'm looking at it in VS C# Express, but I'm unable to find anything that I'm missing to make it simply turn one output on and off. Any ideas?
The flip flop bit of the output has to go between 1 and 0 every transmission. Also byte number 61 must be all 255.
And you cannot skip Initialize. It has to create a File Handle, if it doesnt nothing will work. If you get 50 back from Free, that means there was nothing to free, so nothing was initialized, so nothing will work.
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
Bookmarks