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
Bookmarks