Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6747101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:24:06+00:00 2026-05-26T12:24:06+00:00

I have a serial device that has a binary output and I capture the

  • 0

I have a serial device that has a binary output and I capture the data using the following.

        private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            int count = sp.BytesToRead;
            byte[] data = new byte[count];
            sp.Read(data, 0, data.Length);
            file.WriteLine(BitConverter.ToString(data));
        }

The data comes through and looks like this…

06-14-F2-A1-64-2D-62-00-1A-31-00-06-14-F3-84-62-59-01-00-1A-31-00-06-14-F3-85-56-52-55-31
1A-31-00-06-14-F4-18-04-2E-62-00-1A-31-00-06-14-F4-E3-27-5B-01-00-1A-31-00-06-14-F4-E4-1C-51-55-31
1A-31-00-06-14-F5-71-4C-59-71-20-1A-31-00-06-14-F5-8E-A5-2E-62-00-1A-31-00-06-14-F5-F4-47-56-55-31-1A-31-00-06-14-F6-10-1A-1A-31-52-24-1A-31-00-06-14-F6-3D-40-19-70-00-1A-31-00-06-14-F6-3E-9C-4C-55-31-1A-33-00-06-14-F6-F6-11-3D-A0-00-17-B0-C8-4E-42-70-AA-00-00-59-51-1E-1A-31-00-06-14-F7-05-4A-2E-62-00-1A-31-00-06-14-F7-83-5C-56-55-31-1A-31-00-06-14-F7-99-04-5A-01-00-1A-31-00-06-14-F7-99-F8-51-55-31-1A-31-00-06-14-F8-7B-EA-2E-62-00-1A-31-00-06-14-F9-00-CE-56-01-00-1A-31-00-06-14-F9-0E-DF-51-55-31-1A-31-00-06-14-F9-F2-8B-2B-62-00-1A-31-00-06-14-FA-15-1F-1D-05-30-1A-31-00-06-14-FA-62-4D-59-01-00-1A-31-00-06-14-FA-63-41-55-55-31-1A-31-00-06-14-FA-6F-6E-1D-67-67-1A-31-00-06-14-FA-EC-50-2E-72-00-1A-31-00-06-14-FB-22-96-38-62-00-1A-31-00-06-14-FB-3B-7A-40-20-43-1A-31-00-06-14-FB-69-2E-2B-62-00-1A-31-00-06-14-FC-62-F1-2D-72-00-1A-31-00-06-14-FC-DF-D1-2E-62-00-1A-31-00-06

The hex isn’t the issue here as I can decode that but a statement I am looking for begins with 1A-31 and then is a set number of bytes long. As you can see the serial stream in this case starts mid flow and so is not a full statement.

How can I look for this marker, discard the beginning and then start processing. Also bear in mind that this will happen multiple times as the readBuffer at some point will truncate the stream and I will need to piece it back together again?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:24:06+00:00Added an answer on May 26, 2026 at 12:24 pm

    You’re almost there. Your problem is that the data you’re streaming comes in chunks, which misalign with where statements begin and end. I’m going to assume that the end of a statement is found by the 1A-31 that identifies the start of the next statement. If this isn’t true, reinterpret this answer accordingly.

    Now, you will not be able to do anything with the very first pieces of data in your example, which contains half a statement. So, let’s start with assuming that the first chunk of data you get indeed starts with 1A-31.

    There are now two options:

    • You can find the entire statement inside the chunk (i.e. you encounter another 1A-31 inside it). In this case, eat it up and do with it whatever you’d want to do with it (I’d add a StatementReceived event and send it there, or something like that). Repeat this exercise until the chunk has been entirely processed.
    • The statement is not entirely contained inside the chunk. Copy the data you already got to a temporary buffer and wait for the next port_DataReceived call.

    If the second option was the case, you know that the data for the next port_DataReceived will not begin with 1A-31 (because the temporary buffer is non-empty). However, you can scan to the end of it (until the next 1A-31), prepend the temporary buffer (stored in the previous port_DataReceived call) to it, and raise StatementReceived and erase the temporary buffer.

    With a similar approach, you can also deal with statements that require more than 2 chunks of data to be sent; each time you do not encounter a 1A-31, append the received data to the temporary buffer, until the statement is complete.

    Finally, if the very first bytes that you read upon startup do not start with 1A-31, you’ll just have to discard those. Can’t do something with half a statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a serial application that I parallelized using OpenMP. I simply added the
We have a device which has a 10 byte serial number which must be
I am receiving data from a device that's sending information over the serial port
I have the following problem: I have a Wintec WBT-202 GPS device which has
I have a tiny shell script that writes to a serial device: #!/usr/bin/ruby require
I have a Windows Service which performs some data collection from a serial device
I can capture data from serial device via pyserial, at this time I can
I have a document with connection information to a device over a serial port.
I have a serial of object defined as: public class Foo { public DateTime
I have to monitor a serial port and process its data. As a test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.