Write Method

Writes specified number of bytes to serial port.

Syntax

Delphi
function Write(DataBuffer: Pointer; BytesToWrite: Cardinal): Cardinal; 
BCBuilder
Cardinal Write(void * DataBuffer, Cardinal BytesToWrite);
 

Parameters

DataBuffer

[in] Buffer of characters to be written. Use type-casting to convert it from void* or char*.

BytesToWrite

[in] Number of bytes to write to serial port.

Return

Number of bytes written to serial port. It can write fewer bytes than requested; the return value must be noted, and the reminder of the operation should be retried when possible.

Errors

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

Remarks

In Visual Basic use WriteArray.

Code Example

const
	DataToWrite = 'String data';
begin
	try
		FTSPCControl1.Write(PChar(DataToWrite), length(DataToWrite));
	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

WriteArray