Announcement

Collapse
No announcement yet.

Problems Initializing FB

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems Initializing FB

    Hi I'm writing a program with c# to interface with the FB as part of my final year project for university. I have written two programs one using FusionUSB.dll and the other using FusionBrain_WinUSB.dll

    My code for the FusionBrain_WinUSB.dll drivers is:
    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);
                
                for (int i = 0; i <= 5; i++)
                {
                    bool myDevice = FusionBrain_WinUSB.MainUSBClass.FindMyDevice(i, 4);
                    Console.WriteLine("Device Found " + i + " : " + myDevice);
                }
                                        
            }
        }
    }
    and my code for FusionUSB.dll drivers is
    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)
                    {
                        bool sent = FusionUSB.FUSB_Send(pFusionUSB, WriteBuffer);
                        bool read = FusionUSB.FUSB_Receive(pFusionUSB, ReadBuffer);
                        
                        Console.WriteLine("Data Sent :" + sent);
                        Console.WriteLine("Data Received :" + read);
    
                        //read in analogue inputs
                        if (read)
                        {
                            int a = Console.Read();
                            while (a != 0)
                            {
                                for (int i = analogueInput; i <= endOfAnalogueInput; i += 2)
                                {
                                    Console.WriteLine("Sensor " + i + " : " + ReadBuffer[i] + "," + ReadBuffer[i + 1]);
                                }
                                a = Console.Read();
                            }
                        }
                        else
                        {
                            Console.WriteLine("No Input");
                        }
    
                    }
                    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();
            }
        }
    }
    I can't figure out why neither of these work, I have been working using the MDX code as a guide, and have followed it closely and still nothing works. I am using windows xp with FBv4 and can see the FB in my devices.

    Could someone please help?

    Thanks
    Jeff

  • #2
    If you use the Fusion_WinUSB.dll then you need to have the new drivers installed.

    If you use the FusionUSB.dll, then you need to old drivers installed.

    Both cannot be installed at the same time.
    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

    Comment


    • #3
      Thanks that helped I uninstalled the drivers from the device manager, which were installed with the mdx installer. After that I just had the FusionBrain_WinUSB.dll as a reference to my project.

      Comment


      • #4
        Still Not Initializing

        Hi I thought I had it working but my last post was a little premature unfortunatly.

        I still have a problem with Initializing the FB this time when using

        FusionBrain_WinUSB.MainUSBClass.FindAllDevices(ref ver3, ref ver4);

        it always returns true even though

        FusionBrain_WinUSB.MainUSBClass.FindMyDevice(i, 4)

        where i is the index. I think

        FusionBrain_WinUSB.MainUSBClass.FindMyDevice(i, 4)

        is correct to return false because the count of the ver4 list is 0 after calling FindAllDevices
        I'm starting to think it's my set up?
        I'm using
        XP
        Visual Studio 2008 full

        Added
        FusionBrainWinUSB.dll as a reference to my project

        Uninstalled
        MDX
        FusionBrainV4 drivers(installed from drivers download on FusionControllCenter)

        If I get this working I'll put up a for dummies post

        Here is my complete code incase I have made some huge error
        Code:
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using FusionBrain_WinUSB;
        
        namespace AAL
        {
            class FusionBrain
            {
                
                public void connect()
                {
                    //holds list of devices found
                    List<string> ver3 = new List<string>();
                    List<string> ver4 = new List<string>();
                    byte[] buffer = new byte [64];
        
        
                    //returns true even if there is no Brain connected
                    bool deviceFound = FusionBrain_WinUSB.MainUSBClass.FindAllDevices(ref ver3, ref ver4);
                    Console.WriteLine("Device Found : " + deviceFound);
        
                    //count always == 0 even with 2 Brains connected
                    Console.WriteLine("Version 4 count: "+ ver4.Count() );
                    
                    int index4 = 0;
        
                    for (int i = 0; i < ver4.Count; i++)
                    {
                        //not connecting when Brain is connected
                        bool myDevice = FusionBrain_WinUSB.MainUSBClass.FindMyDevice(i, 4);
                        
                        if( myDevice )
                        {
                            index4 = i;
                            Console.WriteLine("Conected at Index: " + index4);
                        }
                    }
                              
                                
                }
        
                
        
            }
        }

        Comment


        • #5
          Insert a breakpoint right after ...FindAllDevices(...);

          See what those lists contain. do any instances appear at all? If not then the drivers aren't installed correctly or not properly plugged in or system initialized.

          It should return true unless there was an error that got trapped by the exception handler. Finding 0 devices will still return true if all goes well.
          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

          Comment


          • #6
            Thanks

            This is working now I moved everything onto my vista laptop and installed the drivers and it's working now. I'll have to try and reinstall the drivers when I get back to my lab machine on Tuesday.

            I'll let you know how it goes. But I think I owe you a guide for dummies.

            Comment

            Working...
            X