OnReceive Event

This event occurs when data is received on the serial port.

Syntax

Delphi
OnReceive(Sender: TObject; Count: Cardinal);
BCBuilder
OnReceive(TObject * Sender, Cardinal Count);

Parameters

Sender

Event source.

Count

Number of bytes can be read from serial port.

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;