How to open the serialDevice port in binary mode on UWP ?

Rolandas 0 Reputation points
2025-11-26T07:51:20.91+00:00

C# I used:

using Windows.Devices.SerialCommunication;

byte[] raw = new byte[] { 0x3f, 0x5f, 0x20, 0x21, 0x0A };

IBuffer buf = raw.AsBuffer();

 await serialDev.OutputStream.WriteAsync(buf);

I'm looking at the USB traffic with Wireshark and I find { 0x3f, 0x20, 0x20, 0x21, 0x0A }.

Someone changed the symbol '_' to ' '. I guess the serialDevice is working in terminal mode. How do serialDevice set to binary mode ?

Windows development | WinUI
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Le (WICLOUD CORPORATION) 6,670 Reputation points Microsoft External Staff Moderator
    2025-11-26T11:08:14.1+00:00

    Hello @Rolandas ,

    There is no binary mode setting in UWP. The SerialDevice API always transmits raw bytes exactly as provided in your buffer.

    So we can narrow down the issue to either the virtual COM driver or the device/firmware itself.

    You can try the following steps to diagnose the problem:

    • Check the virtual COM driver's settings and version. Trial builds sometimes alter data; if applicable, switch to a licensed build or try another driver.
    • Confirm the device isn't in ASCII/terminal mode and that no firmware option maps characters or does line-ending translation.
    • Disable any emulation features in the virtual port tool (CR/LF conversion, character filtering, transformers).
    • As a sanity check, loop the port back and read exactly what you wrote. If the bytes change on loopback, it's the driver; if they only change when talking to the device, it's the device/firmware.
    1 person found this answer helpful.

  2. Q&A Assist
    2025-11-26T07:51:32.2866667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To open a SerialDevice port in binary mode on UWP, you typically need to ensure that the data you are sending does not get altered by any character translation settings that might be applied by the serial port configuration. In UWP, the SerialDevice class itself does not have a specific setting for binary mode like some other platforms do. Instead, the behavior is often determined by the settings of the serial port and how the data is written to it.

    When you write data using the OutputStream, it should send the raw bytes as they are. If you are observing that certain bytes are being changed (like the underscore _ being converted to a space), this could be due to the configuration of the receiving end or the serial port settings.

    Here are a few things to check:

    1. Ensure No Character Translation: Make sure that the device you are communicating with is configured to interpret the data as binary and not as text. Some devices may have settings that interpret incoming data as ASCII or other character sets.
    2. Check Serial Device Settings: Verify the settings of the SerialDevice instance, such as baud rate, parity, data bits, and stop bits, to ensure they match the expected configuration of the device you are communicating with.
    3. Use Raw Byte Arrays: When writing to the OutputStream, continue using byte arrays (as you are doing) to ensure you are sending raw data. If the receiving device is set up correctly, it should interpret the bytes as intended.

    If you continue to experience issues, you might want to look into the documentation for the specific device you are communicating with to see if there are any additional settings or modes that need to be configured to prevent data alteration during transmission.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.