ReadArray Method

Reads specified number of bytes from serial port to array.

Syntax

Visual Basic .NET
Function ReadArray(ByRef DataBuffer As array of Byte, ByVal BytesToRead As UInt32) As UInt32 
Visual C#
UInt32 ReadArray(ref byte[] DataBuffer, UInt32 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

private void ftspcControl1_OnReceive(object Sender, uint Count)
{
	try
	{
		uint ReadCount = 0;
		byte[] ReadBuffer = new byte[Count];

		ReadCount = ftspcControl1.ReadArray(ref ReadBuffer);
		if (ReadCount > 0)
		{
			this.TextBox_Data.Text +=
				System.Text.Encoding.ASCII.GetString(
					ReadBuffer
				);
		}
	}
	catch (FTSPCException E)
	{
		MessageBox.Show("Error " + E.ErrorCode.ToString() + "\r\n" + 
			E.ErrorSource, "Error", MessageBoxButtons.OK,
			MessageBoxIcon.Error);
	}
}