Hi,
I am having problem getting my simulation to run. I have two classes ADC and VoltageMonitor. ADC has a private attribute val:int and VoltageMonitor has a private attribute voltage:int. I want Voltagemonitor to use the operation readADCVal():int in ADC to update it's own attribute via ports typed by an interface:
I have a stm in VoltageMonitor that just calls readADCVal() at it's initial transition and sets its attribute voltage to the returned value:
and the implementation of readADCVal():int is like this:
When I press Full Build I get the following error:
I then decided to simplify things a bit in order to make sure that I could get the behaviour that I wanted by instead of using ports and interfaces only use associations and make sure that I at least could call the operation in ADC from VoltageMonitor. So instead of readADCVal():int I created a printVal() operation and instead of a private attribute val I changed it to public:
printVal() has the following implementation:
I also updated to stm in VoltageMonitor:
Now when I do Full Build, i do not get any errors, however as soon as I run the simulation i just stops and I get this message in the console:
DefaultComponent.exe.stackdump looks like this:
I then simplified it even further and removed the val from the implementation of the printVal() operation:
Now the simulation works:
Questions:
Do you know why I get the Cygwin exception above?
How can I modify the model to get the behaviour that I wanted in the first place?
Thanks!
Regarding your model with Association between objects: the executable crashes because the association between your objects is not initialized, i.e., it's a null pointer. The simplest way is to delete it from the diagram that has your objects on it (click on the association and then press the delete button on the keyboard; do not delete it from the model) and then create a "link" between your objects, by selecting Link on the Drawing Toolbar and then drawing a line between your objects. That subtle change will make it work, so rebuild your model and run it again, and it should work without crashing.
Regarding your model with Port: you are not using the port when calling the readADCVal() method, that's why it cannot build the generated code. For that, a macro OPORT() or OUT_PORT() is provided by Rhapsody, to be used to call methods through ports. You need to do a couple of things:
1- Assuming the name of the port is "port_0", your default transition needs to become: /voltage = OPORT(port_0)->readADCVal(); (this way your code can build, but it won't call the method, see next point)
2- You need also to double-click on the port_0 that is under the class ADC, then check the box "Behavior" that is in the General tab, then click OK, then confirm that you want to realize the interface, that way an inheritance with the interface class iVM_ADC will be added to the class ADC (this way the readADCVal() will be called)
Rebuild your model and it should work.
Good luck!