Main Site Documentation

UsbClient 4.3 documentation?


#1

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.

Especially when a release has so many changes.


#2

Here https://www.ghielectronics.com/downloads/man/Library_Documentation_v4.3/ you have at least the API docs


#3

Thanks Reinhard, i have this one, and also the netmf 4.3 docs http://msdn.microsoft.com/en-us/library/microsoft.spot.hardware.usbclient(v=vs.102).aspx

but i’m not able to spend mutch time searching for what’s changed and how these changes have to be implemented in a existing application.

I was hoping these was “some” documentation, maybe for the insiders that i could use to port from 4.2 to 4.3. :whistle:

And yes, i have to go to 4.3 because this version fixes a bug that’s a showstopper for us :wink:


#4

I also have some problems with porting existing code from 4.1 to 4.3. I use virtual MassStorage, but on G120 and EMX modules I can’t make it work…

Perhaps a couple of examples in the documentation would solve the problem :slight_smile:


#5

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…


#6

@ David@ Emrol - Have you tried to create a new MassStorrage object instead of using the DefaultDevice?

like:

MyUSBClient = new GHI.Usb.Client.MassStorage(
   0x01, 0x02, 1, 300, 
   "Me", "MeDrive", "0123", "IMe", 1);

@ GHI - btw. according to the API docs the MassStorrage constructor:

[quote]Creates a new mouse. [/quote] ::slight_smile:


#7

I did now :wink: but same error.


#8

@ 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.


#9

@ John - Ok, i put stop working on this until then, using GHI.Usb.Client.MassStorage.DefaultDevice will be correct then?


#10

@ David@ Emrol - DefaultDevice will work, yes.


#11

@ John - is the next beta released to the insiders before the general public?


#12

@ David@ Emrol - It is not, betas are released to everyone at the same time.


#13

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?


#14

@ 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.


#15

:naughty: No it’s not :whistle:

‘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?


#16

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

    }
}

Tried it with SDCard and IRemovable, some error.

[EDIT] test was on Cobra II


#17

@ David@ Emrol -

This line is important:




Below is tested on G120 4.3.3



```cs

 #define USB_LUN
using System;
using System.IO;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;

using GHI.Processor;
using GHI.IO;
using GHI.IO.Storage;
using GHI.Usb;
using GHI.Usb.Client;
using GHI.Usb.Host;


namespace G120_Lun
{
    public class Program
    {
        private static SDCard _sd;
        private static GHI.Usb.Host.MassStorage _usb;
        private static GHI.Usb.Client.MassStorage _ms = null;
        private static InputPort ldr1 = new InputPort((Cpu.Pin)(22), false, Port.ResistorMode.PullUp); // PA4 - LDR1
        private static OutputPort led = new OutputPort((Cpu.Pin)(47), true);// PD3 led
        // SPIder II, switch 3rd need to be on for LMode
               
        public static void Main()
        {
            led.Write(true);
            GHI.Usb.Host.Controller.MassStorageConnected += Controller_MassStorageConnected;
            GHI.Usb.Host.Controller.Start();
 #if USB_LUN
            while (detectUsbconnected == false)
            {
                Thread.Sleep(50);
                led.Write(!led.Read());
             
            }

 #else        
            // For SD, I tested on FezcorbaII
            while (ldr1.Read())
            {
                Thread.Sleep(50);
                led.Write(true);
                Thread.Sleep(50);
                led.Write(false);
            }
            _sd = new SDCard();
 #endif
           
            Thread.Sleep(100);
            _ms = new GHI.Usb.Client.MassStorage(0x1B9F, 0xF002, 0x100, 250, "GHI Electronics", "Mass Storage", null, "Mass Storage", 1);

            GHI.Usb.Client.Controller.ActiveDevice = _ms;

 #if USB_LUN
            _ms.AttachLogicalUnit(_usb, 0, " ", " ");
 #else          
            Thread.Sleep(100);
            _ms.AttachLogicalUnit(_sd,0 , " ", " ");
            Thread.Sleep(100);
 #endif

            _ms.EnableLogicalUnit(0);
            Thread.Sleep(100);
            
            while (true)
            {
                led.Write(true);
                Thread.Sleep(200);
                led.Write(false);
                Thread.Sleep(200);
            }
        }



        static void Controller_MassStorageConnected(object sender, GHI.Usb.Host.MassStorage e)
        {
            _usb = e;
            detectUsbconnected = true;
             
        }

        static bool detectUsbconnected = false;

       
    }
}


#18

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

:think:


#19

@ David@ Emrol -

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 :smiley:


#20

I’m actualy “stepping” in the code with “F10” so timing should be ok?

Firmware is the 4.3.3 yes

previous error was on a Cobra II Wifi

I’m deploying now to a custom G120 board and ActiveDevice can be set, old error on AttachLogicalUnit

[EDIT] i go and check dll versions and references