Main Content

rtiostream_wrapper

Test rtiostream shared library functions in MATLAB

Description

streamID = rtiostream_wrapper(sharedLib, 'open') opens an rtiostream communication channel or stream through a shared library.

[errFlag,transmittedDataSize] = rtiostream_wrapper(sharedLib,'send',streamID,data,dataSize)transmits data from a workspace variable through the open communication channel or stream.

[errFlag,receivedData,receivedDataSize] = rtiostream_wrapper(sharedLib,'recv',streamID,dataSize) receives workspace variable data from the open communication channel or stream.

streamID = rtiostream_wrapper(___,Name,Value) specifies additional options using one or more name-value pair arguments. These arguments are implementation-dependent, that is, they are specific to the shared library that you use.

errFlag = rtiostream_wrapper(sharedLib,'close',streamID) closes the rtiostream communication channel or stream.

example

rtiostream_wrapper(sharedLib,'unloadlibrary') unloads the shared library, clearing persistent data.

Examples

Open Communication Channels

These examples use the supplied TCP/IP and serial communication drivers to open communication channels.

Open rtiostream stationA as a TCP/IP server:

stationA = rtiostream_wrapper('libmwrtiostreamtcpip.dll','open',...
                              '-client', '0',...
                              '-blocking', '0',...
                              '-port', port_number);

Opens rtiostream StationB as a TCP/IP client:

stationB = rtiostream_wrapper('libmwrtiostreamtcpip.dll','open',...
                              '-client','1',...
                              '-blocking', '0',...
                              '-port', port_number,...
                              '-hostname','localhost');

If you use the supplied development computer driver for serial communications (as an alternative to the drivers for TCP/IP), specify the bit rate when you open a channel with a specific port. For example, open channel stationA with port COM1 and bit rate of 9600:

stationA = rtiostream_wrapper('libmwrtiostreamserial.dll','open',...
                              '-port','COM1',...
                              '-baud','9600');

Input Arguments

collapse all

Shared library that implements required rtIOStream functions, rtIOStreamOpen, rtIOStreamSend, rtIOStreamRecv, and rtIOStreamClose. Must be on system path. Specify one of these values:

  • libTCPIP — For TCP/IP communication. Value depends on your operating system, for example, 'libmwrtiostreamtcpip.dll'

  • libSerial — For serial communication, for example, 'libmwrtiostreamserial.dll'.

Handle to rtiostream communication stream.

Array that contains data for transmission.

Size of workspace variable data to transmit or receive, in bytes.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: '-hostname','localhost'
TCP/IP Communication

collapse all

Open rtiostream as TCP/IP server or client:

  • 0 — TCP/IP server

  • 1 — TCP/IP client

Port for TCP/IP communication.

Identifier for your development computer, for example, 'localhost'.

Call behavior when receiving data:

  • 0 — Polling mode. If data is available, call returns with data. If data is not available, call returns without waiting.

  • 1 — Blocking mode. If data is available, call returns with data. If data is not available, call waits for data. Use recv_timeout_secs to specify the waiting period.

Default is 0 unless the preprocessor macro define VXWORKS exists. In this case, the default is 1.

Waiting period of call that receives data:

  • X, a positive integer — Wait for X seconds.

  • 0 — No waiting period.

  • -1 — Wait indefinitely.

  • -2 — Wait for default period.

  • -3 — Wait 10 ms.

Default for client connections is to wait 1 second. Default for server connections is to wait indefinitely.

Serial Communication

collapse all

COM port for serial communication.

Bit rate for serial communication port.

Output Arguments

collapse all

If the function opens the communications stream, it returns a handle to the stream. Otherwise, it returns -1.

If the function runs without errors, it returns zero. Otherwise, it returns -1.

Size of data transmitted through communication stream. Can be less than dataSize, the number of bytes specified for transmission.

Array that contains received data.

Number of bytes received from communication stream. Can be less than dataSize, the number of bytes specified for transmission.

Introduced in R2008b