locked
Sending/Reeiving binary serial binary data RRS feed

  • Question

  • I am using RPi 3b+ and want to send raw binary data (NOT encoded in any way) via a serial channel.

    I can successfully  send and receive ascii string data without a problem (using DataWriter).  But for the life of me, I cannot figure out how to send just plain raw, unencoded hex values.  Looked at BinaryWriter but it wantss to encode everything.  Gad.

    Example  0x02 0x00 0x05 0x38 0x82 0x03.  Just a raw binary array.

    Using Windows iot, c#, xaml, Visual Studio.

    Any help would be greatly appreciated.

    Regards to all  - Bob Scott

    Monday, April 15, 2019 7:08 PM

Answers

  • Once again Rita, thank you very much!!  Now why didn't I see it??

    Ah well - works like a champ!

    Regards as always

    Bob

    • Marked as answer by CVIBob Tuesday, April 16, 2019 5:17 PM
    Tuesday, April 16, 2019 5:16 PM

All replies

  • Hello CVIBob,

    You can use DataWriter.WriteBytes() and ReadBytes(). Modify official serial uart sample, use dataWriteObject.WriteBytes instead of dataWriteObject.WriteString.

    // Write
    
                    dataWriteObject.WriteBytes(new Byte[] {0x02, 0x00, 0x05, 0x38, 0x82, 0x03});
                    // Launch an async task to complete the write operation
                    storeAsyncTask = dataWriteObject.StoreAsync().AsTask();
    
                    UInt32 bytesWritten = await storeAsyncTask;
    
    
    // Read
    
                    loadAsyncTask = dataReaderObject.LoadAsync(ReadBufferLength).AsTask(childCancellationTokenSource.Token);
    
                    // Launch the task and wait
                    UInt32 bytesRead = await loadAsyncTask;
                    if (bytesRead > 0)
                    {
                        var readData = new Byte[bytesRead];
                        dataReaderObject.ReadBytes(readData);
                    }

    Best regards,

    Rita


    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, April 16, 2019 1:04 AM
  • Once again Rita, thank you very much!!  Now why didn't I see it??

    Ah well - works like a champ!

    Regards as always

    Bob

    • Marked as answer by CVIBob Tuesday, April 16, 2019 5:17 PM
    Tuesday, April 16, 2019 5:16 PM