locked
Can't access a USB device (USB GPS) via the WinJS APIs

    Question

  • Hello,

    I am trying to access data received from my USB GPS (GlobalSat G-STAR IV GPS Receiver) in a Windows 8.1 JavaScript app.

    I followed this Microsoft tutorial "Talking to USB devices, start to finish ":

    http://msdn.microsoft.com/en-US/library/windows/apps/xaml/dn312121

    I went to the Device Manager and found the useful informations:

    So my vendor ID is "0x067B" and product ID is "0x2303".

    And my Device class is FF, subclass 00 and prot 00

    If I list all devices connected on my computer using Windows.Devices.Enumeration.DeviceInformation.findAllAsync, i can see my device "Prolific USB-to-Serial Comm Port (COM3)" in the list using this code:

                Windows.Devices.Enumeration.DeviceInformation.findAllAsync().done(function success(results) {
                    var memory = [];
                    for (var i = 0, l = results.length; i < l; i++) {
                        var result = results[i];
                        var resultName = result.name;
                        if (memory.indexOf(resultName) != -1) {
                            continue;
                        }
                        if (resultName == "Prolific USB-to-Serial Comm Port (COM3)") {
                            window.deviceDescriptor = result;
                            break;
                        }
                        memory.push(resultName);
                    }}, function error(e){
                    console.log(e);
                });

    The deviceDescriptor (DeviceInformation) seem good:

    So I added the info in the manifest like stated in the tutorial:

    <Capabilities>
        <Capability Name="internetClient" />
        <!--When the device's classId is FF * *, there is a predefined name for the class. 
              You can use the name instead of the class id. 
              There are also other predefined names that correspond to a classId.-->
        <m2:DeviceCapability Name="usb">
          <m2:Device Id="vidpid:067B 2303">
            <!--<wb:Function Type="classId:ff * *"/>-->
            <m2:Function Type="name:vendorSpecific"/>
          </m2:Device>
        </m2:DeviceCapability>
      </Capabilities>

    Then I try getting the UsbDevice from the descriptor:

    Windows.Devices.Usb.UsbDevice.fromIdAsync(window.deviceDescriptor.id).done(function (usbDevice) {
                        if (usbDevice) {
                            window.usbDevice = usbDevice;
                        } else {
                            var deviceAccessStatus = Windows.Devices.Enumeration.DeviceAccessInformation.createFromId(window.deviceDescriptor.id).currentStatus;
                            console.log(deviceAccessStatus);
                            switch (deviceAccessStatus) {
                                case Windows.Devices.Enumeration.DeviceAccessStatus.deniedByUser:
                                    WinJS.log && WinJS.log("Access to the device was blocked by the user : " + deviceInfo.id, "sample", "error");
    
                                    break;
                                case Windows.Devices.Enumeration.DeviceAccessStatus.deniedBySystem:
                                    // This status is most likely caused by app permissions (did not declare the device in the app's package.appxmanifest)
                                    // This status does not cover the case where the device is already opened by another app.
                                    WinJS.log && WinJS.log("Access to the device was blocked by the system : " + deviceInfo.id, "sample", "error");
    
                                    break;
                                default:
                                    // Most likely the device is opened by another app, but cannot be sure
                                    WinJS.log && WinJS.log("Unknown error, possibly opened by another app : " + deviceInfo.id, "sample", "error");
    
                                    break;
                            }
                        }


    The app goes into the success callback but does not return a device. When I query the device status, i get "3" as a value, which is "Windows.Devices.Enumeration.DeviceAccessStatus.deniedBySystem". The comment I found in the tutorial says that i must have got my manifest wrong but I think the information I provided is ok.

    I also try querying only this device with this code:

    var string = Windows.Devices.Usb.UsbDevice.getDeviceSelector(0x067B, 0x2303);
    Windows.Devices.Enumeration.DeviceInformation.findAllAsync(string, null).done(function success(results) { ...

    But the results is an empty array.

    Can someone with WinJS knowledge help me on this? Why is the system rejecting my query? Is it because my app is listed in the COM PORT section and not in the USB devices (even tho it is a USB device)?

    Thanks a lot,

    Fabien


    Saturday, September 20, 2014 1:09 PM

All replies

  • Do you know if the device would be accessed by COM or USB if this were a desktop app? AFAIK, COM isn't supported in Store apps, but USB is. If this is accessed only via COM APIs in desktop, then you might be out of luck.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, September 22, 2014 12:19 PM
    Moderator
  • Thanks for your answer,

    I am not sure, the driver is "serial-to-com" and it is in the COM section in the device manager, maybe to be compatible with the "old softwares" that were only using COM. The simulator provided with the device seem to connect on the COM port though.

    But when I list all the devices on my machine, I can see it and the ID is "USB\\VID..." so I thought that would make it (still) a USB device, accessible via WinJS APIs. What on Windows decides if that is a COM or USB device, is it a drivers issue?

    Thanks,

    Fabien

    Monday, September 22, 2014 12:25 PM
  • I'll ask our hardware guys to check this out.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, September 22, 2014 1:40 PM
    Moderator
  • Fabien,

    Could you try out our USB CDC sample to see if it is closer to what you are looking for?

    http://code.msdn.microsoft.com/windowsapps/USB-CDC-Control-sample-5ba19caa

    Best Regards - Eric


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Monday, September 22, 2014 10:34 PM
    Moderator
  • Hello Eric,

    I tried the samples already, including the USB-CDC with no luck. I modified the packagemanifest and the hardcoded values in the code to correspond to my device but it does not get listed. Should it be "CDC"? It is not very clear what it is

    Thanks,

    Fabien

    Monday, September 22, 2014 10:36 PM
  • Fabien,

    The CDC sample is the correct one.  Which CDC device are you using?  I would re-check the manifest to see if everything looks correct. Perhaps there is an error in the file?

    Best Regards - Eric


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, October 10, 2014 11:11 PM
    Moderator
  • Hello Eric and thanks for your answer, sorry for the delay.

    I tried to modify this one in JavaScript:

    https://code.msdn.microsoft.com/windowsapps/USB-CDC-Control-sample-5ba19caa

    Opened the manifest and changed:

      <Capabilities>
        <m2:DeviceCapability Name="usb">
          <m2:Device Id="vidpid:056E 5003">
            <m2:Function Type="classId:ff * *"/>
          </m2:Device>
          <m2:Device Id="vidpid:056E 5004">
            <m2:Function Type="classId:ff * *"/>
          </m2:Device>
        </m2:DeviceCapability>
      </Capabilities>

    to

    <m2:Device Id="vidpid:067B 2303">
            <!--<wb:Function Type="classId:ff * *"/>-->
            <m2:Function Type="name:vendorSpecific"/>
          </m2:Device>

    Then in constants.js, I changed:

    supportedDevices: [
                {
                    vid: 0x056e,
                    pid: 0x5003
                },
                {
                    vid: 0x056e,
                    pid: 0x5004
                }
            ]

    to:

            supportedDevices: [
                {
                    vid: 0x067B,
                    pid: 0x2303
                }
            ]

    But nothing gets listed. Do you or your hardware colleagues have other ideas on this issue?

    Thanks a lot,

    Fabien

    Wednesday, October 22, 2014 6:08 PM