Read Method

Reads specified number of bytes from serial port.

Syntax

Visual Basic
- 
Visual C++ (MFC)
long Read(long DataBuffer, long BytesToRead);
Visual C++ (#import)
LONG Read(LONG DataBuffer, LONG 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. Use GetLastError method to get the error code.

Remarks

In Visual Basic use function ReadArray.

Code Example

void CSPCDemoDlg::OnReceiveFtspccontrol1(unsigned long Count)
{
	CHAR *Buffer = new CHAR[Count];
	LONG ReadCnt;

	try
	{
		ReadCnt = m_SPCControl1.Read((LONG)Buffer, Count);
	}
	catch (COleDispatchException* E)
	{
		MessageBox(E->m_strDescription, mbCaption, 
			MB_OK | MB_ICONERROR);
	}

	for (int i = 0; i < ReadCnt; i++)
	{
		PCHAR P = (PCHAR)Buffer + i;

		// Todo: add your code
	}
}

See Also

ReadArray