none
SerialDevice.FromIdAsync always returns null on Raspberry Pi 2? RRS feed

  • Question

  • I am trying to communicate with a serial device on RPi2 but I have run into a problem.

    In my own application, whenever I try to create the serial device 

    var serialPort = await SerialDevice.FromIdAsync(device.Id);

    serialPort is always null. I am using a silicon labs USB to TTL device that shows up in the device manager, and through debugging my application, I can see that the device info is enumerated properly. It's just the creation that fails.

    I downloaded and ran this sample ( http://ms-iot.github.io/content/en-US/win10/samples/SerialSample.htm ) and it also crashes because serialPort is null:

    DeviceInformation entry = (DeviceInformation)selection[0];         
    
        try
        {                
            serialPort = await SerialDevice.FromIdAsync(entry.Id);
    
            // ...
    
            // Configure serial settings
            serialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000); // throws null exception here
            serialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000);                
            serialPort.BaudRate = 9600;
            serialPort.Parity = SerialParity.None;
            serialPort.StopBits = SerialStopBitCount.One;
            serialPort.DataBits = 8;
    
            // ...
        }
        catch (Exception ex)
        {
            // ...
        }

    I built and ran the sample with absolutely no modifications, so it should work, but serialPort is always null.

    Is there a known issue with SerialDevice.FromIdAsync ? Am I missing a step somewhere? Is the sample out of date?

    This is really frustrating because my FTDI devices are not supported so i ordered the exact Silicon Labs USB to TTL device suggested in the sample, and while it does show up in the device enumeration I can't actually use it!

    Thanks for any advice.

    Monday, August 17, 2015 4:37 PM

Answers

  • 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:23 PM
    Moderator

All replies

  • For reference, the application does work with MBM UART2. Did you update the package.appxmanifest and add the PnP information to the Capabilities section?

    Sean Liming - Book Author: Starter Guide SIM (WEI), Pro Guide to WE8S & WES 7, Pro Guide to POS for .NET - www.annabooks.com / www.seanliming.com

    Monday, August 17, 2015 5:32 PM
  • I used the sample as-is from github, so I did not modify anything.

    this is the only entry in the appmanifest:

    <Capabilities>
        <DeviceCapability Name="serialcommunication">
          <Device Id="any">
            <Function Type="name:serialPort" />
          </Device>
        </DeviceCapability>
      </Capabilities>

    (it came that way from the sample on github). I should mention (if it's not obvious) that I am using the C# version of the sample, since my own app is written in C#. I am not sure if the C++ sample works.

    Monday, August 17, 2015 6:23 PM
  • I used the same C# on MBM. I thought the Capabilities had to be set specifically for a USB port. The Channel 9 video discusses this: https://channel9.msdn.com/events/Build/2015/3-81

    Sean Liming - Book Author: Starter Guide SIM (WEI), Pro Guide to WE8S & WES 7, Pro Guide to POS for .NET - www.annabooks.com / www.seanliming.com

    Monday, August 17, 2015 6:43 PM
  • watched the video - they use the same capabilities that the sample uses, however, the video does mention that I can query DeviceAccessInformation to see why the device is null. Apparently there is some concept user access settings for serial devices. I am not sure what the story is there with the RPi2. I'll amend my code when I get home from the office to see if the DeviceAccessInformation uncovers why this is happening.
    Monday, August 17, 2015 7:46 PM
  • watched the video - they use the same capabilities that the sample uses, however, the video does mention that I can query DeviceAccessInformation to see why the device is null. Apparently there is some concept user access settings for serial devices. I am not sure what the story is there with the RPi2. I'll amend my code when I get home from the office to see if the DeviceAccessInformation uncovers why this is happening.

     I added the following to the sample and aded a breakpoint:

    if(serialPort == null)
    {
        var status = DeviceAccessInformation.CreateFromId(entry.Id).CurrentStatus;
        int noop = 0; // breakpoint here
    }

    the value of status when the breakpoint triggers is "unspecified"

    At this point I am still unsure why this is not working. It's frustrating and I am seriously considering switching to Minnowboard Max

    Tuesday, August 18, 2015 12:04 AM
  • Try these:

    1. Plug in the USB to Serial adapter AFTER you start the RPi.
    2. Double check to make sure that the SerialPort capability is still in the .appx manifest. I've had Visual Studio remove it without me knowing. (That caused a lot of headaches)
    3. Download and re-flash the latest version of IoT Core for the RPi.

    Silicon Labs CP21x USB to Serial Adapters do work with the RPi 2 and Windows 10 IoT Core. I have one, that after much frustration, is now working.

    Tuesday, August 18, 2015 12:54 PM
  • Try these:

    1. Plug in the USB to Serial adapter AFTER you start the RPi.
    2. Double check to make sure that the SerialPort capability is still in the .appx manifest. I've had Visual Studio remove it without me knowing. (That caused a lot of headaches)
    3. Download and re-flash the latest version of IoT Core for the RPi.

    Silicon Labs CP21x USB to Serial Adapters do work with the RPi 2 and Windows 10 IoT Core. I have one, that after much frustration, is now working.

    so unplugging and then re-plugging the device seems to fix the problem, but of course it's untenable since I will have the device installed in an inaccessible location once the project is complete (going to be installed behind the dash in a 1970's VW beetle)

    hopefully this will be resolved in a subsequent release, but this is kind of frustrating. 

     
    Wednesday, August 19, 2015 4:16 AM
  • Yeah, and I'm in the same situation. I'm going to be putting mine in an inaccessible location where power could go out and it needs to startup properly when power is restored.

    I'm going to start another thread on this.

    EDIT: Here's the thread that I just started on this issue: https://social.msdn.microsoft.com/Forums/en-US/b9633593-377e-4d6f-b3a9-838de0555371/serialdevicefromidasync-always-returns-null-unless-the-serial-adapter-is-plugged-in-after-boot?forum=WindowsIoT


    • Edited by Josiah_B Wednesday, August 19, 2015 9:36 PM
    Wednesday, August 19, 2015 1:34 PM
  • Yeah, and I'm in the same situation. I'm going to be putting mine in an inaccessible location where power could go out and it needs to startup properly when power is restored.



    I spoke a little too soon i guess. the next day after I got my device working, SerialDevice.FromIdAsync(...) kept returning null whether I plugged, unplugged, replugged, booted the Pi with it plugged in or unplugged. Eventually it started working after a few hours of trying various things. 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.

    Friday, August 21, 2015 9:48 PM
  • I was able to get my silicon labs device to consistently work if i attach it to a powered USB hub after booting the pi, or unlugging/replugging. If I attach the device directly to the pi, it almost never works.

    fortunately for me, I found this solution for FTDI devices: https://github.com/Jark/FTDISample

    It works, and the FTDI device works even connected at boot, so I am probably going to abandon the Silicon Labs devices. It's a shame that the microsoft APIs don't work correctly.

    Friday, August 28, 2015 7:33 PM
  • I am using Silicon Labs CP2102 USB to UART Bridge

    Here, once the USB is connected, I got roughly 20 seconds to lunch the application. If it done within that time serialPort will NOT be null and can open the port.

    If its get late than that, serialPort becomes null.

    Another thing I have noticed is that, when its null, the pi is sending some garbage data to the USB to UART. May be that's why I cannot open the port.

    Friday, October 2, 2015 6:25 PM
  • This problem is affecting everybody, please resolve it soon.

    Monday, October 19, 2015 5:19 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:23 PM
    Moderator
  • If you are using the same code in x86 application on windows 10 Home 

    var serialPort = await SerialDevice.FromIdAsync(device.Id);

    Still you get null back 

    I am not even compiling the application by selecting ARM I am right now testing on local machine 

    and if you try the command in power shell on your Windows 10 Home

    remove headless ZWave

    it does not run as it says "the term headless is not recognized"


    Monday, August 1, 2016 12:36 AM
  • @Hammad Rafique

    remove headless is a Windows IoT Core command


    Monday, August 1, 2016 8:56 AM
    Moderator