Cobra 3 -> usb host serial

Hello!

This is my first project with the cobra, though I do have experience on the spider with a few projects before.
I’ve read through the …docs/36 giving info about usb serial and it seems like it should be very straightforward.

I am able to plug a usb serial mouse into the cobra usb host and can see that it is connected, so that makes me
think I have the code setup ok with the right assembly and am using GHI.Usb.Host ok.

But, I want to do usb serial using a terminal program with a usb-usb null modem cable connected to my computer (win 7) on one end and the cobra usb host on the other.
I installed the ftdi virtual com drivers and seems like it installed ok but I’m not really seeing anything when I check the devices on my computer.

I guess I’m expecting to see some com port show up when I connect the cable to my computer but not seeing it.
I’m beginning to wonder if I’m supposed to do more than just install the ftdi driver but not sure what that would be…

I have a breakpoint set in the function Controller_USBSerialConnected but never gets tripped.

My code is like the document:
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;
}

etc…

Help is greatly appreciated and needed!!

ok, maybe I know what is wrong but can someone with experience confirm?

I have a usb-usb null modem cable I bought from Fry’s but now starting to think I have
to have the FTDI cable as it has a pcb inside that crosses tx/rx and maybe pulls down the line (can’t tell from website).

an FTDI (or any USB to serial device) is actually not needed. That can allow a standard serial port (RX/TX pins) to be connected to a USB port and work.

The “null modem” cable is wrong - set it aside and enjoy not doing anything with it.

The fact you have the USB mouse working shows you have something going. But USB Host Serial is NOT what you want to allow you to communicate to a PC. You just want USB Client CDC, see https://www.ghielectronics.com/docs/20/usb-client#106 for the deets.

USB Host means you can have a UART sending device like another microcontroller that is connected to an FTDI.

1 Like

Thanks for your response Brett, I knew I could use the client but I would be giving up the ability to debug in that case so thought
I could use the usb host even though it is not the normal way to use it.

Anyway, thanks again, I will try using your suggestion, maybe I can use the debugger and do communication over the same port at the same time, I never thought of it that way…

Trying to use the the client, I get an exception on Controller.ActiveDevice = vsp;
(using same code per your link above).
I think the exception is due to trying to run/deploy on usb at same time trying to use the usb client for application.

Looks like I would have to deploy & debug serially and I’ve seen a few posts where they had problems doing that.
I’m sure it does work but looks like a pain to make it work.

In your post above talking about FTDI, I don’t know if you have considered this (see image)…

Can someone answer my question?
I cannot get this code to work which I copied from ghi support document:

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;

whenever the above line is executed, I get a System.InvalidOperationException.
Under debug, I can see that vsp is a GHI.Usb.Client.Cdc object which appears to have valid stuff inside (streams, etc).
The Controller.ActiveDevice is null.

The stack trace is:
GHI.Usb.Client.RawDevice::NativeInitialize
GHI.Usb.Client.RawDevice::Activate
GHI.Usb.Client.Controller::set_ActiveDevice
MyProg.Program::Main

In my program resource extensions, I have GHI.Usb version 4.3.8.1.

Q: Does executing above statemente matter if I’m debug/deploy using the usb client?

thanks!

@ dave001 - Are you running CDC and debug over the USB cable, or are you doing serial debugging? Have you loaded the CDC driver on the PC?

try putting a few seconds of sleep at the beginning of your program to let things initialize behind the scenes.

1 Like

yes, that error makes sense to me when you’re still using the USB connection for debugging - it’s in use, so not able to be used for CDC.

1 Like

Ok, I hope my experiment will be useful to someone because I finally got what I wanted to work and
that is connect the Cobra usbhost (not usbclient) to another usbhost on the computer and have it work
like a usbserial connection. Now I have the debug and deploy using the normal usb client and can use
the usb host for communicating to a computer.

Last week, after realizing that a null modem cable would not work (thanks Brett), I decided to try a special USB NMC from www.ftdichip.com.
(cost about $36 which I understand some people would not want to buy but for me it is worth it).
This cable came in today and lo and beholds works like a charm. Note that you need to install the ftdi driver on the computer but thankfully
nothing extra is needed on the Cobra side.

I now have the usb host connected via this special usb null modem cable to a computer terminal program and working fine.
There is some kind of bridge pcb built into the cable which makes this work.

The computer device manager shows a usbSerial connection.
My code is just like the GHI code snippet:

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

}

1 Like