WriteBinary Method
Writes binary data to the output queue.
Syntax
Syntax
Visual Basic
Use the Write() method (see Reading and Writing Binary Data for more information)
Visual C++
object.WriteBinary(long pWriteBuffer, long NumBytesToWrite, long Timeout)
Delphi
Use the Write() method (see Reading and Writing Binary Data for more information)
| Part
| Description |
| object |
An object expression that evaluates to a PortController object. |
| pWriteBuffer |
The address of the buffer to be written (see Remarks for explanation).
|
| NumBytesToWrite |
A long integer indicating the number of bytes to be written to the output 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 perform a write
and return immediately. Setting this parameter to a negative value causes the function to wait until the
write operation completes before returning.
|
Example
Visual C++
BYTE myBinaryData[3] = {0x01, 0x00, 0x03};
m_myPortController.WriteBinary((long)&myBinaryData, 3, 0); // writes 3 bytes
Remarks
The pWriteBuffer value is simply the address of the buffer that holds the data to be written. It is not a pointer type because of Visual Studio and COM limitations. Please see Reading and Writing Binary Data for details.
A Timeout value of 0 indicates that the function should not wait for the operation to complete before returning.
If Timeout is a negative value, this function will block until the write operation
completes. This will likely lock up the application and its UI if the device receiving the data has indicated
it is not ready to receive data and handshaking is enabled.
See Reading and Writing Binary Data for more information on working with binary data.
Returns
An integer indicating the number of bytes written to the output queue. If Timeout is 0, the return value
will be 0 if either no data was written, or no data has yet been written.
Errors
Attempting to write to the output queue when the port is closed will cause
the PortController to throw a "Port is closed." exception.
If an error occurs during the write, a
"An error occurred while trying to place data in output queue." exception is thrown.
Attempting to set NumBytesToWrite to a negative value
will cause PortController to throw an "Invalid argument" exception.
If there are greater than 10000 write operations queued for processing, a
"Maximum outstanding write operations limit has been reached" exception is thrown and
the write operation is ignored. This error will never occur when requiring a write operation to
complete before control is returned by specifying a non-zero value for Timeout.
See Also
Open(), ReadBinary()
|