20.08.2019
Posted by 
Active3 years, 3 months ago

After issues I met, trying to read from COM port with Simulink, as I wrote in this discussion, I would like to follow Phil Goddard's suggestion on writing a C S-function for that. My problem is that I am not able to write C-code, so I hope in some help from you.I have found this two scripts on the net about C S-function for serial communication:

Hi I would like to ask where to find examples of serial code conversion to parallel using Parallel Computing Toolbox. Specifically I want to convert a serial matlab algorithm, which simulates fire spreading using cellular automata. I found some very simple examples at official site of Mathworks but it is not what i' m looking for. 1 serial peripheral interface. MATLAB Compiler Simulink Coder Simulink HDL. Image and Video Processing with MATLAB.pdf. Two new products and updates to MATLAB, Simulink, and 81 other. Implementing a floating Point Multiplier using HDL Coder and Simulink. Implementing a floating Point Multiplier using HDL Coder. October 24, 2014 October 26, 2014 Examples, Home Leave a comment code parallel to serial converter Verilog. Parallel to serial converter `timescale 1ns / 1ps. Module Parallel2Serial(Parin, clk, serout,reset, load, eoc).

1)

But when I try to compile it by mex sfun_comport.c it returns following errors:

2)

This produces:

As you can notice common errors between two S-function are about:

Do you have some suggestion to fix those errors ?

PS: I have MATLAB 2013b 64-bit, 64-bit Windows 7, Microsoft Visual C++ 2010 (32-bit) as compiler (it has worked fine in 64-bit matlab to produce mex files)

Community
cyberdynecyberdyne
1361 gold badge3 silver badges20 bronze badges

1 Answer

You still have to write those functions by yourself. As you can see from their names, they define the sizes and sample time of the S-Function. They are required components of a complete and functional S-Function.

Users can select individual maps in areas of interest and transfer the maps to a compatible GARMIN GPS unit. Garmin MapSource CD's Garmin MapSource TM CD's MapSource TM products feature geographic Electronic Base Map Data plus Trip & Waypoint Management Software on CD-ROM. Electronic Base Map Data This data augments the information already on the electronic basemap compatible GARMIN GPS units and is sold as an accessory. Mapsource cd rom download.

For example:

static void mdlInitializeSizes(SimStruct *S) describes the sizes information that is used by Simulink to determine the S-function block's characteristics (number of inputs, outputs, states, etc.).

static void mdlInitializeSampleTimes(SimStruct *S) is used to specify the sample time(s) for your S-function.

See also:

GitaarLAB
12.2k8 gold badges44 silver badges70 bronze badges
Manxiu ZhanManxiu Zhan
Parallel to serial conversion simulink coder online
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Not the answer you're looking for? Browse other questions tagged matlabserial-portsimulinks-function or ask your own question.

Discrete-time serial-in, parallel-out shift register

  • Library:
  • Simscape / Electrical / Control / General Control

Description

The Serial-In Parallel-Out Shift Register block implements a serial-in parallel-out shift register in discrete time. You can use a shift register to convert between serial and parallel interfaces or to implement a circuit delay or hardware stack.

This block outputs a vector of last N samples of the input signal. If the input signal is a vector, the block outputs the last N samples of each input signal.

Ports

Input

Output

Parallel output signal.

Data Types: singledouble

Parameters

Number of samples — Number of input samples
4 (default) positive integer

Initial condition — Initial value of the input sample
0 (default) real number

Initial value of the N-1 samples preceeding simulation start time. The value must be a scalar or a vector of the same size as the input signal.

Sample time (-1 for inherited) — Block sample time
-1 (default) 0 positive scalar

Parallel To Serial Conversion

Time between consecutive block executions. During execution, the block produces outputs and, if appropriate, updates its internal state. For more information, see What Is Sample Time? (Simulink) and Specify Sample Time (Simulink).

For inherited discrete-time, specify -1. For discrete-time, specify a positive integer. For continuous-time, specify 0.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.