Results 1 to 9 of 9

Thread: Interfacing custom software with the Fusion Brain

  1. #1
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049

    Interfacing custom software with the Fusion Brain

    The Fusion Brain interfaces with the computer using USB. To get the datastream to start flowing, you must initialize the device first, then you can send and receive data packets, and when you are done with the device you must free it.

    The data packets are 64 bytes in length, and information on the encoding of the byte stream can be found here: http://www.mp3car.com/vbulletin/docu...-protocol.html
    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

  2. #2
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049

    C# -- DLL Interface

    1.) Call FUSB_Initialize() --. pFusionUSB is the Uint32 pointer to the USB handle. It is 0 when not initialized. deviceID is the full string of the PID/VID including the hardware ID. instanceNumber should be 0. If it returns true, it was initialized successfully.

    2.) Call FUSB_Send() and FUSB_Receive(). FUSB_Send takes an array of 64 bytes. FUSB_Receive returns an array of bytes 64 long.

    3.) Once you are all done, call FUSB_Free() and pass in the pointer you used to initialize to free it. If it returns 0, then it was freed successfully.


    Code:
    public static class FusionUSB
            {
    
                [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

  3. #3
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049

    VB -- DLL Interface Thanks to mx270a

    I converted the code you posted to VB. For future reference for anyone else, here is what that looks like:

    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
    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. #4
    Newbie
    Join Date
    Oct 2008
    Posts
    11

    Using FusionUSB with VC++

    Hi I'm having a problem getting the FusionUSB.dll working with my C++ project in VC++, I'm getting the linking error

    error LNK2019: unresolved external symbol "__declspec(dllimport) bool __cdecl FUSB_Initialize(long,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,long)" (__imp_?FUSB_Initialize@@YA_NJV?$basic_string@DU?$ char_traits@D@std@@V?$allocator@D@2@@std@@J@Z) referenced in function _main

    Here is my code incase it might help.
    Code:
    #include <iostream>
    using std::cout;
    using std::cin;
    
    #include <windows.h>
    
    #include <stdio.h>
    
    #include <String>
    using std::string;
    
    
    //#define _STATIC_CPPLIB
    #include "FusionUSB.h"
    #pragma comment(lib,"FusionUSB.lib")
    
    _declspec( dllimport ) bool FUSB_Initialize(long pFusionUSB, string deviceID, long instanceNumber);
    
    int main()
    {
    	
    
    	cout << "Hello World";
    	
    	if(FUSB_Initialize( NULL,"",0) )
    		cout << "initialised";
    	
    	return 0;
    }
    C++ isn't my main language infact this is my first major project using it.

    Thanks

  5. #5
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    C++ isn't my language either, I prefer C#. One thing I notice is that you are using long instead of UInt32. Long is 64bits wide, where as Int32 and UInt32 are both 32bits wide.

    Also we have abandoned this old dll. We have a new Fusion_WinUSB.dll that is easier to interface with.
    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
    Newbie
    Join Date
    Oct 2008
    Posts
    11
    Is there a download for the source of the new Fusion_WinUSB.dll so it will be easier to link with? and would it be possible for a list of the neccessary functions needed to show how to use them similar to the previous post you put up.

    Thanks

  7. #7
    Newbie
    Join Date
    Oct 2008
    Posts
    11

    All values are 0

    Hi I switched over to c# and I have got my program working with the drivers, but when I read in values from my FB and print them out all I get is 0 even though I have 3 temperature sensors connected to the FB.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Timers;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            public const int analogueInput = 32;
            public const int endOfAnalogueInput = 57;
                
            public const int digitalInput = 0;
            public const int endOfDigitalInput = 31;
            
            public static class FusionUSB
            {
    
                [DllImport("FusionUSB.dll")]
                public static extern bool FUSB_Initialize(ref UInt32 pFusionUSB, String deviceID, UInt32 instanceNumber);
    
                [DllImport("FusionUSB.dll")]
                public static extern bool FUSB_Receive(UInt32 pFusionUSB, byte[] buffer);
    
                [DllImport("FusionUSB.dll")]
                public static extern bool FUSB_Send(UInt32 pFusionUSB, byte[] buffer);
    
                [DllImport("FusionUSB.dll")]
                public static extern UInt32 FUSB_Free(ref UInt32 pFusionUSB);
    
                [DllImport("FusionUSB.dll")]
                public static extern bool FUSB_printf(UInt32 pFusionUSB);
    
                [DllImport("FusionUSB.dll")]
                public static extern UInt32 FUSB_GetWinUSBerror(UInt32 pFusionUSB);
    
                [DllImport("FusionUSB.dll")]
                public static extern UInt32 FUSB_GetFUSBstatus(UInt32 pFusionUSB);
    
                [DllImport("FusionUSB.dll")]
                public static extern String FUSB_GetDeviceInstanceID(UInt32 pFusionUSB);
    
            }
    
    
            static void Main(string[] args)
            {
                UInt32 instanceNumber = 0;
                const UInt32 INVALID_HANDLE_VALUE = 0xFFFFFFFF;
                const UInt32 NULL = 0;
                UInt32 pFusionUSB = NULL;
                byte[] ReadBuffer = new byte[64];
                byte[] WriteBuffer = new byte[64];
                const UInt32 FUSB_OK = 0;
                const UInt32 FUSB_DEVICE_NOT_FOUND = 13;
                const UInt32 MAX_DEVICES = 100;
                string deviceID = @"USB\VID_0409&PID_005A\5&1ED3900F&0&3\";
                bool flip_et_flop = true;
                
                
    
                try
                {
    
                    FusionUSB.FUSB_Initialize(ref pFusionUSB, deviceID, instanceNumber);
    
                    if (pFusionUSB != NULL)
                    {
                        Console.WriteLine("Connected");
    
                        FusionUSB.FUSB_Receive(pFusionUSB, ReadBuffer);
                        
                        /*Timer clock = new Timer();
                        clock.Elapsed += new ElapsedEventHandler(Program.OnTimedEvent(ReadBuffer));
                        clock.Elapsed += new ElapsedEventHandler(clock_Elapsed);
                        clock.Interval = 100000;
                        clock.Enabled = true;*/
    
    
                        //read in analogue inputs
                        int a = Console.Read();
                        while (a != 0)
                        {
                            for (int i = analogueInput; i <= endOfAnalogueInput; i += 2)
                            {
                                Console.WriteLine("Byte " + i + " : " + ReadBuffer[i] + "," + ReadBuffer[i + 1]);
                            }
                            a = Console.Read();
                        }
    
                        
                    }
                    FusionUSB.FUSB_Free(ref pFusionUSB);
    
                }
                catch (DllNotFoundException)
                {
                    Console.WriteLine("FusionUSB.dll Not Found");
                }
            }
    
            static void clock_Elapsed(object sender, ElapsedEventArgs e)
            {
                throw new NotImplementedException();
            }
        }
    }
    Has any one any ideas why this is happening?

  8. #8
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    You need to send then receive. If you only call receive, nothing will be returned.
    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. #9
    Newbie
    Join Date
    Oct 2008
    Posts
    11
    Hi
    I figured out after some test statements that nothing was working because the FB was never found, I've tried using the new FusionBrain_WinUSB.dll and the old FusionUSB.dll but neither seem to work. I have the FBv4 and I'm running XP. I have tried connecting two different brains one at a time and neither seems to get picked up by my software even though windows picks them up fine.

    here is my FusionBrain_WinUSB.dll code
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using FusionBrain_WinUSB;
    
    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                //holds list of devices found
                List <string> ver3 = null, ver4 = null;
    
                bool deviceFound = FusionBrain_WinUSB.MainUSBClass.FindAllDevices(ref ver3,ref ver4);
                Console.WriteLine("Device Found : " + deviceFound);
    
                bool myDevice = FusionBrain_WinUSB.MainUSBClass.FindMyDevice(0, 4);
                Console.WriteLine("Device Found : " + myDevice);
                                        
            }
        }
    }
    and here is my FusionUSB.dll code
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Timers;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            public const int analogueInput = 32;
            public const int endOfAnalogueInput = 57;
                
            public const int digitalInput = 0;
            public const int endOfDigitalInput = 31;
            
            public static class FusionUSB
            {
    
                [DllImport("FusionUSB.dll")]
                public static extern bool FUSB_Initialize(ref UInt32 pFusionUSB, String deviceID, UInt32 instanceNumber);
    
                [DllImport("FusionUSB.dll")]
                public static extern bool FUSB_Receive(UInt32 pFusionUSB, byte[] buffer);
    
                [DllImport("FusionUSB.dll")]
                public static extern bool FUSB_Send(UInt32 pFusionUSB, byte[] buffer);
    
                [DllImport("FusionUSB.dll")]
                public static extern UInt32 FUSB_Free(ref UInt32 pFusionUSB);
    
                [DllImport("FusionUSB.dll")]
                public static extern bool FUSB_printf(UInt32 pFusionUSB);
    
                [DllImport("FusionUSB.dll")]
                public static extern UInt32 FUSB_GetWinUSBerror(UInt32 pFusionUSB);
    
                [DllImport("FusionUSB.dll")]
                public static extern UInt32 FUSB_GetFUSBstatus(UInt32 pFusionUSB);
    
                [DllImport("FusionUSB.dll")]
                public static extern String FUSB_GetDeviceInstanceID(UInt32 pFusionUSB);
    
            }
    
    
            static void Main(string[] args)
            {
                UInt32 instanceNumber = 0;
                
                const UInt32 NULL = 0;
                
                UInt32 pFusionUSB = NULL;
                
                byte[] ReadBuffer = new byte[64];
                byte[] WriteBuffer = new byte[64];
                            
                // from mdx source code       
                //string deviceID = @"USB\VID_04D8&PID_000C\";
                
                //full path from my devices
                //string deviceID = @"USB\VID_04D8&PID_000E\5&327F1E4E&0&1";
                
                //root of vid & pid path from my devices
                string deviceID = @"USB\VID_04D8&PID_000E\";
               
                try
                {
                    
                    bool connected = FusionUSB.FUSB_Initialize(ref pFusionUSB, deviceID, instanceNumber);
                    
                    Console.WriteLine("Connected :" + connected );
    
                    if (connected)
                    {
                        // do stuff (removed to shorten the code)
    
                    }
                    else
                    {
                        Console.WriteLine("Fusion Debug");
                        FusionUSB.FUSB_printf(pFusionUSB);
                                      
                    }
                   
                   uint released = FusionUSB.FUSB_Free(ref pFusionUSB);
                   Console.WriteLine("Release code :" + released );
    
                }
                catch (DllNotFoundException)
                {
                    Console.WriteLine("FusionUSB.dll Not Found");
                }
            }
    
            static void clock_Elapsed(object sender, ElapsedEventArgs e)
            {
                throw new NotImplementedException();
            }
        }
    }
    For my FusionUSB.dll program I get the same error codes for all 3 device Ids. Sorry for the long post and thanks again for your help.

Similar Threads

  1. Does Fusion Brain allow Hibernation
    By rgarjr in forum Fusion Brain
    Replies: 5
    Last Post: 04-10-2008, 12:30 AM
  2. Fusion Brain Casing
    By zzzBrett in forum Fusion Brain
    Replies: 1
    Last Post: 10-15-2007, 11:46 PM
  3. software for custom guages, etc.
    By Nephus in forum Engine Management, OBD-II, Engine Diagnostics, etc.
    Replies: 87
    Last Post: 07-12-2005, 04:55 PM
  4. My numpad controlled custom MP3Car software - need your opinions
    By PorscheMP3 in forum Software & Software Development
    Replies: 7
    Last Post: 04-11-2002, 10:30 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
  •