Opened 8 years ago
Closed 8 years ago
#4064 closed defect (fixed)
string inputs to external object constructor
Reported by: | Volker Waurich | Owned by: | Volker Waurich |
---|---|---|---|
Priority: | normal | Milestone: | Future |
Component: | Code Generation | Version: | |
Keywords: | Cc: | Martin Sjölund, Willi Braun, Adrian Pop |
Description
Hi,
String arguments to external object constructors are usually handled like this:
static const MMC_DEFSTRINGLIT(tmp0,11,"stringinput"); data->simulationInfo->extObjs[0] = omc_ExtObj_Name_constructor(threadData, MMC_REFSTRINGLIT(tmp0));
if the actual external constructor call is reached,it gets as an input
MMC_STRINGDATA(_inputArgument)
These macros put the string in some data structure. The MMC_STRINGDATA
does bitshifting to reach the original string.
This is the case for simulation. In FMU-Generation, the original string reaches the constructor call without being transformed to some other structure. Anyway, the bit shifting using MMC_STRINGDATA
is applied and hence the string argument to the constructor is incomplete.
So simulation needs the MMC_STRINGDATA
call and FMU-generation does not.
How should this problem being adressed? Shall we check if an FMU
should be generated and decide in the template call whether to set the macro or not? Or can we leave these macros at all? (I have no overview where these things are necessary)
Thanks.
Attachments (1)
Change History (19)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
Use the model from #4062 with:
translateModelFMU(MDD_test, version="1.0", fmuType="me"); getErrorString();
I end up with a runtime error:
MDDSerialPort.h: CreateFileA of serial port OM3 failed with error: 2
Which should be "COM3"
See attached file for more details.
by , 8 years ago
comment:3 by , 8 years ago
The attached file was wrong, Iv found the mmc_mk_scon. The runtime error appears anyway.
comment:5 by , 8 years ago
In MDD_test_callExternalObjectConstructors
data->simulationInfo->stringParameter[0]
gets in the constructor, which is "COM3". After calling MMC_STRINGDATA(_deviceName)
only "OM3" is left.
comment:6 by , 8 years ago
comment:7 by , 8 years ago
For DAE.SCONST inputs to external constructor calls, it works fine. For DAE.CREF inputs of type DAE.T_STRING, we miss a mmc_mk_scon()
call. The cref is generated by
CodegenCFunction.tpl ::daeExpCrefRhs
. I do not know which template I should change to generate a mmc_mk_scon() call of a cref. The templates to generate crefs are used frequently and adding mmc_mk_scon-call breaks the codegeneration. I could implement various cref-template functions to bypass the ordinary templates for the concrete situation, but I dont like to add so many functions for such a special case. As a workaround for my model, I will evaluate all parameters and leave this topic open for discussion.
comment:8 by , 8 years ago
Owner: | changed from | to
---|---|
Priority: | high → normal |
Status: | new → assigned |
comment:9 by , 8 years ago
CREF does not need any mmc_mk_scon
call (bootstrapping works just fine after all). Which variable does not work for you? (with your commit, COM3
is passed just fine, but then seg.faults due to COM3
not being available on Linux)
comment:10 by , 8 years ago
In MDD_test_01.exp.c :: MDD_test_callExternalObjectConstructors
I get data->simulationInfo->stringParameter[0] /* serialReceive._Serial_Port PARAM */
as an input. This is forwarded to MDD_test_functions.c :::omc_Modelica__DeviceDrivers_Communication_SerialPort_constructor
and then put in the constructor:
MDD_serialPortConstructor(MMC_STRINGDATA(_deviceName),...
data->simulationInfo->stringParameter[0]
is "COM3" and MMC_STRINGDATA(data->simulationInfo->stringParameter[0])
is "OM3"
comment:11 by , 8 years ago
That works just fine with your commit 889d1e and becomes COM3
. I get the following printed just fine:
assert | debug | MDDSerialPort.h: open(..) of serial port COM3 failed (No such file or directory)
I guess the problem is simply that the start-value is not boxed when it is put into the data structure (it is already boxed at that place in the C runtime, so you need to fix it sooner in the FMU code; I can look for the place).
comment:12 by , 8 years ago
Oh..misunderstanding. The commit fixes the problem but breaks other tests. So I thought I need something different. But if you say that this fix could be valid, I will take a closer look at the broken test.
comment:14 by , 8 years ago
The value in there seems to be ignored by some other FMI function. It's rather messy and I guess I won't be able to find the cause :(
comment:15 by , 8 years ago
Shall we check whether the inputs to the constructor are constant and if not, output a warning or even evaluate all constructor inputs by default?
comment:16 by , 8 years ago
We shouldn't need to. I think we have use cases for constructing external objects depending on parameters.
This should not be a problem that is only true for external objects, but also more general models, right? Although that warrants testing :)
comment:18 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
If there are no opposite views, the issue is fixed and I will close the ticket.
What code in FMUs get this code? All Modelica function calls take strings and all strings in the simulation must use
mmc_mk_scon
or similar to box the argument. Where is this not performed?