I'm making a Modbus library (again...). This time it is meant to run on Windows 10 IoT Core.
I've encountered an interesting problem. This chunk 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 from within a Universal App works perfectly. Of course if you add following code to Package.appxmanifest:
<Capabilities> <DeviceCapability Name="serialcommunication"> <Device Id="any"> <Function Type="name:serialPort" /> </Device> </DeviceCapability> </Capabilities>
Used from within Universal Class Library (File -> New Project -> ... -> Windows -> Universal -> Class Library (Universal Windows) in VS2015) creates Null Reference Exception from mscorlib.dll, which is same as if you remove DeviceCapability from Universal app's Package.appxmanifest.
I suspect that this behaviour has something to do with Class Library not having manifest file and therefore not having appropriate permissions.
Can I use Windows.Devices.SerialCommunication from within class libraries?
Is Microsoft making me tell the users 'Hey! I made for you a useless library for which you have to implement transport layer by yourself in any of your applications separately.' ?