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
|