Reads specified number of bytes from serial port.
| Visual Basic .NET | Function Read(ByVal DataBuffer As System.IntPtr, ByVal BytesToRead As UInt32) As UInt32
|
|---|---|
| Visual C# | UInt32 Read(IntPtr DataBuffer, UInt32 BytesToRead);
|
DataBuffer
[out] Pointer to the buffer that receives the data. Use type-casting to convert it to void* or char*.
BytesToRead
[in, optional] Number of bytes to read from serial port
Number of bytes read from serial port.
The method may throw exception. Refer to Handle errors sample for details.
In Visual Basic use function ReadArray.
// using System.Runtime.InteropServices;
private void ftspcControl1_OnReceive(object Sender, uint Count)
{
try
{
IntPtr Ptr = IntPtr.Zero;
byte[] ReadBuffer = new byte[Count];
Ptr = Marshal.AllocHGlobal((int)Count);
ftspcControl1.Read(Ptr, Count);
Marshal.Copy(Ptr, ReadBuffer, 0, (int)Count);
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);
}
}