Metro Answers: Can I use the Serial Port?
Metro Answers: Can I use the Serial Port?
Join the DZone community and get the full member experience.Join For Free
Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.
Using a WinRT Metro style application, is it possible to access custom devices that connect using a serial port?
The Short Answer
The short answer is no. With this exception: the device is on USB (with a dongle) with a modern driver exposing IOCTLS device information – this gives Metro applications device access.
The Long Answer
On the desktop (and Windows 7), applications access devices through the I/O manager. The I/O manager does not care which application is accessing a device. The I/O manager only cares which user is accessing a device. If there is device security, this is it.
User Controls Capabilities
Metro applications use the I/O manager, too. However, Metro security is different. Device access is restricted by application. This allows users to grant application capabilities. As a result, the Device Access Broker stands in between devices and apps.
Metro applications run in a secure environment called the Application Container. This puts the user in control to choose what resources an application can use. The Device Access Broker enforces the capability permissions granted by the user.
This is the reason low level APIs cannot be opened to applications. When the user is granting access – granting “all USB access” is something the typical user will not understand and therefore cannot securely provision.
Vendor Controls Access
Hardware vendors also have the ability to restrict access to their device. Scenarios may exist where access to a device is private or dangerous. Metro supports two access models:
- Open Device Access Model
Any application can access the device. For example, a camera, maybe a pedometer.
- Restricted Device Access Model
Restricts which app(s) may access devices, For example, a credit card reader.
The Companion Application section in the Device Metadata instructs what to automatically download when you plug in the device. It also allows to you restrict access to your device based on the consuming Metro application’s GUID.
Types of Devices
There are some broad categories of devices:
MSDN: Manufactures of almost any connected device can create tailored device experiences that leverage the unique capabilities of their device through a Metro style device app. Similarly, system makers can leverage embedded functionality within Metro style device apps. Devices that don’t have a built-in user experience in Windows 8 are known as specialized devices. A range of options for developing specialized devices is available, from using in-box device drivers to providing custom functionality through proprietary device drivers.
Types of APIs
Certain Windows APIs are restricted. For those, there are alternatives. Moreover, there are broad categories of APIs for Metro device access:
- Windows Portable Device (WPD). For example, a phone.
- Windows.Storage. For example, an external drive.
- Windows.Networking. There are 2 types of networked devices – those on the local network and those on the internet. UPnP and Web Services for Discovery are the two protocols supported to make device services discoverable. PnPX extensions instructs windows about the device and what needs to be automatically downloaded for it.
- DeviceIoControl. This requires a custom driver. The devices must be marked as restricted. This is important because restricted is required in order to allow Metro applications to access it. This is not required for desktop applications to access it.
The C++ Requirement
These are are available in C++ only – which allows high performance buffer manipulation and management. This is important to deliver the best experience to your device, your app, and (most of all) the user. This means, if you are writing a C# application, you will need to have a hybrid application.
Sends a control code to a device driver.This action causes the device to perform the corresponding operation.
Documentation: Windows Driver Kit
The Windows Driver Kit (WDK) 8 documentation provides information about driver development for Windows 8 Consumer Preview and earlier versions of Windows.
You might also like this sample: Custom Driver Access (once it is published!)
Special thanks to George Roussos and Nar Ganapoathy. And to their excellent //Build/ session “Building apps that connect to specialized devices”. I recommend it.
Best of luck!
Published at DZone with permission of Jerry Nixon , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.