WANGJAY
WANGJAY

Reputation: 203

UWP link to serial port

I want to create an UWP application to receive information sent by Waspmote board.

in WindowsForms, it's using System.IO.Ports; it can work

but in UWP, it show me this error: enter image description here

how can I solve this problem, and be able to receive the message from serial port

Upvotes: 3

Views: 3099

Answers (1)

Vincent
Vincent

Reputation: 3746

You're trying to use an old API which is not accessible to UWP apps.

Serial communication can be achieved by using the classes from Windows.Devices.SerialCommunication.

The class you'll use is SerialDevice which will allow you to enumerate, open the device and perform I/O operations.

In order to use the API, you will need to add the serial port capability in your application manifest. UWP applications can only access to declared hardware resources.

<DeviceCapability Name="serialcommunication">
  <Device Id="vidpid:045E 0610">
    <Function Type="name:serialPort"/>
  </Device>
</DeviceCapability>

or if you want to access any hardware:

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

You will find a full serial port sample as part of the UWP sample collection.

Upvotes: 5

Related Questions