USB Client with G400-D v1.3

Hi,

I’m having issue working with USB client on a G400-D module. I tried the simple code below taken from the USB Client Documents.

My understanding of the USB client module as a Keyboard means the device should appear in my Keyboards list and I should not be able to debug it through Visual Studio so I added some simple LED to understand where it’s breaking.

After deploying to the board and reseting the device (reset button on the board) the result is:

LED1 is On
LED2 is Off
LED3 is blinking.


using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware.UsbClient;
using Microsoft.SPOT.Hardware;
using GHI.Usb;
using GHI.Usb.Client;

public class Program
{

        private static OutputPort LED1 = new Microsoft.SPOT.Hardware.OutputPort((Cpu.Pin)75, false);
        private static OutputPort LED2 = new Microsoft.SPOT.Hardware.OutputPort((Cpu.Pin)76, false);
        private static OutputPort LED3 = new Microsoft.SPOT.Hardware.OutputPort((Cpu.Pin)77, false);
        private static OutputPort LED4 = new Microsoft.SPOT.Hardware.OutputPort((Cpu.Pin)78, false);

    public static void Main()
    {
        Thread.Sleep(10000);
        Keyboard kb = new Keyboard();

        try
        {Controller.ActiveDevice = kb;}
        catch (Exception)
        {LED1.Write(true);}

        while (true)
        {
            try
            {
                if (Controller.State == UsbController.PortState.Running)
                {
                    try
                    {
                        kb.Stroke(Key.W);
                        kb.Stroke(Key.O);
                        kb.Stroke(Key.R);
                        kb.Stroke(Key.L);
                        kb.Stroke(Key.D);
                        kb.Stroke(Key.Enter);
                    }
                    catch (Exception)
                    {LED3.Write(!LED3.Read());}
                }               
            }
            catch (Exception)
            {LED2.Write(!LED2.Read());}
            Thread.Sleep(1000);
        }
    }
}

I tried anyway with VS debugging and got:

Error caught at “LED1”:

Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (1)

Message:

GHI.Usb.Client.RawDevice::NativeInitialize [IP: 0000]

GHI.Usb.Client.RawDevice::Activate [IP: 00f3]

GHI.Usb.Client.Controller::set_ActiveDevice [IP: 0015]

Program::Main [IP: 0013]

A first chance exception of type ‘System.InvalidOperationException’ occurred in GHI.Usb.dll

Error caught at “LED3” (likely dependant of the first error):

Exception System.InvalidOperationException - 0x00000000 (1)

Message: Operation timed out.

GHI.Usb.Client.RawDevice+RawStream::Write [IP: 007d]

GHI.Usb.Client.RawDevice+RawStream::Write [IP: 0022]

GHI.Usb.Client.Keyboard::Press [IP: 006e]

GHI.Usb.Client.Keyboard::Stroke [IP: 0013]

Program::Main [IP: 003f]

A first chance exception of type ‘System.InvalidOperationException’ occurred in GHI.Usb.dll

Any ideas to progress on this? Did I miss annything?

Thanks a lot

Thanks,

Ok, if I connect PA25 to ground I do get the Keyboard in my devices’ list therefore LED 3 is still blinking and I don’t receive any data.

I’ll figure out a debug connection with COM1 and try to get the new error… Unless you already know or have an idea?

Kind regards

Agreed, but check this online documentation https://www.ghielectronics.com/docs/20/usb-client Keyboard section and you’ll see the same code as in the G400 documentation plus this line.
And as far as I read on other post on this forum it should be there…

@ pidji87 - Just to be sure. Are you on the latest SDK/Firmware?

As you can see on the screen shot.

@ pidji87 - There was a problem with Keyboard that was supposed to be fixed, but GHI should be able to confirm if it was included in the latest firmware or not.

Reply #2 from Dat in this thread:

https://www.ghielectronics.com/community/forum/topic?id=16295&page=1#msg164816

I just gave a shot to the code below with a Mouse this time. I do also get an extra Mouse HID in my devices but no movement and surprisingly LED3 is ON and not blinking


    public static void TestMouse()
    {
        Thread.Sleep(10000);

        Mouse mouse = new Mouse();
        try
        {
            Controller.ActiveDevice = mouse;
        }
        catch (Exception)
        {LED1.Write(true);}

        try
        {
            while (Controller.State != UsbController.PortState.Running)
            {
                Thread.Sleep(1000);
            }
        }
        catch (Exception)
        {
            LED2.Write(!LED2.Read());
        }

        int posx = 20;
        int posy = 20;
        while (true)
        {
            try
            {
                posx += 20;
                posy += 10;                
                mouse.MoveCursorTo(posx, posy);
            }
            catch (Exception)
            { LED3.Write(!LED3.Read()); }

            Thread.Sleep(1000);
        }
    }

@ pidji87 -

If I remember correctly, on G400, USBClient does only support CDC and USB Client MS.
Keyboard, mouse are not supported yet. Check release note, I think

@ Dat -

Tried the CDC and it works, I can send data from the board to a terminal on my laptop.
Therefore regarding Keyboard (and mouse potentially) I looked at “NETMF v4.3 Release Notes” and in 2014 R3 you (GHI) mentioned :

All Boards

Changes

  • USB Client keyboards now behave properly.

In 2014 R4:

G400

Version

  • 4.3.5.0 Firmware
  • 4.3.5.0 Loader

Changes

  • Fixed a bug where USB Host and Client at the same time can freeze the board.
  • Fixed CDC failing to write after the first time.
  • Fixed CDC crashing the board.

Issues

  • USB Client Mass Storage may work incorrectly.

And in 2014 R5:

G400

Version

  • 4.3.6.0 Firmware
  • 4.3.6.0 Loader

Changes

  • Improved USB client stability.

So as far as we discuss here I’d say either something has been broken in latest releases or it has never worked on G400.
It’s a shame I’m having such issues because even if I’m new to your products I’m looking at using them in a V2 of my commercial product and I’m not feeling confident at deploying it to the market yet. G400 is your “professionnal” module, am I right? and I’m hoping for more stability or at least from a marketing point of view a clearer understanding of what’s available and what’s not on such module.

Anyway if you have any other inputs or Beta framework to test I’m willing to help.

Regards

@ pidji87 - It was mistakenly left out of the release notes. Only USB client mass storage and CDC are functional on the G400. See https://www.ghielectronics.com/community/forum/topic?id=17345

Hi, does something changed? I tried my G400 as USB Client Keyboard without success. Does the G30 TH Module be used as USB Client Keyboard to send keys to a PC?

Thank you.