Assembly: Quanser.Communications (in Quanser.Communications.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Sub SetSwapBytes ( _ swap As Boolean _ ) |
C# |
---|
public void SetSwapBytes( bool swap ) |
Visual C++ |
---|
public: void SetSwapBytes( bool swap ) |
JavaScript |
---|
function setSwapBytes(swap); |
Parameters
- swap
- Type: System..::.Boolean
If this parameter is true then the Stream object will swap the bytes within primitive data types when sending and receiving those types, or arrays of those types. Otherwise, no byte swapping will occur.
Remarks
This method may be used to cause the bytes within shorts, integers, doubles and other data types to be swapped by the Stream object to account for endian differences between the two endpoints of the connection. The Stream object does not detect the endianness of the peer. Calling this method with the swap flag set to true causes the bytes to be swapped unconditionally.
Byte swapping is only necessary when communicating between processors that use a different endianness. For example, Intel processors are little endian (LSB first) while Motorola processors tend to be big endian (MSB first). By default, no byte swapping takes place. Whether byte swapping is necessary may be determined simply by sending 0x1234 as a short and seeing if it arrives as the same number or 0x3421.
Note that the SetSwapBytes(Boolean) and SetByteOrder(Stream..::.ByteOrder) methods override each other, so byte swapping will be determined by the last method called.
Examples
C# | Copy Code |
---|---|
stream.SetSwapBytes(true); |
Visual Basic | Copy Code |
---|---|
stream.SetSwapBytes(True) |
Visual C++ | Copy Code |
---|---|
stream->SetSwapBytes(true); |
Exceptions
Exception | Condition |
---|---|
Quanser.Communications..::.StreamException | If byte-swapping cannot be configured then an exception is thrown. This situation should never occur unless the underlying stream has been closed. |