从众创共享中下载的MDD库,使用VC2017编译器,32位,modelica3.2.3,试图与串口通讯时报错:
This log was created by MWSolver at Thu Jul 24 11:43:01 2025.
MWSolver started ...
Error:MDDSerialPort.h: CreateFileA of serial port failed with error: 3
Error:Failed to initialize Solver!
Simulation finished at time = 0 (stopTime = 1)
CPU time for Integration: 0.062s
Number of Time Events: 0
Number of State Events: 0
Number of Step Events: 0
Number of Grid Points: 0
Minimum integration stepsize: 0.002
Maximum integration stepsize: 0.002
仿真失败。初始化失败。
我当前的代码为
model Model7
"Test case to send two integer values using serial interface"
extends Modelica.Icons.Example;
Modelica_DeviceDrivers.Blocks.Communication.SerialPortSend serialSend(
autoBufferSize = true,
baud = Modelica_DeviceDrivers.Utilities.Types.SerialBaudRate.B115200,
Serial_Port = "COM1",
sampleTime = 0.1) annotation(Placement(transformation(
extent = {{-10, -10}, {10, 10}},
rotation = -90,
origin = {-46, -90})));
Modelica_DeviceDrivers.Blocks.Packaging.SerialPackager.Packager packager
annotation(Placement(transformation(extent = {{-58, 42}, {-38, 62}})));
Modelica_DeviceDrivers.Blocks.OperatingSystem.SynchronizeRealtime synchronizeRealtime
annotation(Placement(transformation(origin = {21.6514, 43.0459},
extent = {{-10, -10}, {10, 10}})));
Modelica.Blocks.Sources.IntegerExpression integerExpression(y = integer(3 * sin(
time) + 3))
annotation(Placement(transformation(extent = {{-100, 0}, {-74, 20}})));
Packaging.SerialPackager.PackUnsignedInteger packInt(width = 10, nu = 1)
annotation(Placement(transformation(extent = {{-56, 0}, {-36, 20}})));
Packaging.SerialPackager.AddString addString(data = stringEx.y, nu = 1)
annotation(Placement(transformation(extent = {{-56, -30}, {-36, -10}})));
Utilities.StringExpression stringEx(y = "An example String\n")
annotation(Placement(transformation(extent = {{-94, -28}, {-66, -10}})));
Packaging.SerialPackager.AddInteger addInteger(nu = 1)
annotation(Placement(transformation(extent = {{-56, -66}, {-36, -46}})));
Modelica.Blocks.Sources.IntegerExpression integerExpression1(
y = integer(3 * sin(
time) + 3))
annotation(Placement(transformation(extent = {{-100, -66}, {-72, -46}})));
equation
connect(integerExpression.y, packInt.u) annotation(Line(
points = {{-72.7, 10}, {-58, 10}},
color = {255, 127, 0}));
connect(packInt.pkgOut[1], addString.pkgIn) annotation(Line(
points = {{-46, -0.8}, {-46, -9.2}}));
connect(packager.pkgOut, packInt.pkgIn) annotation(Line(
points = {{-48, 41.2}, {-48, 31.6}, {-46, 31.6}, {-46, 20.8}}));
connect(addString.pkgOut[1], addInteger.pkgIn) annotation(Line(
points = {{-46, -30.8}, {-46, -45.2}}));
connect(addInteger.pkgOut[1], serialSend.pkgIn) annotation(Line(
points = {{-46, -66.8}, {-46, -79.2}}));
connect(integerExpression1.y, addInteger.u[1]) annotation(Line(
points = {{-70.6, -56}, {-58, -56}},
color = {255, 127, 0}));
annotation(Documentation(info = "
Example for serial port support
Hardware setup
In order to execute the example an appropriate physical connection between the sending and the receiving serial port needs to be established, (e.g., by using a null modem cable between the two serial port interfaces http://en.wikipedia.org/wiki/Null_modem). In fact a minimal mull modem with lines (TxD, Rxd and GND) is sufficient. Next, the SerialPortReceive and SerialPortSend blocks parameters must be updated with the device filenames corresponding to the connected physical serial ports. Now, the example can be executed.
Alternative: Using virtual serial port devices for test purposes
To run the example without serial port hardware, it is possible to resort to virtual serial ports. Possible ways of doing this are described in the following.
On Linux, make sure that socat is installed, e.g., on an Ubuntu machine do
sudo aptitude install socat
Now open a console and create two virtual serial port interfaces using socat:
socat -d -d pty,raw,echo=0 pty,raw,echo=0
The socat program will print the device file names that it created. The output will resemble the following:
2013/11/24 15:20:21 socat[3262] N PTY is /dev/pts/1 2013/11/24 15:20:21 socat[3262] N PTY is /dev/pts/3 2013/11/24 15:20:21 socat[3262] N starting data transfer loop with FDs [3,3] and [5,5]
Use them in the Send and Receive block. E.g., for the output above you would use "/dev/pts/1" in SerialPortReceive and "/dev/pts/3" in SerialPortSend.
You may have also have a look at the discussion about virtual serial port devices on stackoverflowhttp://stackoverflow.com/questions/52187/virtual-serial-port-for-linux.
On Windows, make sure that the null modem emulator com0com is installed.
Start the Setup for com0com and check the device names of the created virtual port pair. E.g. you could type "COM6" in SerialPortReceive and "COM7" in SerialPortSend.
是在例程里作了修改而来的,看起来是找不到该串口的路径,但我能够在串口调试助手或arduino IDE中正常打开该串口并通讯,设备管理器中的设备端口号和状态也是正常的,请问该怎么解决