none
Reading a serial device from an UWP app. RRS feed

  • Question

  • (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 https://filipemadureira.com




    • Edited by Fieel Monday, December 16, 2019 12:17 PM
    • Moved by CoolDadTx Thursday, December 19, 2019 2:57 PM UWP forum moved, moving this to off topic
    Monday, December 16, 2019 12:15 PM

All replies

  • Hi Fieel,

    Since this thread is related to UWP, so I suggest that you can ask this question in  Microsoft Q&A.

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Tuesday, December 17, 2019 1:19 AM
  • If you want to write/read to virtual COM port, you can use System.IO.Ports.SerialPort class.

    It can Open virtual COM ports, and write / read data to the virtual COM port.

     

    But, there is a limitation. SerialPort class on UWP can't list ports using GetPortNames method. If the method was used, then PlatformNotSupportedException would be occurred.


    Wednesday, December 18, 2019 2:40 PM
  • I'm having an hard time navigating the forums, let alone finding the correct section.. thanks. I'll repost there.


    noob software dev https://filipemadureira.com

    Thursday, December 19, 2019 1:37 PM