I have an interface ISFactory
as follows.
namespace MyApp.ViewModels
{
public interface IStreamFactory
{
Stream CreateSPStream(string sPName);
}
}
On Windows non-universal version the above function was implemented as follows.
public Stream CreateSerialPortStream(string serialPortName)
{
var p = new System.IO.Ports.SerialPort();
p.PortName = serialPortName;
p.BaudRate = 9600;
p.RtsEnable = true;
p.DtrEnable = true;
p.ReadTimeout = 150;
p.Open();
return p.BaseStream;
}
This implementation is no longer available in Windows Universal. What I attempted is shown below.
public Stream CreateSerialPortStream(string serialPortName)
{
var selector = SerialDevice.GetDeviceSelector(serialPortName); //Get the serial port on port '3'
var devices = await DeviceInformation.FindAllAsync(selector);
if (devices.Any()) //if the device is found
{
var deviceInfo = devices.First();
var serialDevice = await SerialDevice.FromIdAsync(deviceInfo.Id);
//Set up serial device according to device specifications:
//This might differ from device to device
serialDevice.BaudRate = 19600;
serialDevice.DataBits = 8;
serialDevice.Parity = SerialParity.None;
}
}
I get the following error.
The await operator can only be used within an async method.`
Can anyone suggest a way around this.