1 | within ;
|
---|
2 | package example2
|
---|
3 | record ConnectorRecord
|
---|
4 |
|
---|
5 | Integer signal;
|
---|
6 | example2.dataTypes signalType;
|
---|
7 |
|
---|
8 | end ConnectorRecord;
|
---|
9 |
|
---|
10 | connector OutputConnector = output ConnectorRecord;
|
---|
11 | annotation (uses(Modelica(version="3.2.1")));
|
---|
12 | connector InputConnector = input ConnectorRecord;
|
---|
13 | type dataTypes = enumeration(
|
---|
14 | S8 "signed integer 8 bit",
|
---|
15 | U8 "unsigned integer 8 bit",
|
---|
16 | S16 "signed integer 16 bit",
|
---|
17 | U16 "unsigned integer 16 bit",
|
---|
18 | S32 "signed integer 32 bit",
|
---|
19 | U32 "unsigned integer 32 bit",
|
---|
20 | error);
|
---|
21 | model Source
|
---|
22 |
|
---|
23 | parameter Integer signal = 3;
|
---|
24 | parameter example2.dataTypes signalType=example2.dataTypes.S8;
|
---|
25 |
|
---|
26 | OutputConnector outputConnector
|
---|
27 | annotation (Placement(transformation(extent={{90,-12},{110,8}})));
|
---|
28 |
|
---|
29 | equation
|
---|
30 | outputConnector.signal = signal;
|
---|
31 | outputConnector.signalType = signalType;
|
---|
32 |
|
---|
33 | annotation (Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100,100}}), graphics={
|
---|
34 | Rectangle(extent={{-100,100},{100,-100}}, lineColor={0,0,255}), Text(
|
---|
35 | extent={{-80,80},{80,-80}},
|
---|
36 | lineColor={0,0,255},
|
---|
37 | textString="Source")}));
|
---|
38 | end Source;
|
---|
39 |
|
---|
40 | block WriteSomeOutput
|
---|
41 |
|
---|
42 | InputConnector inputConnector[2] annotation (Placement(transformation(extent={{-110,-12},{-90,
|
---|
43 | 8}}), iconTransformation(extent={{-110,-12},{-90,8}})));
|
---|
44 | OutputConnector outputConnector annotation (Placement(transformation(extent={{90,-12},{110,
|
---|
45 | 8}}), iconTransformation(extent={{90,-12},{110,8}})));
|
---|
46 |
|
---|
47 | algorithm
|
---|
48 | // first write input to output
|
---|
49 | outputConnector:=inputConnector[1];
|
---|
50 |
|
---|
51 | // change output signal values
|
---|
52 | for i in 1:2 loop
|
---|
53 | if not
|
---|
54 | (inputConnector[i].signal==0) then
|
---|
55 | outputConnector.signal:= outputConnector.signal+1;
|
---|
56 | end if;
|
---|
57 | end for;
|
---|
58 |
|
---|
59 | annotation (Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100,100}}),
|
---|
60 | graphics={Text(
|
---|
61 | extent={{-120,40},{-62,20}},
|
---|
62 | lineColor={0,0,255},
|
---|
63 | textString="ArrayInput Size2"), Text(
|
---|
64 | extent={{60,40},{118,20}},
|
---|
65 | lineColor={0,0,255},
|
---|
66 | textString="ArrayOutput Size2"),
|
---|
67 | Rectangle(extent={{-100,100},{100,-100}}, lineColor={0,0,255}),
|
---|
68 | Text(
|
---|
69 | extent={{-80,80},{80,-80}},
|
---|
70 | lineColor={0,0,255},
|
---|
71 | textString="ChangeValuesOfSignals")}));
|
---|
72 |
|
---|
73 | end WriteSomeOutput;
|
---|
74 |
|
---|
75 | model testmodel
|
---|
76 | Source source annotation (Placement(transformation(extent={{-100,20},{-80,40}})));
|
---|
77 | Source source1 annotation (Placement(transformation(extent={{-100,-40},{-80,-20}})));
|
---|
78 | WriteSomeOutput writeSomeOutput annotation (Placement(transformation(extent={{-20,-40},{60,40}})));
|
---|
79 | equation
|
---|
80 | connect(source.outputConnector, writeSomeOutput.inputConnector[1]) annotation (Line(
|
---|
81 | points={{-80,29.8},{-60,29.8},{-60,30},{-60,30},{-60,0},{-20,0},{-20,-2},{-20,-2},{-20,-2},{-20,-2.8}},
|
---|
82 |
|
---|
83 | color={0,0,0},
|
---|
84 | smooth=Smooth.None));
|
---|
85 | connect(source1.outputConnector, writeSomeOutput.inputConnector[2]) annotation (Line(
|
---|
86 | points={{-80,-30.2},{-60,-30.2},{-60,-2},{-20,-2},{-20,1.2}},
|
---|
87 | color={0,0,0},
|
---|
88 | smooth=Smooth.None));
|
---|
89 | annotation (Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100,100}}), graphics));
|
---|
90 | end testmodel;
|
---|
91 | end example2;
|
---|