ReadArray Method

Reads specified number of bytes from serial port to array.

Syntax

Delphi
function ReadArray(var DataBuffer: array of byte; BytesToRead: Cardinal): Cardinal; 
BCBuilder
Cardinal ReadArray (Byte * DataBuffer, const int DataBuffer_Size, Cardinal BytesToRead); 

Parameters

DataBuffer

[out] Array of received bytes

BytesToRead

[in, optional] 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.

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.ReadArray(ReadBuffer);
		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;