Reading a serial device from an UWP app.

  • Thread starter Thread starter Fieel
  • Start date Start date
F

Fieel

Guest
(Mods please move this thread to "Developing Universal Windows Apps" section! I just chose a random one)

Hello,

how to properly read from a serial device from an UWP app? I'm trying to read data from an industrial scale; have tried every single possible solution i found on google and still have no idea what i'm doing wrong.

Can someone point me to the right direction? How am i supposed to communicate with a serial device? I have to send commands and read the received reply.

I tried using

Windows.Devices.SerialCommunication: I can find select and config my device but i can't communicate with it as i would like to. I need to send specific string commands and listen for replies, the replies might be ACK/NACK strings or a formatted string with the data i need. I can only read and write using writers but it's not what i need! I just want to send a string and read the response, simple as that! My tentative:

string selector = SerialDevice.GetDeviceSelector("COM2");
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector);
if (devices.Any())
{
// Setup
DeviceInformation deviceInfo = devices[0];
SerialDevice serialDevice = await SerialDevice.FromIdAsync(deviceInfo.Id);
serialDevice.BaudRate = 9600;
serialDevice.DataBits = 8;
serialDevice.StopBits = SerialStopBitCount.One;
serialDevice.Parity = SerialParity.None;


// Write with DataWrite
// Read with DataReader
}


The flow i'm looking for is more of "i send you this and then wait and read for the answer"


thanks in advance



noob software dev Filipe Madureira / Developer - Ticino, Switzerland

Continue reading...
 
Back
Top