Read Method
Reads specified number of bytes from serial port.
Syntax
Visual Basic .NET | Function Read(ByVal DataBuffer As System.IntPtr, ByVal BytesToRead As UInt32) As UInt32 |
---|---|
Visual C# | UInt32 Read(IntPtr DataBuffer, UInt32 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. Refer to Handle errors sample for details.
Remarks
In Visual Basic use function ReadArray.
Code Example
// 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); } }