building apps for usb accessories develop apps that can connect with hardware from the past and...
TRANSCRIPT
![Page 1: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/1.jpg)
![Page 2: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/2.jpg)
Session 3-81
Building apps for USB Accessories
George Roussos Arvind AiyarSenior Program Manager Senior Software Engineer
![Page 3: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/3.jpg)
Develop apps that can connect with hardware from the past and present
![Page 4: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/4.jpg)
Windows 10 introduces
1) USB Accessories on Phones2) Windows.Devices.SerialCommunication
enabling you to develop apps that connect with hardware from the past and present.
![Page 5: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/5.jpg)
USB Accessories1. Typical accessories and demo2. Vendor specific accessories and
demo
Serial Communication3. Overview and demo4. Getting Started5. Device discovery6. Basic communication7. Additional features
Resources and Call To Action
Agenda
![Page 6: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/6.jpg)
• Windows 10 Mobile SKU adds support for USB connected accessories on new Phones and Tablets via USB Dual Role.
• Developers can build accessories based upon open industry standard hardware without per-unit royalties.
USB Accessories
![Page 7: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/7.jpg)
Windows 10 supports two kinds of USB Accessories in Mobile SKU:
1. Typical accessories2. Vendor specific
accessories
USB Accessories in Windows 10 Mobile SKU
Click icon to add picture
![Page 8: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/8.jpg)
Typical accessories on Mobile SKUAccessories that just work with OS
• Windows natively supports these accessory types regardless of who makes the hardware.
• Windows provides built-in OS experiences for many of them
Examples Accessories Namespace
AudioMicrophoneMIDISpeakers
Windows.Media.CaptureWindows.Devices.MidiAudioGraph (new for Windows 10)
FilesRemovable Storage Windows.Storage
Point of Service
Magnetic Stripe Reader
Barcode Scanner
Windows.Devices.PointofService.BarcodeScanner
Windows.Devices.PointofService.MagneticStripeReader
Also productivity oriented accessories like keyboards, mice and network adapters
![Page 9: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/9.jpg)
Demo: USB Flash Drive
![Page 10: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/10.jpg)
• Examples: Fitness devices, Robots, Smart Toys, etc
Vendor specific accessories
![Page 11: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/11.jpg)
Demo: Arduino
![Page 12: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/12.jpg)
Vendor specific accessories on Mobile SKU
API Namespace SDK Sample(s)
HID Windows.Devices.HumanInterfaceDevice
Custom HID Device Access
Serial Windows.Devices.SerialCommunication Custom Serial Device Access
USB Windows.Devices.Usb Custom USB Device Access
![Page 13: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/13.jpg)
• Use OS inbox drivers for HID, USBSerial, or WinUSB.
• Accessories should report hardware or compatible IDs that install these drivers.
• Mobile SKU does NOT support installing vendor drivers from WU
• Audience Challenge: Produce a USB to RS232 cable that reports these compatible IDs
Click icon to add picture
Driver installation for vendor specific accessories
API Compatible IDs
HID Follow Standard. Report Vendor_Specific Top Level Collection
Serial USB\Class_02&SubClass_02&Prot_01USB\Class_02&SubClass_02
WinUSB
WinUSB (Winusb.sys) Installation
![Page 14: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/14.jpg)
1. Start developing a universal app on desktop w/ USB port
2. Make sure the UX of your app lays out properly on phones
3. Once available get a Dual Role capable Mobile device to test your app with accessories
Start developing apps for USB Accessories
![Page 15: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/15.jpg)
• New Phones and Tablets that support USB dual role
• Before you buy a new device
• Should be clear in device marketing if USB dual role is supported or not
• On your current deviceUSB Settings UX informs users if their mobile device supports USB connections or not
Identifying mobile systems that support USB Accessories
![Page 16: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/16.jpg)
Serial Communication using WinRT
![Page 17: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/17.jpg)
Overview
![Page 18: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/18.jpg)
Device Protocol APIs
New Windows Runtime APIs:• Bluetooth• Bluetooth
Smart• HID• USB• Serial• Serial
Innovative
Devices
Ecosystem of Apps
Independent
Developers
![Page 19: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/19.jpg)
Unified and built-in model for device discovery, access and instantiation
New Windows Runtime API that simplifies communicating to/from your device
Works with Universal Apps – write once, deploy everywhere …
Serial in Windows 10
![Page 20: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/20.jpg)
Prerequisites
1. Working knowledge of Serial Communication• Introduction to Serial Communications – MSDN
2 . Good to know …• Win32 Serial Programming interface - MSDN• .NET serial programming interface - MSDN
3. Knowledge of Windows Runtime concepts and paradigms
• Async operations• Data buffers and streams• Fundamentals of working with devices
3
Before you begin…
![Page 21: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/21.jpg)
AppContainer
Architecture diagram
Architecture
Windows Store app
Device Access Broker
Native Serial layer
Serial device
Windows.Devices.SerialCommunication API
![Page 22: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/22.jpg)
Demo: Arduino
![Page 23: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/23.jpg)
Getting Started
![Page 24: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/24.jpg)
Accessing devices from the Windows Runtime
1) Author an app manifestDeclare the correct capability for your device
2) Device discoveryFind out what devices are connected to your
system
3) Find the device you’re looking forInformation about a specific device
4) CommunicateAccess information on your device
5) Clean up resources
Capability
Device discovery
Communication
Cleanup
![Page 25: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/25.jpg)
App capabilities (i.e. app manifest)
1. Declare the device capability• DeviceCapability Name=“serialcommunication”
2. Declare the device • Device Id=“any” - if you want all serial devices
• Device Id=“vidpid:<vid> <pid>” - if you want a specific device
3. Declare usages• Function Type=“name:serialPort”
3.
Capability
Device discovery
Communication
Cleanup
![Page 26: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/26.jpg)
Editing the Package.appxmanifest
![Page 27: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/27.jpg)
AppXmanifest: examplePackage.appxmanifest:
<Capabilities>
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability >
<DeviceCapability Name="serialcommunication">
<Device Id="vidpid:2341 0043">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
</Capabilities>
![Page 28: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/28.jpg)
• Finding serial devices on your system
Device discovery
![Page 29: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/29.jpg)
Device discovery
• Traditional mechanism uses COM ports – which has issues• COM1, COM2 isn’t very descriptive about the device• The actual port name will vary across systems• Port assignment relies on driver components that are not
always there.
• Augmented discovery model in WinRT• Supports more descriptive device identifiers or
names that are independent of driver components.• Supports identification of a USB serial device via
VID/PID
Capability
Device discovery
Communication
Cleanup
![Page 30: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/30.jpg)
Device discovery
1. Use the static DeviceSelector methods in SerialDevice to build a serial-specific AQS:
• SerialDevice.GetDeviceSelector();
• SerialDevice.GetDeviceSelector(portName);
• SerialDevice.GetDeviceSelectorFromUsbVidPid(vid, pid);• You can augment the selector to be more specific.
2. Use the Device Enumeration APIs to find the serial device• DeviceInformation.FindAllAsync(aqsFilter) OR• DeviceInformation.CreateWatcher(aqsFilter)
3. Use an enumerated DeviceInformation object to instantiate a SerialDevice• SerialDevice.FromIdAsync(DeviceInformation.Id)
Capability
Device discovery
Communication
Cleanup
![Page 31: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/31.jpg)
Device discoveryusing Windows.Devices.SerialCommunication;
using Windows.Devices.Enumeration
// Create an AQS using on of the static DeviceSelector methods
// USB VID/PID selector
string selector = SerialDevice.GetDeviceSelectorFromUsbVidPid(vid, pid);
// Friendly Name selector
string selector2 = SerialDevice.GetDeviceSelector(“COM1”);
// Pass the selector to FindAllAsync to get a collection of DeviceInformation // objects.
DeviceInformationCollection deviceInformation;
deviceInformation = await DeviceInformation.FindAllAsync(selector);
![Page 32: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/32.jpg)
Device instantiationawait MainPage.Current.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
var openedDevice = await SerialDevice.FromIdAsync(deviceInformation.Id);
if (openedDevice == null)
{
}
else
{
// Begin watching for disconnect. Begin accessing the device.
}
}
![Page 33: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/33.jpg)
Runtime Checks:
1. Capability declarations in the manifest.
2. Allowed by OS Policy.
3. Exclusivity.
4. Consent and Dynamic Access.
If your app is denied access as a result of any of the above, the function returns a NULL SerialDevice object.
What happens when you call FromIdAsync ?
Device instantiation
![Page 34: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/34.jpg)
SerialDevice is NULL ?if (openedDevice == null)
{
var deviceAccessStatus = DeviceAccessInformation.CreateFromId(deviceInformation.Id).CurrentStatus;
if (deviceAccessStatus == DeviceAccessStatus.DeniedByUser)
{
notificationMessage = "Access to the device was blocked by the user : " + deviceInformation.Id;
}
else if (deviceAccessStatus == DeviceAccessStatus.DeniedBySystem)
{
// (Possible failure with Package.appxmanifest declaration, seen at development time only)
}
else
{
// Most likely the device is opened by another app, but cannot be sure
notificationMessage = "Unknown error, possibly opened by another app : " + deviceInformation.Id;
}
![Page 35: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/35.jpg)
• How it all comes together …
Basic communication
![Page 36: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/36.jpg)
Device Configuration• Baud rate, Parity, Stop Bits etc.
Reading• InputStreams and DataReader
Writing• OutputStreams and DataWriter
Basic communication
Declare capability
Device discovery
Communication
Cleanup
![Page 37: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/37.jpg)
Basic Communication
//
// Configure the device
//
serialDevice.BaudRate = 9600;
serialDevice.Parity = SerialParity.None;
serialDevice.StopBits = SerialStopBitCount.One;
serialDevice.Handshake = SerialHandshake.None;
serialDevice.DataBits = 8;
![Page 38: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/38.jpg)
Basic Communication///
/// Write to the device
///
var dataWriter = new DataWriter(serialDevice.OutputStream);
dataWriter.WriteString(“hello");
var bytesWritten = await dataWriter.StoreAsync();
this.NotifyUser("Write completed - " + bytesWritten.ToString() + " bytes written, NotifyType.StatusMessage);
dataWriter.DetachStream();
![Page 39: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/39.jpg)
Basic Communication///
/// Read from the device
///
var dataReader = new DataReader(serialDevice.InputStream);
uint readBufferLength = 8;
UInt32 bytesRead = await dataReader.LoadAsync(readBufferLength);
if (bytesRead > 0)
{
string temp = dataReader.ReadString(bytesRead);
this.NotifyUser("Read completed - " + bytesRead.ToString() + " bytes were read", NotifyType.StatusMessage);
}
dataReader.DetachStream();
![Page 40: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/40.jpg)
1. When done with device communication, the app must close the SerialDevice.
2. Be aware of language-specific nuances for object close and deletion.
Closing the device
Declare capability
Device discovery
Communication
Cleanup
![Page 41: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/41.jpg)
Closing the device
C++:
delete device;
device = nullptr;
C#:
device.Dispose();
device = null;
JS:
this._device.close();
this._device = null;
![Page 42: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/42.jpg)
1. It must close the SerialDevice as it will be invalidated.
2. It should not send any new I/O.
3. On app resume, app must re-open the device.
App must register for suspension
Suspension/Resume
![Page 43: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/43.jpg)
• How it all comes together …
Arduino: Redux
![Page 44: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/44.jpg)
Additional features
![Page 45: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/45.jpg)
• App can do long running operations using background tasks.
• Supports all existing triggers e.g. System Event trigger, Control Channel trigger, DeviceUse trigger
• Tasks aren’t throttled like other system background tasks (no CPU time quota) but will run with reduced priority to keep foreground apps responsive.
Background tasks
![Page 46: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/46.jpg)
Tracing:• Windows.Devices.SerialCommunic
ation
• Device Broker
Details on MSDN page
Debugging
![Page 47: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/47.jpg)
Related SessionsIntroducing the Windows App Model
Moving to Universal: Porting to Windows 10 from Windows 8.1 XAML or Windows Phone Silverlight
Developing Windows 10 Universal Apps in Visual Studio 2015
Universal App Packaging and Deployment for Windows 10 DevicesWindows 10 App Lifecycle: From Activation & Suspension to Background Execution and Multitasking
Optimizing Universal Apps for Continuum
New Retail Peripherals and NFC/HCE Support in Windows 10
Developing universal audio and video apps for Windows
Building Rich, Contextually Aware Applications Using Sensors
Windows for Makers: Raspberry Pi 2, Arduino and More!
Internet of Things: Overview
Building Windows Apps that Discover, Connect, and Interact with Other Devices and Cloud Services Using AllJoyn
![Page 48: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/48.jpg)
Resources: Typical accessories on Mobile SKU
Accessories that just work with OS
• Windows natively supports these accessory types regardless of who makes the hardware.
• Windows provides built-in OS experiences for many of them
Examples Accessories Namespace
AudioMicrophoneMIDISpeakers
Windows.Media.CaptureWindows.Devices.MidiAudioGraph (new for Windows 10)
FilesRemovable Storage Windows.Storage
Point of Service
Magnetic Stripe Reader
Barcode Scanner
Windows.Devices.PointofService.BarcodeScanner
Windows.Devices.PointofService.MagneticStripeReader
Also productivity oriented accessories like keyboards, mice and network adapters
![Page 49: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/49.jpg)
Resources: Vendor specific accessories on Mobile SKU
API Namespace SDK Sample(s)
HID Windows.Devices.HumanInterfaceDevice
Custom HID Device Access
Serial Windows.Devices.SerialCommunication Custom Serial Device Access
USB Windows.Devices.Usb Custom USB device access
![Page 50: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/50.jpg)
USB Accessories1. Start developing a Universal Windows App on desktop w/ USB
port2. Make sure the UX of you’re app lays out properly on phones3. Once available, get a Dual Role capable Mobile device to test
your app with accessories4. Make sure your vendor specific accessories report the correct
hardware IDs to work with Mobile SKU :
Feedback: Anything missing in our APIs?mailto:[email protected]
Call to Action
![Page 51: Building apps for USB Accessories Develop apps that can connect with hardware from the past and present](https://reader033.vdocuments.net/reader033/viewer/2022061520/56649d825503460f94a67aa2/html5/thumbnails/51.jpg)
© 2015 Microsoft Corporation. All rights reserved.