@@ -4,8 +4,7 @@ package Communication
4
4
model SharedMemoryRead "A block for reading data from a shared memory buffer"
5
5
extends Modelica_DeviceDrivers.Utilities.Icons.BaseIcon;
6
6
extends Modelica_DeviceDrivers.Utilities.Icons.SharedMemoryIcon;
7
- extends
8
- Modelica_DeviceDrivers.Utilities.Icons.PartialClockedDeviceDriverIcon;
7
+ extends Modelica_DeviceDrivers.Utilities.Icons.PartialClockedDeviceDriverIcon;
9
8
import Modelica_DeviceDrivers.Packaging.SerialPackager;
10
9
import Modelica_DeviceDrivers.Packaging.alignAtByteBoundary;
11
10
import Modelica_DeviceDrivers.Communication.SharedMemory;
@@ -16,10 +15,10 @@ package Communication
16
15
annotation(Dialog(group="Shared memory partition" ), choices(__Dymola_checkBox=true));
17
16
parameter Integer userBufferSize= 16 * 1024
18
17
"Buffer size of shared memory partition in bytes (if not deduced automatically)"
19
- annotation(Dialog(enable=not autoBufferSize, group="Shared memory partition" ));
18
+ annotation(Dialog(enable=not autoBufferSize, group="Shared memory partition" ));
20
19
parameter String memoryID= "sharedMemory" "ID of the shared memory buffer" annotation(Dialog(group="Shared memory partition" ));
21
20
22
- Interfaces.PackageOut pkgOut annotation (Placement(
21
+ Interfaces.PackageOut pkgOut annotation (Placement(
23
22
transformation(
24
23
extent={{-20,-20},{20,20}},
25
24
rotation=90,
@@ -47,10 +46,9 @@ package Communication
47
46
end if ;
48
47
49
48
dummy = previous(dummy) + Ts;
50
- pkgOut.dummy = Modelica_DeviceDrivers.Blocks.Packaging.SerialPackager.Internal.DummyFunctions.setPackage(
49
+ pkgOut.dummy = Modelica_DeviceDrivers.ClockedBlocks.Communication.Internal.DummyFunctions.readSharedMemory(
50
+ sm,
51
51
pkgOut.pkg,
52
- SharedMemory_.read(sm),
53
- bufferSize,
54
52
dummy);
55
53
annotation (preferredView="info" ,
56
54
Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,
@@ -76,10 +74,10 @@ provided by the parameter <b>memoryID</b>. If the shared memory partition does n
76
74
annotation(Dialog(group="Shared memory partition" ), choices(__Dymola_checkBox=true));
77
75
parameter Integer userBufferSize= 16 * 1024
78
76
"Buffer size of shared memory partition in bytes (if not deduced automatically)"
79
- annotation(Dialog(enable=not autoBufferSize, group="Shared memory partition" ));
77
+ annotation(Dialog(enable=not autoBufferSize, group="Shared memory partition" ));
80
78
parameter String memoryID= "sharedMemory" "ID of the shared memory buffer" annotation(Dialog(group="Shared memory partition" ));
81
79
82
- Interfaces.PackageIn pkgIn annotation (Placement(
80
+ Interfaces.PackageIn pkgIn annotation (Placement(
83
81
transformation(
84
82
extent={{-20,-20},{20,20}},
85
83
rotation=270,
@@ -100,16 +98,12 @@ provided by the parameter <b>memoryID</b>. If the shared memory partition does n
100
98
initialized := previous(initialized);
101
99
end if ;
102
100
equation
103
- pkgIn.userPkgBitSize = if autoBufferSize then - 1 else userBufferSize* 8 ;
104
- pkgIn.autoPkgBitSize = 0 ;
105
- bufferSize = if autoBufferSize then Modelica_DeviceDrivers.Packaging.SerialPackager_.getBufferSize(
106
- pkgIn.pkg)
107
- else userBufferSize;
108
- dummy =
109
- Modelica_DeviceDrivers.ClockedBlocks.Communication.Internal.DummyFunctions.writeSharedMemory(
101
+ pkgIn.userPkgBitSize = if autoBufferSize then - 1 else userBufferSize* 8 ;
102
+ pkgIn.autoPkgBitSize = 0 ;
103
+ bufferSize = if autoBufferSize then Modelica_DeviceDrivers.Packaging.SerialPackager_.getBufferSize(pkgIn.pkg) else userBufferSize;
104
+ dummy = Modelica_DeviceDrivers.ClockedBlocks.Communication.Internal.DummyFunctions.writeSharedMemory(
110
105
sm,
111
- Modelica_DeviceDrivers.Packaging.SerialPackager_.getPackage(
112
- pkgIn.pkg),
106
+ pkgIn.pkg,
113
107
bufferSize,
114
108
pkgIn.dummy);
115
109
@@ -170,11 +164,9 @@ provided by the parameter <b>memoryID</b>. If the shared memory partition does n
170
164
171
165
dummy = previous(dummy) + Ts;
172
166
173
- pkgOut.dummy =
174
- Modelica_DeviceDrivers.ClockedBlocks.Packaging.SerialPackager.Internal.DummyFunctions.setPackage(
167
+ pkgOut.dummy = Modelica_DeviceDrivers.ClockedBlocks.Communication.Internal.DummyFunctions.readUDP(
168
+ socket,
175
169
pkgOut.pkg,
176
- Modelica_DeviceDrivers.Communication.UDPSocket_.read(socket),
177
- bufferSize,
178
170
dummy);
179
171
180
172
annotation (preferredView="info" ,
@@ -200,11 +192,11 @@ provided by the parameter <b>memoryID</b>. If the shared memory partition does n
200
192
parameter Integer userBufferSize= 16 * 1024
201
193
"Buffer size of message data in bytes (if not deduced automatically)." annotation(Dialog(enable=not autoBufferSize, group="Outgoing data" ));
202
194
parameter String IPAddress= "127.0.0.1" "IP address of remote UDP server"
203
- annotation (Dialog(group="Outgoing data" ));
195
+ annotation (Dialog(group="Outgoing data" ));
204
196
parameter Integer port_send= 10002 "Target port of the receiving UDP server"
205
- annotation (Dialog(group="Outgoing data" ));
197
+ annotation (Dialog(group="Outgoing data" ));
206
198
207
- Interfaces.PackageIn pkgIn annotation (Placement(
199
+ Interfaces.PackageIn pkgIn annotation (Placement(
208
200
transformation(
209
201
extent={{-20,-20},{20,20}},
210
202
rotation=270,
@@ -218,19 +210,15 @@ provided by the parameter <b>memoryID</b>. If the shared memory partition does n
218
210
219
211
pkgIn.userPkgBitSize = if autoBufferSize then - 1 else userBufferSize* 8 ;
220
212
pkgIn.autoPkgBitSize = 0 ;
221
- bufferSize = if autoBufferSize then Modelica_DeviceDrivers.Packaging.SerialPackager_.getBufferSize(
222
- pkgIn.pkg)
223
- else userBufferSize;
213
+ bufferSize = if autoBufferSize then Modelica_DeviceDrivers.Packaging.SerialPackager_.getBufferSize(pkgIn.pkg) else userBufferSize;
224
214
225
215
// socket = previous(socket);
226
216
227
- dummy =
228
- Modelica_DeviceDrivers.ClockedBlocks.Communication.Internal.DummyFunctions.sendToUDP(
217
+ dummy = Modelica_DeviceDrivers.ClockedBlocks.Communication.Internal.DummyFunctions.sendToUDP(
229
218
socket,
230
219
IPAddress,
231
220
port_send,
232
- Modelica_DeviceDrivers.Packaging.SerialPackager_.getPackage(
233
- pkgIn.pkg),
221
+ pkgIn.pkg,
234
222
bufferSize,
235
223
pkgIn.dummy);
236
224
@@ -246,32 +234,50 @@ provided by the parameter <b>memoryID</b>. If the shared memory partition does n
246
234
extends Modelica_DeviceDrivers.Utilities.Icons.InternalPackage;
247
235
package DummyFunctions
248
236
extends Modelica_DeviceDrivers.Utilities.Icons.InternalPackage;
237
+ function readSharedMemory
238
+ input Modelica_DeviceDrivers.Communication.SharedMemory sm;
239
+ input Modelica_DeviceDrivers.Packaging.SerialPackager pkg;
240
+ input Real dummy;
241
+ output Real dummy2;
242
+ algorithm
243
+ Modelica_DeviceDrivers.Communication.SharedMemory_.read(sm, pkg);
244
+ dummy2 := dummy;
245
+ end readSharedMemory;
246
+
249
247
function writeSharedMemory
250
248
input Modelica_DeviceDrivers.Communication.SharedMemory sm;
251
- input String data ;
249
+ input Modelica_DeviceDrivers.Packaging.SerialPackager pkg ;
252
250
input Integer len;
253
251
input Real dummy;
254
252
output Real dummy2;
255
253
algorithm
256
- Modelica_DeviceDrivers.Communication.SharedMemory_.write(
257
- sm,data,len);
258
- dummy2 := dummy;
254
+ Modelica_DeviceDrivers.Communication.SharedMemory_.write(sm, pkg, len);
255
+ dummy2 := dummy;
259
256
end writeSharedMemory;
260
257
258
+ function readUDP
259
+ input Modelica_DeviceDrivers.Communication.UDPSocket socket;
260
+ input Modelica_DeviceDrivers.Packaging.SerialPackager pkg;
261
+ input Real dummy;
262
+ output Real dummy2;
263
+ algorithm
264
+ Modelica_DeviceDrivers.Communication.UDPSocket_.read(socket, pkg);
265
+ dummy2 := dummy;
266
+ end readUDP;
267
+
261
268
function sendToUDP
262
- import Modelica_DeviceDrivers.Communication.UDPSocket;
263
- input UDPSocket socket;
269
+ input Modelica_DeviceDrivers.Communication.UDPSocket socket;
264
270
input String ipAddress "IP address where data has to be sent" ;
265
271
input Integer port "Port number where data has to be sent" ;
266
- input String data "Data to be sent" ;
272
+ input Modelica_DeviceDrivers.Packaging.SerialPackager pkg ;
267
273
input Integer dataSize "Size of data" ;
268
274
input Real dummy;
269
275
output Real dummy2;
270
276
algorithm
271
- Modelica_DeviceDrivers.Communication.UDPSocket_.sendTo(
272
- socket, ipAddress, port,data, dataSize);
273
- dummy2 := dummy;
277
+ Modelica_DeviceDrivers.Communication.UDPSocket_.sendTo(socket, ipAddress, port, pkg, dataSize);
278
+ dummy2 := dummy;
274
279
end sendToUDP;
280
+
275
281
end DummyFunctions;
276
282
277
283
end Internal;
0 commit comments