About PortController
Introduction
Purchasing PortController
Redistributing PortController
License Agreement
Support
Getting Started
How to Use PortController
PortController Sample Projects
Handling PortController Errors
Reference
Properties
AvailableSystemPorts
BaudRate Property
Break Property
BytesUsedRQ Property
BytesUsedTQ Property
Cd Property
Cts Property
DataBits Property
Dsr Property
Dtr Property
DtrDsr Property
EnableReadOnEventChar Property
EventChar Property
ForceBeginInvokeEventFiring Property
IsOpen Property
IsFileTransferInProgress Property
Parity Property
PortHandle Property
PortName Property
ReceiveBufferSize Property
Ring Property
Rts Property
RtsCts Property
StopBits Property
SystemPorts Property
TraceOutput Property
TransmitBufferSize
XoffByte Property
XonByte Property
XonXoff Property
Methods
CancelFileTransfer Method
ClearRQ Method
ClearTQ Method
Close Method
GetErrorStatus Method
Open Method
Read Method
ReadBinary Method
ReceiveFileXModem Method
ReceiveFileXModemCRC Method
ReceiveFileYModem Method
ReceiveFileZModem Method
SendFileXModem Method
SendFileXModem1k Method
SendFileYModem Method
SendFileZModem Method
SimulateReceivedXoff Method
SimulateReceivedXon Method
Write Method
WriteBinary Method
Events
OnBreakSignal Event
OnCdToggle Event
OnCtsToggle Event
OnDataReceived Event
OnDsrToggle Event
OnError Event
OnEventCharReceived Event
OnFileTransferComplete Event
OnFileTransferStatusUpdate Event
OnRing Event
OnTQEmpty Event

WriteBinary Method

Writes binary data to the output queue.

Syntax

[Visual Basic]
object.WriteBinary(WriteBuffer [, NumBytesToWrite, Timeout])

[C#]
object.WriteBinary(WriteBuffer [, NumBytesToWrite, Timeout])

[C++]
object->WriteBinary(WriteBuffer [, NumBytesToWrite, Timeout])

Parameters

object

An object expression that evaluates to a PortController object.

WriteBuffer

A Byte Array containing the data to be written to the output queue.

[optional] NumBytesToWrite

An Int32 indicating the number of bytes to be written to the output queue.

[optional] Timeout

An Int32 indicating the amount of time in milliseconds to wait before terminating the operation. Omitting this parameter (or setting it 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.

Return Value

An Int32 indicating the number of bytes written to the output queue. If Timeout is 0 or omitted, the return value will be 0 if either no data was written, or no data has yet been written.

Remarks

  • The NumBytesToWrite and Timeout parameters are optional. When the NumBytesToWrite parameter is omitted (or set to 0) the entire specified string is written to the output queue. When the Timeout parameter is omitted (or set to 0), the function does 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.

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 the PortController to throw an "Invalid argument" exception.
  • If there are greater than 10000 write operations queued for processing (occurs when Timeout is omitted or 0), 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.

Example

[Visual Basic]
Dim BinaryWriteBuffer() As Byte = {&H1, &H0, &H3}
myPortController.WriteBinary(BinaryWriteBuffer)  'writes all bytes

[C#]
Byte[] BinaryWriteBuffer = {0x01, 0x00, 0x03};
myPortController.WriteBinary(BinaryWriteBuffer); // writes all bytes

[C++]
Byte BinaryWriteBuffer __gc[] = {0x01, 0x00, 0x03};
myPortController->WriteBinary(BinaryWriteBuffer); // writes all bytes

See Also

Open method | ReadBinary method | Write method