Reading binary data from serial port using Dejan TComport Delphi component

Posted by johnma on Stack Overflow See other posts from Stack Overflow or by johnma
Published on 2010-03-16T21:17:01Z Indexed on 2010/03/16 21:21 UTC
Read the original article Hit count: 577

Filed under:
|

Apologies for this question but I am a bit of a noob with Delphi. I am using Dejan TComport component to get data from a serial port. A box of equipment connected to the port sends about 100 bytes of binary data to the serial port. What I want to do is extract the bytes as numerical values into an array so that I can perform calculations on them.

TComport has a method Read(buffer,Count) which reads DATA from input buffer.

function Read(var Buffer; Count: Integer): Integer;

The help says the Buffer variable must be large enough to hold Count bytes but does not provide any example of how to use this function. I can see that the Count variable holds the number of bytes received but I can't find a way to access the bytes in Buffer.

TComport also has a methord Readstr which reads data from input buffer into a STRING variable.

function ReadStr(var Str: String; Count: Integer): Integer;

Again the Count variable shows the number of bytes received and I can use Memo1.Text:=str to display some information but obviously Memo1 has problems displaying the control characters. I have tried various ways to try and extract the byte data from Str but so far without success.

I am sure it must be easy. Here's hoping.

© Stack Overflow or respective owner

Related posts about delphi

Related posts about Windows