rtIOStreamSend - Send data through communication channel - MATLAB (original) (raw)

Send data through communication channel

Syntax

Description

[errFlag](#d126e42364) = rtIOStreamSend([streamID](#d126e42303), [src](#d126e42323), [size](#d126e42340), [sizeSent](#d126e42389)) sends data through a communication stream.

The API for rtIOStream functions is independent of the physical layer across which you send the data, for example, RS232, Ethernet, or Controller Area Network (CAN). The choice of physical layer affects the achievable data rates for communication between your development computer and target processor.

For a processor-in-the-loop (PIL) application, there is no minimum data rate requirement. The higher the data rate is, the faster the simulation runs.

A communications device driver can require additional hardware-specific or channel-specific configuration parameters. For example:

When you implement the rtIOStream driver functions, provide this configuration data, for example, by hard-coding the data or by supplying arguments to rtIOStreamOpen.

example

Examples

Send and Receive Data from Processor

This code from [rtiostreamtest.c](https://mdsite.deno.dev/matlab:edit%28fullfile%28matlabroot,'/toolbox/coder/rtiostream/src/rtiostreamtest/rtiostreamtest.c'%29%29) shows how to send and receive data from a target processor.

static void blockingIO(int send, unsigned long numMemUnits) { size_t sizeToTransfer = (size_t) numMemUnits; size_t sizeTransferred; IOUnit_T * ioPtr = (IOUnit_T *) &buff[0]; int status;

if (numMemUnits > BUFFER_SIZE)
{
    AckCode = stat_notEnoughSpace;
    AckArg0 = BUFFER_SIZE;
    return;
}

#ifdef HOST_WORD_ADDRESSABLE_TESTING
/* map to bytes */ sizeToTransfer *= MEM_UNIT_BYTES; #endif

while (sizeToTransfer > 0) { sizeTransferred = 0; /* Do the low level call */ status = send ? rtIOStreamSend(streamID, ioPtr, sizeToTransfer, &sizeTransferred) : rtIOStreamRecv(streamID, ioPtr, sizeToTransfer, &sizeTransferred);

  if (status != RTIOSTREAM_NO_ERROR) {
     if (AckCode == stat_OK) {
        AckCode = stat_RTIOSTREAM_ERROR;
        AckArg0 = data_counter;
     }
     return;
  }
  else {
     sizeToTransfer -= sizeTransferred;
     ioPtr += sizeTransferred;
  }

} }

Input Arguments

collapse all

Handle to the stream returned by a previous call tortIOStreamOpen.

Pointer to the start of the buffer that contains a data array for transmission.

Size of data to transmit from the source buffer. For byte-addressable architectures, size is measured in bytes. Some DSP architectures are not byte-addressable. In these cases, size is measured in number of WORDs, wheresizeof(WORD) == 1.

Output Arguments

collapse all

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

The rtiostream.h file defines these macros:

#define RTIOSTREAM_ERROR (-1) #define RTIOSTREAM_NO_ERROR (0)

Size of transmitted data, which is less than or equal tosize. If data is not transmitted, value is zero.

Version History

Introduced in R2009a