I am trying to do a request response pattern to a device using the UWP platform. I can successfully get a write with this code, but the read always returns 0 bytes. I used a cross connect cable to confirm the writes with another serial port. With the UWP sample I can return and read responses, but the code below never reads any data.
https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/CustomSerialDeviceAccess
Below is the method I am using to attempt to send a request and receive a response
async public void FindDevices()
{
string comDeviceSelector = SerialDevice.GetDeviceSelector("COM2");
var UsbDevices = await DeviceInformation.FindAllAsync(comDeviceSelector);
var device = await SerialDevice.FromIdAsync(UsbDevices.First().Id);
device.BaudRate = 115200;
device.DataBits = 8;
device.StopBits = SerialStopBitCount.One;
device.Parity = SerialParity.None;
device.Handshake = SerialHandshake.None;
device.BreakSignalState = false;
device.IsDataTerminalReadyEnabled = false;
device.IsRequestToSendEnabled = false;
device.WriteTimeout = TimeSpan.FromMilliseconds(50);
device.ReadTimeout = TimeSpan.FromSeconds(30);
var writer = new DataWriter(device.OutputStream);
var requestWriteAccess = new byte[] { 0xA5, 0x3F, 0x02, 0x07, 0x00, 0x01, 0xB3, 0xE7, 0x0F, 0x00, 0x10, 0x3E};
writer.WriteBytes(requestWriteAccess);
var bytesWritten = writer.StoreAsync().AsTask();
writer.DetachStream();
writer = null;
uint ReadBufferLength = 1024;
var reader = new DataReader(device.InputStream);
reader.InputStreamOptions = InputStreamOptions.Partial;
var readTask = reader.LoadAsync(ReadBufferLength).AsTask();
var bytesRead = await readTask;
}
The following is in my appxmanifest:
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort"/>
</Device>
</DeviceCapability>