Assembly: Quanser.Communications (in Quanser.Communications.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Function Send ( _ buffer As Long() _ ) As Integer |
C# |
---|
public int Send( long[] buffer ) |
Visual C++ |
---|
public: int Send( array<long long>^ buffer ) |
JavaScript |
---|
function send(buffer); |
Parameters
- buffer
- Type: array<
System..::.Int64
>[]()[]
The buffer containing the values to write. The length of this buffer determines the number of elements this method attempts to send. The number of elements written may be less than the number of elements in the buffer, so be sure to check the return value to see how many elements were actually written.
Return Value
The number of 64-bit integers written, which may be less than the number of elements in the buffer for non-blocking streams. If no 64-bit integers could be written to the stream buffer and the method would block then -ErrorCode.WouldBlock is returned for non-blocking streams. If an error occurs then a StreamException is thrown.Remarks
This method writes data to the stream send buffer. It attempts to store buffer.Length 64-bit integers in the internal stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed using Flush()()() or there is no more room available in the stream buffer. If an error occurs, then it throws a StreamException. If the connection is closed it is considered an error condition.
If the stream has been configured to swap bytes using the SetSwapBytes(Boolean) method then this function will swap the order of the bytes within each 64-bit integer when they are sent.
If Listen or Connect was called with the non-blocking flag set to false, then this method may block attempting to flush the stream buffer. All the data will be consumed and the total number of 64-bit integers sent is returned. Some of the data may remain in the stream buffer and not be sent until the next time Flush()()() is called or there is no more room available in the stream buffer. If an error occurs then the a StreamException is thrown and the stream should be closed.
If Listen or Connect was called with the non-blocking flag set to true, then this method does not block. It returns the number of 64-bit integers sent successfully, which will be between 1 and buffer.Length (unless the buffer has zero length). If no 64-bit integers could be sent without blocking, then -ErrorCode.WouldBlock is returned. In this case, the Poll(Timeout, Int32) method may be used with the Send flag to determine when space in the buffer becomes available. If an error occurs then a StreamException is thrown and the stream should be closed.
This method does not support two threads calling Send or Flush()()() at the same time. However, Receive may be called by another thread at the same time as Send.
The BSD socket API has no equivalent to this method.
Unlike the SendArray(array<Int64>[]()[]) method, this method does not require that the internal stream send buffer be as large as the array of 64-bit integers to be sent. Hence, it allows smaller stream buffers to be used. The size of the stream send buffer is set when the stream is created using the Connect or Accept method.
Examples
C# | Copy Code |
---|---|
long [] buffer = { 9223372036854775807, -9223372036854775807, 31, 41, 59 }; int numElementsWritten; numElementsWritten = stream.Send(buffer); if (numElementsWritten > 0) { /* ... generate next data to send ... */ } |
Visual Basic | Copy Code |
---|---|
Dim buffer() As Long = {9223372036854775807, -9223372036854775807, 31, 41, 59} Dim numElementsWritten As Integer numElementsWritten = stream.Send(buffer) If numElementsWritten > 0 Then ' ... generate next data to send ... End If |
Visual C++ | Copy Code |
---|---|
array<long long>^ buffer = { 9223372036854775807LL, -9223372036854775807LL, 31, 41, 59 }; int numElementsWritten; numElementsWritten = stream->Send(buffer); if (numElementsWritten > 0) { /* ... generate next data to send ... */ } |
Exceptions
Exception | Condition |
---|---|
Quanser.Communications..::.StreamException | If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly. |