About PortController
Introduction
Purchasing PortController
Redistributing PortController
License Agreement
Support
Getting Started
How to Use PortController
Using PortController with Visual Basic
Using PortController with Visual C++
Using PortController with Delphi
How to Use Events
Handling Events in Visual Basic
Handling Events in Visual C++
Handling Events in Delphi
PortController Sample Projects
Reading and Writing Binary Data
Handling PortController Errors
Reference
Properties
BaudRate Property
Break Property
BytesUsedRQ Property
BytesUsedTQ Property
Cd Property
Cts Property
DataBits Property
Dsr Property
Dtr Property
DtrDsr Property
EnableReadOnEventChar Property
EventChar Property
Parity Property
PortHandle Property
PortName Property
Ring Property
Rts Property
RtsCts Property
StopBits Property
XonXoff Property
Methods
ClearRQ Method
ClearTQ Method
Close Method
GetErrorStatus Method
Open Method
Read Method
ReadBinary Method
Write Method
WriteBinary Method
SendXoff Method
SendXon Method
Events
BreakSignal Event
CdToggle Event
CtsToggle Event
DataReceived Event
DsrToggle Event
Error Event
EvtCharReceived Event
Ring Event
TQEmpty Event

ReadBinary Method

Reads binary data from the receive queue.

Syntax

Visual Basic

Use the Read() method (see Reading and Writing Binary Data for more information)

Visual C++

(BYTE *)object.ReadBinary(long NumBytesToRead, long Timeout, long &NumBytesRead)

Delphi

Use the Read() method (see Reading and Writing Binary Data for more information)

Part Description
object An object expression that evaluates to a PortController object.
NumBytesToRead A long integer indicating the number of bytes to read from the receive queue.
Timeout A long integer indicating the amount of time in milliseconds to wait before terminating the operation. Setting this parameter to 0 causes the function to wait indefinitely for the operation to complete before returning.
NumBytesRead [out] A long integer containing the number of bytes actually read from the receive queue.

Example

Visual C++

long numBytesRead;
BYTE *readBytes;
readBytes = (BYTE *)m_myPortController.ReadBinary(10, 0, &numBytesRead);  // reads 10 bytes

Remarks

  • A NumBytesToRead value of 0 indicates that all data in the receive queue is to be read.

  • A Timeout value of 0 indicates that the should function wait indefinitely for the operation to complete before returning.

  • If the operation does not complete in the time specified by the Timeout parameter, the function returns NO data. For example, if the NumBytesToRead parameter is 10 and timeout elapses with only 5 bytes having been received, the receive queue is not read and the function returns no data.

  • See Reading and Writing Binary Data for more information on working with binary data.

Returns

The address of the buffer containing the read data.

Errors

  • Attempting to read from the receive queue when the port is closed will cause the PortController to throw a "Port is closed." exception.

  • If an error occurs during the read, a "An error occurred while trying to read data from the receive queue." exception is thrown.

  • Attempting to set Timeout or NumBytesToRead to a negative value will cause PortController to throw an "Invalid argument" exception.

See Also

Open(), WriteBinary(), Reading and Writing Binary Data