USB Host in MF 4.3

In MF 4.3, for the USB Host, when a serial device is plugged in, I do not get the UsbSerialConnected event, instead I get the RawDeviceConnected event. I need to get the UsbSerialConnected event so I can get the parameter UsbSerial object so that I can read and write to the serial device. How do I make use of RawDeviceConnected to read and write the serial device, as there is no UsbSerial object passed?

In the class constructor, I do this:


          // Subscribe to USBH event.
            Controller.UsbSerialConnected += Controller_UsbSerialConnected;
            Controller.RawDeviceConnected += Controller_RawDeviceConnected;
            Controller.DeviceConnectFailed += Controller_DeviceConnectFailed;
            Controller.JoystickConnected += Controller_JoystickConnected;
            Controller.KeyboardConnected += Controller_KeyboardConnected;
            Controller.MassStorageConnected += Controller_MassStorageConnected;
            Controller.MouseConnected += Controller_MouseConnected;
            Controller.WebcamConnected += Controller_WebcamConnected;
            Controller.Start();

My event handler for the UsbSerialConnected event:



        /// <summary>
        /// USB device connected event handler
        /// </summary>
        /// <param name="device"></param>
        private void Controller_UsbSerialConnected(object sender, UsbSerial _usbSerial)
        {
            try
            {
                Debug.Print("UsbSerial connected.");
                serialUSB = _usbSerial;
                //serialUSB.DataReceived += usbSerial_DataReceived;
                serialUSB.Disconnected += usbSerial_Disconnected;
                switch (serialUSB.Type)
                {
                    case BaseDevice.DeviceType.SerialFTDI: // FTDI connected
                        Debug.Print("FTDI device connected");
                        break;

                    case BaseDevice.DeviceType.Unknown: // SiLabs but not recognized
                        Debug.Print("Unknown device connected");
                        break;

                    case BaseDevice.DeviceType.SerialCDC:
                        Debug.Print("CDC device connected");
                        break;

                    case BaseDevice.DeviceType.SerialSiLabs:
                        Debug.Print("SiLabs device connected");
                        break;

                    default:
                        Debug.Print("Not used device.TYPE device connected");
                        break;
                }
                serialUSB.BaudRate = 9600;
                serialUSB.Parity = System.IO.Ports.Parity.None;
                serialUSB.DataBits = 8;
                serialUSB.StopBits = System.IO.Ports.StopBits.One;
                serialUSBReadThread = new Thread(SerialUSBReadThread);
                Thread.Sleep(100);
                serialUSBReadThread.Start();
                USBHostConnected = true;

            }
            catch (Exception ex)
            {
                Controller.Error err = Controller.GetLastError();
                Debug.Print("USB Error Description: " + err.ToString() + " Exception: " + ex.ToString());
            }
        }

And handlers for the other events:


        void Controller_WebcamConnected(object sender, Webcam e)
        {
            Debug.Print("USB web cam device connected");
            e.Disconnected +=e_Disconnected;
        }

        void Controller_RawDeviceConnected(object sender, RawDevice e)
        {
            Debug.Print("USB raw device connected");
            e.Disconnected +=e_Disconnected;
        }

        void Controller_MouseConnected(object sender, Mouse e)
        {
            Debug.Print("USB mouse device connected");
            e.Disconnected +=e_Disconnected;
        }

        void Controller_MassStorageConnected(object sender, MassStorage e)
        {
            Debug.Print("USB mass storage device connected");
            e.Disconnected += e_Disconnected;
        }

        void e_Disconnected(BaseDevice sender, EventArgs e)
        {
            Debug.Print("USB device disconnected");
        }

        void Controller_KeyboardConnected(object sender, Keyboard e)
        {
            Debug.Print("USB keyboard device connected");
            e.Disconnected +=e_Disconnected;
        }

        void Controller_JoystickConnected(object sender, Joystick e)
        {
            Debug.Print("USB joystick device connected");
            e.Disconnected+=e_Disconnected;
        }

        void Controller_DeviceConnectFailed(object sender, EventArgs e)
        {
            Debug.Print("USB device connect failed");
        }

The UsbSerialConnected does not get called when I plug in a CDC or SiLabs USB serial device into the USB host, instead, the RawDeviceConnected event gets called, so I do not get the UsbSerial object.

@ dspacek - We do not handle non-FTDI serial connections properly in the current SDK. That will be fixed in the next one. UsbSerialConnected will be raised for FTDI, CDC, SiLabs, Sierra, and Prolific. However, all but FTDI are obsolete, not fully supported, and may not function at all.

@ John - I misspoke in the last post. I should have said all but FTDI and CDC are obsolete.