'KCMLReadPort(iHandle, pData$, iCount)

Reads data from a serial or parallel port on the client previoulsy opened with KCMLOpenPort.

Arguments

INT()iHandle[in] Handle to the port returned from KCMLOpenPort.
DIM()pData$[out] Buffer for the data to be read into.
INT()iCount[in] The number of bytes to be read.

Returns

The number of bytes read. This can be less than the number requested.

Syntax

The following definition is built into KCML. You do not have to include it in your own code.

$DECLARE 'KCMLReadPort(INT(), RETURN DIM(), INT())

Remarks

KCMLReadPort reads data from a port previously opened with KCMLOpenPort. If reading from a serial port a timeout based on the baud rate and number of bytes to be read is used. It is possible that not all the data, or even any at all will be available to be read. Thus the applicartion may need to poll for available data.

Note this function is synchronous and will not return until the timeout is reached or all the data is read. Until the function returns the client will be unresponsive.

Example

	$DECLARE 'KCMLReadPort(INT(),RETURN DIM(),INT())
	$DECLARE 'KCMLOpenPort(STR())
	$DECLARE 'KCMLClosePort(INT())
	DIM Data$256
	DIM PortHandle
	DIM BytesRead
	DIM BytesToRead
	BytesToRead = 10
	REM Open COM2 at 9600 baud, 8 bits per character, no parity, one stop bit and hardware flow control
	PortHandle = 'KCMLOpenPort("COM2:9600,8,N,1,H") 
	REM Attempt to read the data
	BytesRead = 'KCMLReadPort(PortHandle, BYREF Data$, BytesToRead)
	REM The amount of data read may be less than that requested
	REM A robust application should attempt to ensure that the complete data is read
	REM Finally close the port
	'KCMLClosePort(PortHandle)

Further Information

IntroducedKCML 6.20
CompatibilityKClient

See Also

KCMLClosePort, KCMLDebugBackProcess, KCMLGetClientIP_TOS, KCMLOpenPort, KCMLSetClientIP_TOS, KCMLWritePort, KCMLWritePortName

Index of internal $DECLARE functions