CDC issue

Hi,

Im trying to send data via Virtual serial port using the example given here: https://www.ghielectronics.com/docs/20/usb-client

I have changed nothing , references are there, version of sdk is 4.3

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


public class Program
{
    public static void Main()
    {
        // Start Cdc
        Cdc vsp = new Cdc();
        Controller.ActiveDevice = vsp;

        // Send "Hello world!" to PC every second. (Append a new line too)
        byte[] bytes = System.Text.Encoding.UTF8.GetBytes("Hello world!\r\n");
        while (true)
        {
            // Check if connected to PC
            if (Controller.State !=
                UsbController.PortState.Running)
            {
                Debug.Print("Waiting to connect to PC...");
            }
            else
            {
                vsp.Stream.Write(bytes, 0, bytes.Length);
            }
            Thread.Sleep(1000);
        }
    }
}

The code always crashes at “Controller.ActiveDevice = vsp;”
with error message: An unhandled exception of type ‘System.InvalidOperationException’ occurred in GHI.Usb.dll

What am i doing wrong?

1 Like

What mainboard are you using?

@ Hanswurst - Also make sure you are using serial and not usb debugging.

using FEZ Spider

I did following :

  • the most left switch of the 4 switches beneath the reset button on the mainboard is set to on (down)

  • driver is put to the install directory of the drivers in the GHI folder

if i try to deploy then same thing happens,

if i try to change transport option in project properties it wont work because device is not detected

How did you deploy your app? by VS and USB port?

change from “serial to usb” or “usb to serial”?

And the version should be 4.3.x.x, what is your “x.x” ?

my current setup:

windows 8.1
visual studio 2012
.netmf sdk v4.3 QFE1
tinybooter v 4.3.4.0
tinyCLR v4.3.6.0

fez spider connected through the usb client dp module
Left switch of the for is set to on

Honestly i dont know what option that is: “serial to usb” or "usb to serial"
I only found the transport option which is mentioned in the description of the sample.

Do you have Serial to USB module or any tool that let PC talks to Spider by serial? and it is connected to socket 11? I guess you do, because you can debug and see where the exception is.

If you doesn’t have that module, and there are only FEZ Spider and USB Client DP, nothing is connected on socket 11, and you still can debug in VS, it means your configuration is wrong.

If the switch #4 is on then you can NOT deploy, debug by USB port. The FEZ Spider (or EMX_EMX) should not be shown on MF DEPLOY or FEZ Config.

usb to serial mode:
Default FEZ Spider is in USB debugger mode (switch 4 is off). In this mode, you can deploy, run, debug your app by USB port. If you want CDC, you have turn switch 4 is on => change from USB mode to serial mode. In this mode, as above, you can not debug in VS via USB port. If you want to debug in this, unless a Serial connection must be connect in socket 11.

Without VS, just hit reset then take a look under device mananger, you will see new Comport is displayed (or searching driver icon appears if the driver is not installed)

I was talking too much, :)) This way is easier for you:

Step 1:

  • Turn 1,2,3,4 off (default)
  • Hit reset
  • Deploy your app (by USB port)
  • You will get the exception as above.

Step 2:

  • Then turn only the switch 4 is on
  • Hit reset
  • Make sure that: You can not ping the device by USB. It means the friendly name FEZ Spider or EMX_EMX should be disappeared in MFDeploy or FEZ Config.

Take a look under Device Manager, new device is attached. The next step is installing the driver.

Step 3:

  • To use default driver of GHI, instead of:


change to:

```cs] Cdc cdc = new Cdc(0x1B9F, 0xF001, 0x100, 250, "GHI Electronics", "CDC VCOM", null, "CDC VCOM");[/code
1 Like

@ Dat - Might be worth while to add a document about serial debugging. The section on CDC in the USB Client document does not mention that serial debugging may have to be used.