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

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()