Read Method

Reads specified number of bytes from serial port.

Syntax

Delphi
function Read(DataBuffer: Pointer; BytesToRead: Cardinal): Cardinal; 
BCBuilder
Cardinal Read(void * DataBuffer, Cardinal BytesToRead);
 

Parameters

DataBuffer

[out] Pointer to the buffer that receives the data. Use type-casting to convert it to void* or char*.

BytesToRead

[in] Number of bytes to read from serial port

Return

Number of bytes read from serial port.

Errors

The method may throw exception. Refer to Handle errors sample for details.

Remarks

In Visual Basic use function ReadArray.

Code Example

procedure TForm1.FTSPCControl1Receive(Sender: TObject; Count: Cardinal);
var
	ReadBuffer: array of byte;
	ReadCount: DWORD;
	i: integer;
begin
	try
		SetLength(ReadBuffer, Count);
		ReadCount := FTSPCControl1.Read(@ReadBuffer[0], Count);
		if ReadCount > 0 then
		begin
			for i := 0 to ReadCount - 1 do
			begin
				Memo_Terminal.Text := Memo_Terminal.Text +
					char(ReadBuffer[i]);
			end;
		end;
	except
		on e:FTSPCException do
		begin
			application.MessageBox(PChar('Error: ' + 
				inttostr(e.ErrorCode) + ' - ' +
				e.ErrorSource), 'Error!', MB_OK + 
				MB_ICONERROR);
		end;
	end;
end;

See Also

ReadArray