none
SerialDevice.FromIdAsync() always returns null - unless the serial adapter is plugged in after boot RRS feed

  • Question

  • As the title says, I've discovered that the SerialDevice.FromIdAsync() method always returns null if the USB to Serial Adapter is plugged in while the RPi2 is booting.

    But, If I unplug the Serial Adapter and plug it back in AFTER the RPi is completely booted the SerialDevice.FromIdAsync() method will return the SerialDevice Object for the Serial Adapter.

    Basically, the only way to get the SerialDevice.FromIdAsync() method to return a SerialDevice object is by plugging the adapter in AFTER the RPi is done booting up.

    The USB to Serial Adapter: "Silicon Labs CP2102 USB to UART Bridge".OS version on the RPi2: 10.0.10240.16384.

    Wednesday, August 19, 2015 1:58 PM

Answers

  • I found the solution - simply add these lines to Package.appxmanifest in the <Capabilities> section. 

    <DeviceCapability Name="serialcommunication">       

    <Device Id="any">         

    <Function Type="name:serialPort" />       

    </Device>   

    </DeviceCapability>

    • Proposed as answer by hdufort Wednesday, April 27, 2016 10:31 PM
    • Marked as answer by Josiah_B Tuesday, June 20, 2017 6:38 PM
    Friday, January 15, 2016 6:52 PM

All replies

  • I am having a similar issue.

    When i boot my RPi2 and run either my own application or the SerialDevice sample from github, SerialDevice.FromIdAsync(...) keeps returning null. If I plug, unplug, replug, boot the Pi with it plugged in or unplugged, nothing seems to make a difference. One day it eventually started working after a few hours of trying various things like forcing a clean deploy, commenting and uncommenting the devicecapability in the app manifest, reformatting my SD card and reflashing the image. The day after that I could not get it to work at all.

    I have three of these devices and they all work when plugged into my pc/laptop. I also tried reflashing my SD card with the IoT image but that did not help either. The device shows up in the device manager through the web console, so i am not sure what the problem is. This is super frustrating and I am disappointed that nobody from Microsoft support has commented on this issue even though there are at least two or three threads devoted to it.

    Friday, August 21, 2015 9:53 PM
  • I spoke a little too soon as well.

    For me at least, it seems that the first post works most of the time, but not every time.


    Friday, August 21, 2015 11:23 PM
  • I'm seeing similar issues, which causes issues when I reboot.

    Have you found any workaround via code / config?

    David

    Saturday, August 22, 2015 1:02 PM
  • Nope.

    I've gotten to the point where I'm convinced that its either a Device Driver issue, or some bug in the SerialDevice API.

    Saturday, August 22, 2015 3:57 PM
  • Hi Josiah,

    Trying a shot at this here as something was reported for Minnowboard at http://ms-iot.github.io/content/en-US/win10/ReleaseNotes.htm

    Quote

    "A NULL value may be returned by SerialDevice::FromIdAsync() when devices are connected to the top USB port on MinnowBoardMax (2175837) WORKAROUND: Use the bottom USB port."

    This might not be identical to what is happening on the Pi2, but worth a short trying out.

    Regards,
    Chun Siong

    Sunday, August 23, 2015 6:48 AM
  • hmm...

    I've been using the 2 USB ports farthest from the Ethernet connector and it doesn't matter which one of those I try. I'm always getting the same result.

    But now you have me thinking... I've yet to try the 2 that are closest to the Ethernet connector...

    Sunday, August 23, 2015 12:23 PM
  • hmm...

    I've been using the 2 USB ports farthest from the Ethernet connector and it doesn't matter which one of those I try. I'm always getting the same result.

    But now you have me thinking... I've yet to try the 2 that are closest to the Ethernet connector...

    I have plugged my device into each of the USB ports with no success. With my latest round of attempts I was never able to get a non-null device, regardless of USB port, rebooting,, plugged/unplugged status at boot, etc.
    Tuesday, August 25, 2015 3:31 PM
  • I have plugged my device into each of the USB ports with no success. With my latest round of attempts I was never able to get a non-null device, regardless of USB port, rebooting,, plugged/unplugged status at boot, etc.

    When I plugged my Silicon Labs device into a powered USB hub, the SerialDevice.FromidAsync() now consistently returns a non-null value if i unplug/replug it into the hub after boot. Before I could not get it to work at all, but at least now I have consistent but still broken behavior.

    Is someone from Microsoft going to address this thread at some point? I was super excited about Windows 10 IoT at first, but the support here is so poor that I am thinking about going back to a small full x86 pc solution like VIA epia. Even though those things are like 10 years old, at least I know I can deploy a working  operating system like Windows 7 compact/embedded/whatever.

     
    • Proposed as answer by Lion-1981 Saturday, August 29, 2015 9:58 AM
    • Unproposed as answer by Lion-1981 Saturday, August 29, 2015 9:58 AM
    Friday, August 28, 2015 7:40 PM
  • I made a temporary solution for this bug. Hope microsoft fix this bug quickly. 

    1、Find a USB cable to connect USB Serial module. (not directly plug USB Serial module to RPI2)

    2、Cut USB cable and find +5V line.

    3、Use 5V Relay module to control USB Cable +5V line switch.

    4、Use GPIO to control 5V Relay module switch.

    5、Write a program on app start open GPIO port power ups USB Serial module.

    6、Problem solved.

    USB Cable like this:http://www.ebay.com/itm/EF-USB-2-0-A-Male-to-A-Female-Extension-Cable-/252055674552?hash=item3aafb05eb8

    5V Relay Module like this: http://www.ebay.com/itm/10PCS-1-Channel-5V-Relay-Module-Shield-for-Arduino-uno-1280-2560-ARM-PIC-AVR-DSP-/281394349242?hash=item41846904ba

    • Proposed as answer by Lion-1981 Saturday, August 29, 2015 11:21 AM
    • Unproposed as answer by Josiah_B Wednesday, September 2, 2015 12:45 AM
    Saturday, August 29, 2015 10:10 AM
  • This won't solve our problems but the answer/problem might lie here. MS outsourced the USB stack to MCCI:

    http://www.electronicsweekly.com/news/design/embedded-systems/mcci-usb-host-stack-win-10-iot-core-raspberry-pi-2015-07/

    Because every ARM SOC implementation has its own set of peripherals (read as: unique to each vendor such as Broadcomm), the drivers are different. This is also why video is not ready.

    Gerrit

    Saturday, August 29, 2015 11:46 AM
  • Lion-1981,

    I agree with Gerrit. While your proposed solution may work to get the API working, it's not something that we should have to do. And it doesn't actually solve the problem, its more of a work-around.


    Thanks for trying to help though.
    • Edited by Josiah_B Wednesday, September 2, 2015 12:56 AM
    Wednesday, September 2, 2015 12:55 AM
  • hmm...

    I've been using the 2 USB ports farthest from the Ethernet connector and it doesn't matter which one of those I try. I'm always getting the same result.

    But now you have me thinking... I've yet to try the 2 that are closest to the Ethernet connector...


    Well, I finally had a chance to try it. No luck. I'm getting the same behavior no matter which port its plugged into.
    Wednesday, September 2, 2015 1:01 AM
  • when app started use this code:

    private GpioController gpio; private GpioPin gpioPin; public MainPage() { this.InitializeComponent(); this.gpio = GpioController.GetDefault(); if (this.gpio == null) { Debug.WriteLine("GPIO is null."); return; } this.gpioPin = this.gpio.OpenPin(18); this.gpioPin.Write(GpioPinValue.Low); this.gpioPin.SetDriveMode(GpioPinDriveMode.Output);

    // make a loop here wait usb serial power up.

    // you can use serial device now.

    }

    GpioPinValue: low or high, you can tryit to see effect, and wire follow this picture.


    • Proposed as answer by Lion-1981 Friday, September 4, 2015 7:52 PM
    • Unproposed as answer by Josiah_B Friday, September 4, 2015 10:10 PM
    Friday, September 4, 2015 7:51 PM
  • Lion-1981,

    I'm sure that your idea does work. What I'm trying to say is that the Microsoft APIs are supposed to work properly and we should not have to do something like what you have done.

    Friday, September 4, 2015 10:13 PM
  • I think it is a bug, No APIs can do this right now, Hope microsoft fix this quickly.
    • Edited by Lion-1981 Saturday, September 5, 2015 5:27 AM
    Saturday, September 5, 2015 5:27 AM
  • So glad I just found this thread, I've been futzing around with this for days thinking I was doing something wrong. I get exactly the same behaviour as Hellthorne. Frustrating that they'd release an OS version that has regressed on their own example projects. I've also noted that my USBSerial device only shows up in the device manager when another USB device is connected to the Raspberry Pi. Buggy as hell, Microsoft are you going to fix this?

    Saturday, September 5, 2015 12:02 PM
  • The same problem.I hope microsoft or silicon labs fix it soon.

    Is there any alternative usb to UART that is not presenting that problem?

    Monday, October 19, 2015 4:59 PM
  • Hello everyone!

    We've identified the cause and a resolution for the issue in which SerialDevice.FromIdAsync() returns a null value in Windows 10 IoT Core.  This behavior is due to a conflict with a process running by default on the IoT Core device. To resolve this issue, please follow the steps below:

    Raspberry Pi 2 and Dragonboard 410c

    Windows 10 IoT Core launches a Z-Wave background application at startup and by default. The Z-Wave application will claim a Silicon Labs CP210x device and block other applications from using it.  If the Z-Wave application is not being used by your Windows 10 IoT Core applications, it should be removed from the startup list, making the Silicon Labs CP210x devices available as an interface for other applications. 

    Follow the steps below to resolve this issue:

    1. Connect to the Windows 10 IoT Core device through SSHor PowerShell 
    2. Run the commandiotstartupremove headless ZWave
    3. Reboot the device

    Minnowboard Max

    Windows 10 IoT Core returns an error (Error Code 31) when attempting to access the Silicon Labs serial driver interface because no COM port is defined. 

    Follow the steps below to resolve this issue:

    1. Connect to the Windows 10 IoT Core device through SSHor PowerShell
    2. Ensure the serial device is connected to the Windows 10 IoT Core device
    3. Run the commandegadd "HKEY_LOCAL_MACHINE\system\controlset001\enum\usb\VID_10C4&PID_EA60\0001\Device Parameters" /v PortName/t REG_SZ /d COM3  
    4. Reboot the device

    Calls to SerialDevice.FromIdAsync() will succeed and and retrieve expected results.




    Thursday, November 12, 2015 10:22 PM
    Moderator
  • Hi

    I have a problem with the cp2102.

    in the before days i was using the iot v.10.0.2xx(Don't remember the exact reference) and with it i was using the cp2102 fine(Just with the problem of reconnect it after the device boots). but i'm using the iot v.10.0.10556 and the cp2102 is not working, it just work when i run the OS for the first time. after i reboot the cp2102 never turn's on again, i don't know why.I need some help.

    Regards.

    Oscar.

    Tuesday, November 24, 2015 8:05 PM
  • I have a similar problem but it only occurs when I run my app headless on my rpi.  I have two versions of my app.  The headless version derives from IBackgroundTask, and the headed is derived from Page.  When running the headless app case, FromIdAsync() returns null always.  Whereas if I run that app headed, FromIdAsync works correctly and I am returned a valid serial port.  In both cases the ID string passed to FromIdAsync is the same:

    "\\\\?\\FTDIBUS#VID_0403+PID_6015+DA00V7Q8A#0000#{86e0d1e0-8089-11d0-9ce4-08003e301f73}"

    Is there something else that I need to set or run in the headless case to get the USB to work correctly?  I have tried the work arounds to remove ZWave and plug into different USB ports, but it just doesn't work headless.

    Jim

    Friday, January 15, 2016 5:02 PM
  • I found the solution - simply add these lines to Package.appxmanifest in the <Capabilities> section. 

    <DeviceCapability Name="serialcommunication">       

    <Device Id="any">         

    <Function Type="name:serialPort" />       

    </Device>   

    </DeviceCapability>

    • Proposed as answer by hdufort Wednesday, April 27, 2016 10:31 PM
    • Marked as answer by Josiah_B Tuesday, June 20, 2017 6:38 PM
    Friday, January 15, 2016 6:52 PM
  • My own newly written app didn't work with copy of sample code.

    The sample code worked... so it had to be something like this.

    Cool... it fixes the 'problem'

    thanks

    Wednesday, March 23, 2016 11:54 PM
  • THANK YOU Jim198!

    This should be in the UsbDevice.FindIdAsync docs.  I just wasted about an hour trying to figure out why I was getting null.  ...Some exception should also be thrown IMHO.

    Anyways, thanks to you I figured out how to make mine work.  I'm using my own USB device (a NETMF board) so WinUSB and just the generic interface.  I had to add this code...

        <DeviceCapability Name="usb">
          <Device Id="vidpid:dead 0110">
              <Function Type="name:vendorSpecific"/>
          </Device>
        </DeviceCapability>

    It's also frustrating that this wasn't available in the UI.  Because I had looked in my App's Package for a USB related setting.  There wasn't one.

    ALSO, I had to switch to Chrome to make this comment happen.  Edge wouldn't work.  Pressing backspace from within the textbox the page navigated away.  And when I pasted my text was a mess.  Of course, it worked perfectly with Chrome.

    Seriously Microsoft, get it together!

        
    • Edited by Untitled86 Tuesday, April 26, 2016 7:38 PM wanted to give Jim credit
    Tuesday, April 26, 2016 7:38 PM
  • Hi Brien,

    Could you please suggest an update to the doc in question at GITHUB?  That way the doc owner will be made aware of the issue directly.

    Sincerely,

    IoTGirl

    Tuesday, April 26, 2016 8:10 PM
    Moderator
  • You are the men! Jim198

    I would like to add to your input, that if I add the DeviceCapability to the uper section of the Capabilities, it have fail.

    but if I place it to the end, like this:

      <Capabilities>
        <Capability Name="internetClient" />
        <Capability Name="internetClientServer" />
        <Capability Name="privateNetworkClientServer" />
        <DeviceCapability Name="location" />
        <DeviceCapability Name="serialcommunication">
          <Device Id="any">
            <Function Type="name:serialPort" />
          </Device>
        </DeviceCapability>
      </Capabilities>
    All go fine!

    Wednesday, April 27, 2016 9:24 PM
  • Thank you.  I'm on a 64-bit Intel machine and didn't know I had to do this.
    Tuesday, November 22, 2016 1:37 AM
  • This [Jim198's answer] fixed my problem.

    As an aside, I've been a programmer for 15 years and have never once upvoted anything on this forum.. until just now. So, can anyone tell me why this particular answer, with more than twice the upvotes of any of the others (as far as I can tell), is buried under so many 0-votes and generally unhelpful posts?



    Tuesday, June 20, 2017 6:32 PM
  • This is an old thread but I agree, Jim198's answer seems to be the one people are looking for.
    I've changed the answer from Microsoft's pick to Jim198's. Hopefully that will help others find it easier.
    Tuesday, June 20, 2017 6:42 PM
  • Oddly this demo Sample seems to always work...!!??

    https://github.com/Microsoft/Windows-iotcore-samples/tree/develop/Samples/SerialUART

    Monday, May 14, 2018 3:56 AM