USB Host - usb to serial possible?

Hello!

Sorry to bother you again, but I was wondering if it is possible to use a usb to serial cable with FEZ USB host?

I have a SSC32 (servo controller) board lying around, and I was wondering if I can connect it to FEZ?

If so, is it possible with a usb to serial cable, or should I use/do something else?

Thanks again!

How dare you bother us again :stuck_out_tongue: I am just kidding…you are always welcome to ask anyhting you have on your mind

Yes you can. Have looked at USB serial class in documentaion? :wink:

You can use a USB to serial cable or use the RS232 shield.
I think we used this controller on an old project of ours (link removed)

See above.

Wow! that was a super fast response! I’m impressed! :wink:

Yes, and it’s not working for me, that’s why I’m asking.

Details:

Code:

static void DeviceConnectedEvent(USBH_Device device)
        {
            Debug.Print("device connected");

            switch (device.TYPE)
            {
                case USBH_DeviceType.Serial_FTDI:
                    serialUSB = new USBH_SerialUSB(device, 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
                    serialUSB.Open();
                    serialUSBThread = new Thread(SerialUSBThread);
                    serialUSBThread.Start();
                    break;
            }
        }

Exception in C#:

[quote]The thread 0x2 has exited with code 0 (0x0).
device connected
#### Exception System.Exception - 0xffffffff (3) ####
#### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::Init [IP: 0000] ####
#### GHIElectronics.NETMF.USBHost.USBH_SerialUSB::.ctor [IP: 0039] ####
#### FEZ_USB_SERIAL.Program::DeviceConnectedEvent [IP: 001f] ####
#### GHIElectronics.NETMF.USBHost.USBH_DeviceConnectionEventHandler::Invoke [IP: 0000] ####
#### GHIElectronics.NETMF.USBHost.USBHostController::nativeEventDispatcher_OnInterrupt [IP: 0037] ####
#### GHIElectronics.NETMF.System.InternalEvent::nativeEventDispatcher_OnInterrupt [IP: 0054] ####
A first chance exception of type ‘System.Exception’ occurred in GHIElectronics.NETMF.USBHost.dll
An unhandled exception of type ‘System.Exception’ occurred in GHIElectronics.NETMF.USBHost.dll[/quote]

at line:

serialUSB = new USBH_SerialUSB(device, 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);


Oh, I forgot… You did indeed use an SSC32 on that project. Nice work!

Thank you!

Make sure you have the latest firmware. earlier ones reported a device type as FTDI incorrectly.
See this post:
http://www.tinyclr.com/forum/1/209/

What firmware version is on your board? Did you update to the latest? See release notes please

No error now. I feel ashamed, a lot.
I did notice the new release, but thought this was a beta for 2010… :confused:

Anyway. No errors now and the program runs fine.

One question left:

byte[] data = Encoding.UTF8.GetBytes("#1, P1500, T750");
serialUSB.Write(data, 0, data.Length);

Is my approach correct?

Last release was the production release…which means the release that everyone should use :slight_smile:

Your approach is correct.

Edit:

A new cable (profilic) works. (it’s sending data)

Now the only thing left, is a moving servo… so far no movement, yet…

static void SerialUSBThread()
        {
            byte[] data = System.Text.Encoding.UTF8.GetBytes("#16, P1500, T750");

            while (true)
            {
                Thread.Sleep(1000);
                serialUSB.Write(data, 0, data.Length);
                Debug.Print(data.ToString());
            }
        }

Which returns System.Byte[] to the debug window, is this correct?

Converting an array ToString() will result in the array type and not the values of the array!


// Convert string to byte array
byte[] data = System.Text.Encoding.UTF8.GetBytes("FEZ is Easy!");
// Convert byte array to string
string str = new string(System.Text.Encoding.UTF8.GetChars(data));
Debug.Print(str);

Yes I know, but still the servo is not movin… :frowning:

The data is filled with the correct command, but it seems that the data is not reaching the SSC32.

I am now copying the code from your project to mine, but still no movement…?

Thanks

We have two prolific drivers, try to use the other one… If no luck then there might problems in the commands you are sending. You can change the device type to Prolific2 as shown in previous posts.

namespace MFConsoleApplication1
{
    public class Program
    {
        static USBH_SerialUSB serialUSB;
        static Thread serialUSBThread; // Prints data every second

        public static void Main()
        {
            USBHostController.DeviceConnectedEvent += DeviceConnectedEvent;

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

        static void DeviceConnectedEvent(USBH_Device device)
        {
            switch (device.TYPE)
            {
                case USBH_DeviceType.Serial_Prolific: // Prolific connected                                     
                    Debug.Print("Device connected");
                    Debug.Print("Prolific");
                    serialUSB = new USBH_SerialUSB(device, 115200, System.IO.Ports.Parity.None, 8,
                        System.IO.Ports.StopBits.One);

                    serialUSB.Open();
                    serialUSBThread = new Thread(SerialUSBThread);
                    serialUSBThread.Start();
                    break;
            }
        }

        static void SerialUSBThread()
        {
            byte[] data = Encoding.UTF8.GetBytes("#0,P1500,T1000");

            while (true)
            {
                Thread.Sleep(1000);
                serialUSB.Write(data, 0, data.Length);
                string str = new string(System.Text.Encoding.UTF8.GetChars(data));
                Debug.Print(str);
            }
        }
    }
}

Hope this helps. Getting headache of this… :frowning:

I have had a little thought about this… I am wondering if it’s not the cable which causes it not to work…?

Which cables do you suggest? The sitecom cable needs a driver when plugging into pc. So that one is not good, the other one seems to be needing a driver too, but no idea who produced this cable.

Might be time to get a new one…?
What do you think?

Plug the cable to your pc and load drivers. Then open “device manager” and look for your cable in there. In the settings you should be able to see what is the driver name and who makes it

or open the inf file of windows drivers

Ok, will do that.

But I thought FEZ could only work with driver-less clients?

Thanks.

All USB devices have drivers but some have standard drivers and they are built into FEZ and windows. GHI also adds drivers for common serial-USB chipsets like silab, prolific and FTDI.

Not to forget about the raw USB access where you can simply write any driver for any device.

So, even if my cable needs a driver, it should work?

Plugged the cable into the PC.

[quote]Supplier: unknown
Listed as: USB-Serial controller [/quote]
this is the cable with the prolific chip.

The other one is a sitecom cable:

Yes you can support any cable if you have knowledge of USB and the chipset used. We do not recommend that since you must have good knowledge to write drivers. It is easier to just order an FTDI cable. There are many FTDI cables out there…usually FTDI cost a bit more since the chipset cost more.
Examples:
http://www.saelig.com/product/U004.htm
http://www.saelig.com/product/U003.htm

By the way there are other devices that use FTDI like this temperature/humidity sensor http://www.saelig.com/product/DLTHD1.htm

The cable makers do not make the chipset inside. It is usually prolific or FTDI.

guess it’s time for a new cable then… :wink:

Checked out the two cables you gave me, but shipping from these companies is not an option.
I have checked out the farnell website;

This one would work I guess? It’s an FTDI cable, so it should…?