UWP link to serial port

前端 未结 1 1333
谎友^
谎友^ 2021-01-14 10:04

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

bu

相关标签:
1条回答
  • 2021-01-14 10:23

    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.

    0 讨论(0)
提交回复
热议问题