Main Site Documentation

USBHost interface


#1

Hi there,
I have been trying serial USB code from following link:

https://www.ghielectronics.com/docs/36/usb-host

I modified code as follow :

using System;
using Microsoft.SPOT;
using GHI.Premium.USBHost;
using System.Threading;
using GHI.Premium.System;
using System.IO.Ports;


namespace powercloud
{
    class USBHost
    {

        public static void Main()
        {

            USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;
            USBHostController.DeviceDisconnectedEvent += DeviceDisconnectedEvent;

            // Sleep forever
            Thread.Sleep(Timeout.Infinite);

        }

        static private USBH_Device serialUSB;

        static void DeviceConnectedEvent(USBH_Device device)
        {
            Debug.Print("Device connected...");
            Debug.Print("ID: " + device.ID + ", Interface: " + device.INTERFACE_INDEX + ", Type: " + device.TYPE);

           
            //serialUSB. += usbSerial_DataReceived;


        }

        static void DeviceDisconnectedEvent(USBH_Device device)
        {
            Debug.Print("Device disconnected...");
            Debug.Print("ID: " + device.ID + ", Interface: " + device.INTERFACE_INDEX + ", Type: " + device.TYPE);
        }


        private static void usbSerial_DataReceived(USBH_Device sender, USBH_Device e)
        {

            for (int i = 0; i < e.Data.Length; i++)
                Debug.Print(e.Data[i].ToString());

            sender.Write(e.Data);
        }

    }
}

I got usbSerial_DataReceived() function wrong, so can anyone suggest how could I do that ?


#2

Upgrade your firmware and SDK to the latest version.


#3

Thanks for you response, I was updating using FEZ config and now I am getting following error:

Failure - Device is not connected or not responding.

Now, Fez Cobra II board keep connecting and disconnecting by itself with PC. It stay connected about minute and then it disconnects then it will connect again.

I think I messed up with LDR1 and LDR0 buttons.

What should I do to get it work as before ?

Thanks


#4

@ Akshay - Try a diffrent usb cable. I’ve solved problems that way. Then try starting it with external power. Lack of juice does some weird things.


#5

Now, when I run my application , then on output window of the visual studio showing following message and it is keep going

Waiting for device to initialize…

Please look attached screenshot.

thanks


#6

After updating tinyBooter and tinyCLR , when I debug code I got following error on the output window. (Screenshot 1,2).

Every time I run the code, it stops after 59 iteration and then shows the error that Device not found and cannot be opened.

Thanks
Any help would be great !!


#7

there’s a good chance a recent change in your code is stopping the debugger from responding.

You can fix that by fixing your code - thread.sleep(1) somewhere in a tight loop will allow other things to get scheduled and deal with this issue, should that

OR

You can just hit the reset button once the first few iterations are shown and the debugger should attach (this is more a workaround than a fix). You might find it beneficial to have “start up” control in your app - if a button is held down for instance it doesn’t start your main application, or it holds off for 5 seconds to allow the deployment to kick in.


#8

Hi Bret,
Thanks for your reply ,

I solved that problem by changing target framework of my project to .net micro framework 4.3

I got following firmware in G120:

Loader (TinyBooter) version information:
4.3.4.0 on this computer.
4.3.4.0 on this device.

The Loader (TinyBooter) is up to date. <<<

Firmware (TinyCLR) version information:
4.3.5.0 on this computer.
4.3.5.0 on this device.

The Firmware (TinyCLR) is up to date. <<<
Please wait for the device to reboot… Done.

Now, I have got Error: a3000000, How could I solve it ?

Link failure: some assembly references cannot be resolved!!

Look screenshot

Thanks


#9

by removing ALL your netmf supplied references in your project, and then re-adding them. Just by changing the framework version you don’t actually get the 4.3 framework DLLs replacing your existing 4.2 ones, you have to do that manually.


#10

Hi Brett,

thanks…could you please explain how could I do that as I beginner


#11

In the screenshot, remove all the references you have there (these are still pointing to version 4.2) and add them again.


#12

@ David has helped out with that - but the thing that struck me was, if you’re a beginner, why do you have so many parts of your solution in solution explorer ! Might be worth starting simple :wink:


#13

Thanks guys for your reply…

I know actually how to change references, but if I change it to new ones, my code will break, so I was looking for a way that may not break my code and can upgrade reference , but I think there is not a such way.

Thanks


#14

You need everything to be consistently targeting the same framework version. That means the compiled modules you use have to match the firmware version you have deployed to the device, and the references you include in your modules (all of them) have to refer to the same version. You can’t get away from that; you need consistency. If your app breaks then you need to deal with that - an unfortunate consequence of doing what you’re doing - or what you did.

Note: there is no issue running an older framework version than the version you have installed. You can safely run 4.2 when you use 4.3, but you need to have deployed the right firmware to the device, but you also don’t get any benefit from the improvements that came with the new framework (both bugfixes and new features).


#15

Hi Brett,

I just want to clarify that currently I have 4.3 .net micro framework and I got below firmware
in the device :

Loader (TinyBooter) version information:
4.3.4.0 on this computer.
4.3.4.0 on this device.

The Loader (TinyBooter) is up to date. <<<

Firmware (TinyCLR) version information:
4.3.5.0 on this computer.
4.3.5.0 on this device.

The Firmware (TinyCLR) is up to date. <<<

Before I had code written in 4.2 and all the references of the 4.2

Now, I got 4.3 , so should I be able to use references of 4.2 because my code has written in 4.2 ?

Currently, I am getting following error in output window, I am not sure how could I solve the issue ?

Found debugger!

Create TS.

Loading start at a0e68ea4, end a0e98338

Assembly: mscorlib (4.3.1.0) Assembly: Microsoft.SPOT.Native (4.3.1.0) Assembly: Microsoft.SPOT.Security.PKCS11 (4.3
.1.0) Assembly: System.Security (4.3.1.0) Assembly: Microsoft.SPOT.Hardware (4.3.1.0)
Assembly: Microsoft.SPOT.Graphics (4.3.1.0) Assembly: Microsoft.SPOT.TinyCore (4.3.1.0)
Assembly: Microsoft.SPOT.IO (4.3.1.0) Assembly: System.IO (4.3.1.0) Assembly: Microsoft.SPOT.Hardware.Usb (4.3.1.0)
Assembly: Microsoft.SPOT.Hardware.SerialPort (4.3.1.0) Assembly: Microsoft.SPOT.Touch (4.3.1.0)
Assembly: Microsoft.SPOT.Ink (4.3.1.0) Assembly: Microsoft.SPOT.Hardware.PWM (4.3.1.0)
Loading Deployment Assemblies.

Attaching deployed file.

Assembly: GHI.Premium.System (4.2.11.1) Attaching deployed file.

Assembly: GHIElectronics.Gadgeteer.G400HDRBreakout (4.3.5.0) Attaching deployed file.

Assembly: MFDpwsExtensions (4.3.1.0) Attaching deployed file.

Assembly: GHI.Premium.USBHost (4.2.11.1) Attaching deployed file.

Assembly: GHI.Hardware (4.3.5.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Hardware.OneWire (4.3.1.0) Attaching deployed file.

Assembly: GHIElectronics.Gadgeteer.FEZCerberus (4.3.5.0) Attaching deployed file.

Assembly: GHIElectronics.Gadgeteer.FEZHydra (4.3.5.0) Attaching deployed file.

Assembly: Gadgeteer.DaisyLink (2.43.1.0) Attaching deployed file.

Assembly: System.Net.Security (4.3.1.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Wireless.IEEE_802_15_4.Phy (4.3.1.0) Attaching deployed file.

Assembly: MFUpdate (4.3.1.0) Attaching deployed file.

Assembly: GHI.Premium.Net (4.2.11.1) Attaching deployed file.

Assembly: Microsoft.SPOT.Wireless.IEEE_802_15_4 (1.0.0.0) Attaching deployed file.

Assembly: GHI.Usb (4.3.5.0) Attaching deployed file.

Assembly: GHI.Glide (4.3.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Wireless.IEEE_802_15_4.Mac (4.3.1.0) Attaching deployed file.

Assembly: MFWsStack (4.3.1.0) Attaching deployed file.

Assembly: MFDpwsClient (4.3.1.0) Attaching deployed file.

Assembly: GHI.Premium.USBClient (4.2.11.1) Attaching deployed file.

Assembly: Microsoft.SPOT.Net.Security (4.3.1.0) Attaching deployed file.

Assembly: GHIElectronics.Gadgeteer.FEZRaptor (4.3.5.0) Attaching deployed file.

Assembly: System (4.3.1.0) Attaching deployed file.

Assembly: GHI.Premium.IO (4.2.11.1) Attaching deployed file.

Assembly: Toolbox.NETMF.Core (4.2.0.0) Attaching deployed file.

Assembly: Gadgeteer.SPI (2.43.1.0) Attaching deployed file.

Assembly: Gadgeteer.WebServer (2.43.1.0) Attaching deployed file.

Assembly: GHI.SQLite (4.3.5.0) Attaching deployed file.

Assembly: GHIElectronics.Gadgeteer.FEZSpider (4.3.5.0) Attaching deployed file.

Assembly: MFDpwsDevice (4.3.1.0) Attaching deployed file.

Assembly: GHI.Premium.Hardware (4.2.11.1) Attaching deployed file.

Assembly: System.Ftp (4.3.1.0) Attaching deployed file.

Assembly: System.Xml.Legacy (4.3.1.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Update (4.3.1.0) Attaching deployed file.

Assembly: Microsoft.VisualBasic (1.0.0.0) Attaching deployed file.

Assembly: GHI.Hardware.G120 (4.2.11.1) Attaching deployed file.

Assembly: Gadgeteer.Serial (2.43.1.0) Attaching deployed file.

Assembly: GHIElectronics.Gadgeteer.FEZCerbuinoBee (4.3.5.0) Attaching deployed file.

Assembly: Gadgeteer.WebClient (2.43.1.0) Attaching deployed file.

Assembly: GHI.Networking (4.3.5.0) Attaching deployed file.

Assembly: System.Http (4.3.1.0) Attaching deployed file.

Assembly: powercloud (1.0.0.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Wireless.IEEE_802_15_4.Phy.CC2420 (4.3.1.0) Attaching deployed file.

Assembly: Gadgeteer (2.43.1.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Time (4.3.1.0) Attaching deployed file.

Assembly: GHIElectronics.Gadgeteer.FEZCobraIIEco (4.3.5.0) Attaching deployed file.

Assembly: mfnet.smallbiz.common (1.0.0.0) Attaching deployed file.

Assembly: GHI.Pins (4.3.5.0) Attaching deployed file.

Assembly: System.Text.RegularExpressions (4.3.1.0) Attaching deployed file.

Assembly: Microsoft.SPOT.Net (4.3.1.0) Attaching deployed file.

Assembly: GHIElectronics.Gadgeteer.FEZCerbuinoNet (4.3.5.0) Attaching deployed file.

Assembly: System.Xml (4.3.1.0) Resolving.

Link failure: some assembly references cannot be resolved!!

Assembly: GHI.Premium.System (4.2.11.1) needs assembly ‘mscorlib’ (4.2.0.0)

Assembly: GHI.Premium.System (4.2.11.1) needs assembly ‘Microsoft.SPOT.Hardware’ (4.2.0.0)

Assembly: GHI.Premium.System (4.2.11.1) needs assembly ‘Microsoft.SPOT.Native’ (4.2.0.0)

Assembly: GHI.Premium.USBHost (4.2.11.1) needs assembly ‘mscorlib’ (4.2.0.0)

Assembly: GHI.Premium.USBHost (4.2.11.1) needs assembly ‘GHI.Premium.System’ (4.2.11.1)

Assembly: GHI.Premium.USBHost (4.2.11.1) needs assembly ‘Microsoft.SPOT.Hardware’ (4.2.0.0)

Assembly: GHI.Premium.USBHost (4.2.11.1) needs assembly ‘Microsoft.SPOT.Graphics’ (4.2.0.0)

Assembly: GHI.Premium.Net (4.2.11.1) needs assembly ‘Microsoft.SPOT.Native’ (4.2.0.0)

Assembly: GHI.Premium.Net (4.2.11.1) needs assembly ‘mscorlib’ (4.2.0.0)

Assembly: GHI.Premium.Net (4.2.11.1) needs assembly ‘Microsoft.SPOT.Net’ (4.2.0.0)

Assembly: GHI.Premium.Net (4.2.11.1) needs assembly ‘Microsoft.SPOT.Hardware’ (4.2.0.0)

Assembly: GHI.Glide (4.3.0.0) needs assembly ‘System.Xml’ (4.3.1.0)

Assembly: MFWsStack (4.3.1.0) needs assembly ‘System.Xml’ (4.3.1.0)

Assembly: MFDpwsClient (4.3.1.0) needs assembly ‘MFWsStack’ (4.3.1.0)

Assembly: MFDpwsClient (4.3.1.0) needs assembly ‘System.Xml’ (4.3.1.0)

Assembly: GHI.Premium.USBClient (4.2.11.1) needs assembly ‘mscorlib’ (4.2.0.0)

Assembly: GHI.Premium.USBClient (4.2.11.1) needs assembly ‘Microsoft.SPOT.Hardware.Usb’ (4.2.0.0)

Assembly: GHI.Premium.USBClient (4.2.11.1) needs assembly ‘GHI.Premium.IO’ (4.2.11.1)

Assembly: GHI.Premium.USBClient (4.2.11.1) needs assembly ‘Microsoft.SPOT.Native’ (4.2.0.0)

Assembly: GHI.Premium.IO (4.2.11.1) needs assembly ‘mscorlib’ (4.2.0.0)

Assembly: GHI.Premium.IO (4.2.11.1) needs assembly ‘GHI.Premium.System’ (4.2.11.1)

Assembly: Toolbox.NETMF.Core (4.2.0.0) needs assembly ‘mscorlib’ (4.2.0.0)

Assembly: Toolbox.NETMF.Core (4.2.0.0) needs assembly ‘Microsoft.SPOT.Hardware’ (4.2.0.0)

Assembly: MFDpwsDevice (4.3.1.0) needs assembly ‘MFWsStack’ (4.3.1.0)

Assembly: MFDpwsDevice (4.3.1.0) needs assembly ‘System.Xml’ (4.3.1.0)

Assembly: GHI.Premium.Hardware (4.2.11.1) needs assembly ‘mscorlib’ (4.2.0.0)

Assembly: GHI.Premium.Hardware (4.2.11.1) needs assembly ‘Microsoft.SPOT.Hardware’ (4.2.0.0)

Assembly: GHI.Premium.Hardware (4.2.11.1) needs assembly ‘GHI.Premium.System’ (4.2.11.1)

Assembly: GHI.Hardware.G120 (4.2.11.1) needs assembly ‘mscorlib’ (4.2.0.0)

Assembly: powercloud (1.0.0.0) needs assembly ‘GHI.Premium.Net’ (4.2.11.1)

Assembly: powercloud (1.0.0.0) needs assembly ‘mfnet.smallbiz.common’ (1.0.0.0)

Assembly: powercloud (1.0.0.0) needs assembly ‘GHI.Premium.Hardware’ (4.2.11.1)

Assembly: powercloud (1.0.0.0) needs assembly ‘GHI.Premium.IO’ (4.2.11.1)

Assembly: powercloud (1.0.0.0) needs assembly ‘Microsoft.SPOT.Hardware’ (4.2.0.0)

Assembly: powercloud (1.0.0.0) needs assembly ‘Microsoft.SPOT.Net’ (4.2.0.0)

Assembly: powercloud (1.0.0.0) needs assembly ‘mscorlib’ (4.2.0.0)

Assembly: powercloud (1.0.0.0) needs assembly ‘Toolbox.NETMF.Core’ (4.2.0.0)

Assembly: mfnet.smallbiz.common (1.0.0.0) needs assembly ‘mscorlib’ (4.2.0.0)

Assembly: mfnet.smallbiz.common (1.0.0.0) needs assembly ‘Microsoft.SPOT.IO’ (4.2.0.0)

Assembly: mfnet.smallbiz.common (1.0.0.0) needs assembly ‘Microsoft.SPOT.Native’ (4.2.0.0)

Assembly: mfnet.smallbiz.common (1.0.0.0) needs assembly ‘System’ (4.2.0.0)

Error: a3000000

Waiting for debug commands…

The program ‘[38] Micro Framework application: Managed’ has exited with code 0 (0x0).


#16

you have to check all references in all the projects, if you have a line like this:

Assembly: mfnet.smallbiz.common (1.0.0.0) needs assembly ‘mscorlib’ (4.2.0.0)

It means you have a reference in this project to 4.2 and not 4.3

This one is ok

Assembly: MFDpwsClient (4.3.1.0) needs assembly ‘System.Xml’ (4.3.1.0)

this one is not

Assembly: powercloud (1.0.0.0) needs assembly ‘Microsoft.SPOT.Hardware’ (4.2.0.0)


#17

No you’re exactly going in the wrong direction.

You have two options. No matter what direction you go, everything needs to be consistent. If you target 4.3, you need 4.3 framework on your device, and only have 4.3 references. If you target 4.2, you need 4.2 framework on your device and only have 4.2 references.

Option 1: You have framework 4.3 on your device. You must make sure your project targets 4.3 framework, and update all your references to 4.3, and fix any code things that change.

Option 2: You have 4.2 projects you don’t want to touch. You must downgrade the firmware on your device to match the 4.2 version your projects target.

At one point you had an issue with the device not responding correctly (post 3 or so in this thread). Because there are improvements in USB debugging I suggest you take option 1 to get the benefit of that alone, plus the stability in many other areas (networking in particular)


#18

Thanks Brett and David ,

Now I understand better. you guys are really helpful…

Thanks !! :smiley:


#19

Hi Brett,

Now, my project is successfully compiling in 4.3.
I would like to connect another micro controller to G120 with serial connection and send data to it and read response from it. I would like to use USB interface as that micocontroller doesn’t have UART support

I am using following code. got from https://www.ghielectronics.com/docs/36/usb-host

using GHI.Usb.Host;
using Microsoft.SPOT;
using System.Threading;

public class Program
{
    public static void Main()
    {
        Controller.UsbSerialConnected += Controller_UsbSerialConnected;

        Controller.Start();

        Thread.Sleep(-1);
    }

    private static void Controller_UsbSerialConnected(object sender, UsbSerial usbSerial)
    {
        Debug.Print("UsbSerial connected.");

        usbSerial.DataReceived += usbSerial_DataReceived;
    }

    private static void usbSerial_DataReceived(UsbSerial sender, UsbSerial.DataReceivedEventArgs e)
    {
        for (int i = 0; i < e.Data.Length; i++)
            Debug.Print(e.Data[i].ToString());

        sender.Write(e.Data);
    }
}

Now, I would like to know How could I send data to it ?

Thanks