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 7640435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:40:13+00:00 2026-05-31T08:40:13+00:00

Assume we have a sequence of bytes with header of ‘807F’ which is input

  • 0

Assume we have a sequence of bytes with header of ‘807F’ which is input to PC through RS232. for example “… 80 7F 4B 97 80 7F 21 3A 80 7F … ” in which “21 3A” is our data in bold package and 21 is MSB and 3A is LSB. how can we extract data from the sequence in DELPHI?

  • 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-31T08:40:15+00:00Added an answer on May 31, 2026 at 8:40 am

    How your data is stored is a bit unclear, but assuming it is stored in a TBytes array, here is some code to unpack the data:

    procedure ExtractWordFromRS232Data( a : TBytes);
    var
      i: integer;
      myWord: word;
    begin
      // a is a TBytes buffer from reading the RS232 port
      i := 0;
      while (i < Length(a)-3) do 
      begin
        if (a[i] = $80) and (a[i+1] = $7F) then 
        begin
          myWord := (a[i+2] shl 8) + a[i+3];
          // Do something with myWord
          Inc(i,4);
        end
        else
          Inc(i);
      end;
    end;
    

    It will search for first excistance of the header $80 $7F and unpack the following two bytes into a word. Do what you want with the word. The search then continues until the end of the input data array.

    Update:
    It’s still unclear what you really want, but here is some code where data is coming to the procedure via an event.

    var
      gData : array[1..4] of byte;
      gIX : integer;
    
    gIx := 1; // initialized at start
    
    procedure InterpretIndataEvent( b : byte);
    var
      i : integer;
      myWord : word;
    begin
      gData[gIx] := b;
      if (gIx = 4) then
      begin
        if (gData[1] = $80) and (gData[2] = $7f) then
        begin
          myWord := (gData[3] shl 8) + gData[4];
          // do something with myWord
          gIx := 1;
        end
        else
        begin
          for i := 1 to 3 do gData[i] := gData[i+1];
        end;
      end
      else
        Inc(gIx);
    end;
    

    Update 2:

    By the look of the comments, it seems as though the data is coming as ascii characters.

    Then the decoding procedure will look something like this (including a small test) :

    uses
      System.SysUtils;
    
    var
      gData : string[8] = '12345678'; // Old fixed size ansistring type
      gIX : integer = 1;
    
    procedure InterpretIndataEvent( a : AnsiChar);
    var
      i : integer;
      myWord : word;
    begin
      gData[gIx] := a;
      if (gIx = 8) then
      begin
        if (Copy(gData,1,4) = '807F') then
        begin
          myWord := StrToInt('$'+Copy(gData,5,4));
          // do something with myWord
          WriteLn(IntToHex(myWord,4));
          gIx := 1;
        end
        else
        begin
          for i := 1 to 7 do gData[i] := gData[i+1];
          // During startup or if a character is missed we end up here.
          // These events can be logged from here.
        end;
      end
      else
        Inc(gIx);
    end;
    
    const
      testBuf : string[8] = '807F213A';
    var
      i : integer;
    
    begin
      for i := 1 to 8 do
        InterpretIndataEvent(testBuf[i]);
      ReadLn;
    
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have a set of numbers like 1,2,3,4,5,6,7 input as a single String
By default Rails allows users of our application to input non-utf8 data, such as:
I have a standardized sequence of code which I used to display topic information
Let's assume I have a series of functions that work on a sequence, and
Let's assume, I have some sequence, e.g. Fibonacci numbers, defined as a template: template
Let's assume that on a hard drive I have some very large data file
Assume I have two tables, Student Test Id Name TestId Type StudentId -- ----
Assume I have an enumerable object enum and now I want to get the
Assume I have the following ; def test(): while 1: a = b time.sleep(60)
Assume I have an image uploaded to a store on Shopify called 'logo.png'. In

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.