In this section, a first introduction to the Modelica_DeviceDrivers library is given at hand of several examples.


The library allows to access some selected external devices in Modelica models. This is achieved by using the Modelica external C interface to call the appropriate C driver functions provided by the underlying operating system. Currently MS Windows and Linux are supported.

The library is organized in several layers as indicated below. It is noteworthy that the library provides two high-level Drag & Drop block interfaces. The first (.Blocks) is compatible to Modelica 3.2, using the traditional "when sample()" element for periodically calling Modelica functions from the Function Layer. The second (.ClockedBlocks) uses the Synchronous Language Elements extension introduced in Modelica 3.3 for periodic execution.

Usage Examples

Looking at the examples in .Blocks.Examples (or .ClockedBlocks.Examples, respectively) the usage of the library should be self-explanatory. In the following two exemplarily examples are considered.

User Input devices

E.g., using a joystick or gamepad as input for a real-time simulation just requires to drag & drop two blocks: .Blocks.OperatingSystem.SynchronizeRealtime and .Blocks.InputDevices.JoystickInput (or respectively, .ClockedBlocks.OperatingSystem.SynchronizeRealtime and .ClockedBlocks.InputDevices.JoystickInput). See the executable example at .(Clocked)Blocks.Examples.TestInputJoystick:

The SynchronizeRealtime block synchronizes the simulation time with the operating systems real-time clock. That allows interactive Modelica simulations, e.g., a vehicle driving simulation using a gamepad for user inputs.

Communication Devices

Communication devices like UDP or shared memory use a common packaging concept in order to send or receive data. Therefore the same Packager can be used with different communication devices, as indicated in the figure below.

Generated at 2023-03-29T00:34:31Z by OpenModelicaOpenModelica 1.21.0~dev-397-ga7cd739 using GenerateDoc.mos