I am making a Modbus library (again ...). This time it is designed to work in Windows 10 IoT Core.
I had an interesting problem. This piece of code:
string aqs = SerialDevice.GetDeviceSelector();
var dis = await DeviceInformation.FindAllAsync(aqs);
var port = await SerialDevice.FromIdAsync(dis[0].Id);
if (port != null) {
port.BaudRate = 9600;
port.DataBits = 8;
port.StopBits = SerialStopBitCount.One;
port.Parity = SerialParity.None;
port.Handshake = SerialHandshake.None;
port.ReadTimeout = TimeSpan.FromMilliseconds(1000);
port.WriteTimeout = TimeSpan.FromMilliseconds(1000);
}
Used in a universal application. Of course, if you add the following code to Package.appxmanifest:
<Capabilities>
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
</Capabilities>
Used in the universal class library (File → New Project → ... → Windows → Universal → Class Library (Universal Windows) in VS2015) creates a Null Reference Exception from mscorlib.dll, which is the same as if you removed DeviceCapability from the universal application Package.appxmanifest.
I suspect this behavior is because the class library does not have a manifest file and therefore does not have the appropriate permissions.
Windows.Devices.SerialCommunication ?
Microsoft "! , ".