Results 1 to 6 of 6

Thread: Problems Initializing FB

  1. #1
    Newbie
    Join Date
    Oct 2008
    Posts
    11

    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. #2
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,053
    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

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

  4. #4
    Newbie
    Join Date
    Oct 2008
    Posts
    11

    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);
                    }
                }
                          
                            
            }
    
            
    
        }
    }

  5. #5
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,053
    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

  6. #6
    Newbie
    Join Date
    Oct 2008
    Posts
    11

    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.

Similar Threads

  1. Replies: 33
    Last Post: 03-28-2008, 02:18 PM
  2. any known problems running under bootcamp
    By Ryan711 in forum MacCar
    Replies: 11
    Last Post: 09-13-2007, 03:00 PM
  3. Replies: 2
    Last Post: 08-13-2007, 03:18 PM
  4. Harddrive problems (booting)
    By Axxess in forum General Hardware Discussion
    Replies: 1
    Last Post: 05-15-2007, 04:13 PM
  5. Dell Inspiron 8200 & Lilliput TS problems?
    By bkpsu in forum LCD/Display
    Replies: 1
    Last Post: 08-15-2004, 01:55 PM

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
  •