rtiostream_wrapper - Test rtiostream shared library functions in MATLAB - MATLAB (original) (raw)
Test rtiostream
shared library functions in MATLAB
Syntax
Description
[streamID](#d126e42637) = rtiostream_wrapper([sharedLib](#d126e42591), 'open')
opens an rtiostream
communication channel or stream through a shared library.
[[errFlag](#d126e42913),[transmittedDataSize](#d126e42932)] = rtiostream_wrapper([sharedLib](#d126e42591),'send',[streamID](#d126e42637),[data](#d126e42657),[dataSize](#d126e42674))
transmits data from a workspace variable through the open communication channel or stream.
[[errFlag](#d126e42913),[receivedData](#d126e42952),[receivedDataSize](#d126e42971)] = rtiostream_wrapper([sharedLib](#d126e42591),'recv',[streamID](#d126e42637),[dataSize](#d126e42674))
receives workspace variable data from the open communication channel or stream.
[streamID](#d126e42637) = rtiostream_wrapper(___,[Name,Value](#namevaluepairarguments))
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](#d126e42913) = rtiostream_wrapper([sharedLib](#d126e42591),'close',[streamID](#d126e42637))
closes the rtiostream
communication channel or stream.
rtiostream_wrapper([sharedLib](#d126e42591),'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', portnumber);
Opens rtiostream
StationB
as a TCP/IP client:
stationB = rtiostream_wrapper('libmwrtiostreamtcpip.dll','open',... '-client','1',... '-blocking', '0',... '-port', portnumber,... '-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
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 Arguments
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN
, where Name
is the argument name and Value
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose Name
in quotes.
Example: '-hostname','localhost'
TCP/IP Communication
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 macrodefine VXWORKS
exists. In this case, the default is 1.
Waiting period of call that receives data:
X
, a positive integer — Wait forX
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
COM port for serial communication.
Bit rate for serial communication port.
Output Arguments
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 thandataSize, the number of bytes specified for transmission.
Array that contains received data.
Number of bytes received from communication stream. Can be less thandataSize, the number of bytes specified for transmission.
Version History
Introduced in R2008b