Is there any documentation available on using usbclient in 4.3?
I did read somewhere on the forum documentation will we adjusted when it’s out of beta but to be able to test and do my migration I would be handy to have “some” doc’s.
I did a quick try to see if could figure this out but no succes…
//get controllers
USBControllers = Microsoft.SPOT.Hardware.UsbClient.UsbController.GetControllers();
//if controller is availible on this hardware
if (USBControllers.Length != 0)
{
//4.3 //4.2
//start the first one.. there is only one anyway? //in 4.2 we dont start the controller but the MassStorage
USBControllers[0].Start(); //MyUSBClient = USBClientController.StandardDevices.StartMassStorage();
MyUSBClient = GHI.Usb.Client.MassStorage.DefaultDevice; //
MyUSBClient.AttachLogicalUnit(MySD, 0, "", ""); //MyUSBClient.AttachLun(0, sd, " ", " ");
MyUSBClient.EnableLogicalUnit(0); //MyUSBClient.EnableLun(0);
}
In 4.2 i started the standard massstorage device but in 4.3 this is gone.
I searched a bit over the different namespaces and found a start method for the controller.
And in another namespace i found the default massstorage device. but no…
#### Exception System.IndexOutOfRangeException - 0xa9000000 (5) ####
#### Message:
#### GHI.Usb.Client.RawDevice::SetInterfaceMap [IP: 0017] ####
#### GHI.Usb.Client.MassStorage::.ctor [IP: 00af] ####
#### GHI.Usb.Client.MassStorage::get_DefaultDevice [IP: 0029] ####
#### IRC.Program::WDTCounterResetLoop [IP: 00d3] ####
A first chance exception of type 'System.IndexOutOfRangeException' occurred in GHI.Usb.dll
The state off the controller changes to “running” after start but seems this is not all…
@ Reinhard Ostermeier - Thanks for the wrong comment, it’s been fixed.
@ David@ Emrol - As for USB client, it is still very unstable and hasn’t been tested much. I did find a bug that would cause your issue, but there is no work around at this time. It will be fixed in a coming beta though.
The USBClient.Joystick does not work eather: (FW 4.3 Beat 3)
var controllers = UsbController.GetControllers();
if (controllers.Length > 0)
{
controllers[0].Start();
_joystick = Joystick.DefaultDevice;
}
throws
The thread '<No Name>' (0x2) has exited with code 0 (0x0).
#### Exception System.InvalidOperationException - 0x00000000 (1) ####
#### Message:
#### System.IO.Stream::set_WriteTimeout [IP: 0003] ####
#### HotasConsole.Program::InitJoystick [IP: 002e] ####
#### HotasConsole.Program::Main [IP: 0090] ####
A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
at 1st access to Joystcik.DefaultDevice
no difference if I call the Joystck constructor
btw.:
1: would it be much work to have more axes? (and may be more Buttons)
2: Is it possible to use USBClient Joystick and Keyboard at the same time?
@ Reinhard Ostermeier - I’ve fixed the joystick problem. It was actually a problem in RawStream, so anything that uses that will be affected if it sets the read or write timeout.
As for multiple USB Clients, it is not something we have tested or tried to explicitly support, so it will likely not work. It might also be possible to add more axes and buttons to the joystick but it is not something we plan to do at this time, so I cannot really say how much work it would be. You can always write your own joystick driver on top of GHI.Usb.Client.RawDevice if needed.
‘GHI.Usb.Client.MassStorage’ does not contain a definition for ‘DefaultDevice’…
So i used MassStorage instead but with this code:
MyUSBClient = new GHI.Usb.Client.MassStorage();
MyUSBClient.AttachLogicalUnit(MySD, 0);
MyUSBClient.EnableLogicalUnit(0);
I get this error
#### Exception System.Exception - 0xffffffff (5) ####
#### Message:
#### GHI.Usb.Client.MassStorage::NativeAttachLogicalUnit [IP: 0000] ####
#### GHI.Usb.Client.MassStorage::AttachLogicalUnit [IP: 0056] ####
#### GHI.Usb.Client.MassStorage::AttachLogicalUnit [IP: 000c] ####
#### IRC.Program::WDTCounterResetLoop [IP: 00d4] ####
A first chance exception of type 'System.Exception' occurred in GHI.Usb.dll
An exception of type 'System.Exception' occurred in GHI.Usb.dll and wasn't handled before a managed/native boundary
On the attachLogicalUnit instruction, MySD is a “GHI.IO.Storage.IRemovable”
Is there something else changed in 4.3 usbclient that i’m missing?
I created a minimun app to check the basics but same error, i must be missing something.
using GHI.IO;
using System;
using GHI.Usb;
using Microsoft.SPOT;
namespace MFConsoleApplication2
{
public class Program
{
public static void Main()
{
GHI.Usb.Client.MassStorage MyUSBClient;
GHI.IO.Storage.SDCard MySD;
MySD = new GHI.IO.Storage.SDCard ();
MyUSBClient = new GHI.Usb.Client.MassStorage();
MyUSBClient.AttachLogicalUnit(MySD); // <-- ERR
MyUSBClient.EnableLogicalUnit(0);
}
}
}
I “think” i followed your code (added the extra parameters and Activedevice)
using GHI.IO;
using System;
using GHI.Usb;
using Microsoft.SPOT;
namespace MFConsoleApplication2
{
public class Program
{
public static void Main()
{
GHI.Usb.Client.MassStorage MyUSBClient;
GHI.IO.Storage.SDCard MySD;
MySD = new GHI.IO.Storage.SDCard ();
MyUSBClient = new GHI.Usb.Client.MassStorage(0x1B9F, 0xF002, 0x100, 250, "TriNeuron", "MFC","123456","xyz",1);
GHI.Usb.Client.Controller.ActiveDevice = MyUSBClient;
MyUSBClient.AttachLogicalUnit(MySD,0," "," ");
MyUSBClient.EnableLogicalUnit(0);
}
}
}
But now another error NativeInitialize
#### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (1) ####
#### Message:
#### GHI.Usb.Client.RawDevice::NativeInitialize [IP: 0000] ####
#### GHI.Usb.Client.RawDevice::Activate [IP: 00ea] ####
#### GHI.Usb.Client.Controller::set_ActiveDevice [IP: 0015] ####
#### MFConsoleApplication2.Program::Main [IP: 002e] ####
A first chance exception of type 'System.InvalidOperationException' occurred in GHI.Usb.dll
An unhandled exception of type 'System.InvalidOperationException' occurred in GHI.Usb.dll
What device are you using please? And the firmware is 4.3.3?
And, try to add some sleep (as my code), please!
if you got an exception in here:
"GHI.Usb.Client.Controller.ActiveDevice = MyUSBClient;"
This is not related to SD or any hardware, it is in dll so I think we are different dll. Of course I am using the correct one