- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Openmodelica socket communication
Openmodelica socket communication
Openmodelica socket communication
Hi,
I'm new in this.
I'm trying to run openmodelica compiler thru sockets. I'm working under ubuntu 9.10 and using openmodelica 1.4.5. I want simple communication client-server-omc. Client will send some numbers to server and server runs omc and use this numbers,solve them and send back result to client. I'm working with php and I'm able to create sock.comm. between two servers but how to create between server and omc?? I'm found command like ./omc -dbgCmdPort=<port> +d=interactive but dont know how to use it. I was not able to find anything usefull on the internet to this because mostly people are using corba. but I need to use socket communication
I would be very happy if somebody could help me with this problem.
I apologize for my english
with regards,
Frank
Re: Openmodelica socket communication
$ omc +d=interactive &
$ telnet 127.0.0.1 29500
> 1+2
< 3
Works fine. I'll add text when launching "omc +d=interactive":
print("Opening a socket on port " +& intString(29500) +& "\n");
Since it doesn't say anywhere which port is actually opened...
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
hi, there is another problem. Why it is not working? What's wrong?...
<< root@ubuntu:/usr/lib/omc/bin# ./omc +d=interactive &
[3] 3067
[2] Done ./omc +d=interactive
<< root@ubuntu:/usr/lib/omc/bin# telnet 127.0.0.1 29500
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
class heli input Real alfa; Real x1(start=0); Real x2(start=0); Real x3(start=0); Real x4(start=0); equation der(x1) = x2; der(x3) = x4; der(x2) = -0.65*x2 - 0.02*x4 + 5.4*alfa; der(x4) = -1.57 - 0.03*x4 + 9.8*x1 + 9.8*alfa; end heli
[2:1]: error: expecting SEMICOLON, found ''
simulate(heli)
record SimulationResult
resultFile = "Simulation Failed. Model: heli does not exists! Please load it first before simulation."
end SimulationResult;
thank you
Re: Openmodelica socket communication
It reached the end of the string without finding the semicolon that always follows "end XXX".
I added a trailing semicolon and the class seemed to load fine.
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
class heli input Real alfa; Real x1(start=0); Real x2(start=0); Real x3(start=0); Real x4(start=0); equation der(x1) = x2; der(x3) = x4; der(x2) = -0.65*x2 - 0.02*x4 + 5.4*alfa; der(x4) = -1.57 - 0.03*x4 + 9.8*x1 + 9.8*alfa; end heli;
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
>>> class heli input Real alfa; Real x1(start=0); Real x2(start=0); Real x3(start=0); Real x4(start=0); equation der(x1) = x2; der(x3) = x4; der(x2) = -0.65*x2 - 0.02*x4 + 5.4*alfa; der(x4) = -1.57 - 0.03*x4 + 9.8*x1 + 9.8*alfa; end heli;
{heli}
>>> simulate(heli)
record SimulationResult
resultFile = "heli_res.plt"
end SimulationResult;
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
Is this "{heli}" your output after you put in "class ..."? Because it's still not working for me. After I put in "class ..." I get "ok" and when I press enter I get message:
Error occured building AST
Syntax Error
then put in simulate(heli) and nothing happend.
Re: Openmodelica socket communication
I also try to put simulate right after output OK but still nothing happend... I dont know what else to do. If I do it in OMCShell or OMCShell terminal then it is working but I need to do it thru ubuntu terminal. I'm trying as client sending this commands thru socket to OMC and I want to make graph from output numbers after simulation.
any Ideas what can be wrong?
Re: Openmodelica socket communication
{heli} is the output we get in the new versions of OpenModelica. Why it wouldn't work in the terminal, I do not know
Have you tried the newer OpenModelica releases?
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
For Windows I would say wait until RC3 is released. But since you use Linux I would say the trunk version is best (we made lots of changes since RC1, so waiting isn't really needed).
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
Ah yes, we don't build Linux packages very often, so you would probably have to compile it yourself or use RC1.
I did run the code you used under RC1 and it seems to work fine there. So I guess you should try it.
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
ok so I have install openmodelica 1.5.0 RC1 and it still not working. So this is realy bad for me.
Have try this RC1 in linux? Because I runnig it thru terminal.....(not OMShell-terminal) just ubuntu terminal....
./omc +d=interactive &
telnet 127.0.0.1 29500
and in this case it is not working. Thru OMShell-terminal it's working fine.
Re: Openmodelica socket communication
Hmmm... Are you running ./omc from the install directory (I assume /usr/bin)? omc will put all temporary files in the directory you launch it from, so go to "~/omc-tmp/" and launch $OPENMODELICAHOME/bin/omc and maybe it will run better?
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
Well, of course you'd need to create the temporary folder
You can name it anything you want. You will just have problems running it from /usr/lib since your user doesn't have write rights to it
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
1. mkdir ~/omc-tmp
2. cd ~/omc-tmp
3. /use/lib/omc/bin/omc +d=interactive &
4. telnet 127.0.0.1 29500
5. ??
6. profit
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
so I tried this:
___________________________________________________
root@ubuntu:~/omc-tmp# /usr/lib/omc/bin/omc +d=interactive &
[5] 2032
[4] Done /usr/lib/omc/bin/omc +d=interactive
root@ubuntu:~/omc-tmp# telnet 127.0.0.1 29500
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
class heli input Real alfa; Real x1(start = 0); Real x2(start = 0); Real x3(start = 0); Real x4(start = 0); equation der(x1) = x2; der(x3) = x4; der(x2) = -0.65*x2 - 0.02*x4 + 5.4*alfa; der(x4) = -1.57 - 0.03*x4 + 9.8*x1 + 9.8*alfa; end heli;
Oksimulate(heli)
simulate(heli)
plot(x1)
"No simulation result to plot."
_______________________________________________________________
in RC1 the same......
or doing this:
________________________________________
neo@ubuntu:~/omc-tmp$ /usr/lib/omc/bin/omc +d=interactive &
[1] 1924
neo@ubuntu:~/omc-tmp$ telnet 127.0.0.1 29500
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
class heli input Real alfa; Real x1(start = 0); Real x2(start = 0); Real x3(start = 0); Real x4(start = 0); equation der(x1) = x2; der(x3) = x4; der(x2) = -0.65*x2 - 0.02*x4 + 5.4*alfa; der(x4) = -1.57 - 0.03*x4 + 9.8*x1 + 9.8*alfa; end heli;
Oksimulate(heli)
Connection closed by foreign host.
[1]+ Segmentation fault /usr/lib/omc/bin/omc +d=interactive
neo@ubuntu:~/omc-tmp$
__________________________________________________________
Re: Openmodelica socket communication
Can you run the following commands and paste the output?
ls -l heli.makefile heli heli_res.plt
make -f heli.makefile && ./heli
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
you mean just into ubuntu terminal? I did that and:
root@ubuntu:~/omc-tmp# ls -l heli.makefile heli heli_res.plt
ls: cannot access heli.makefile: No such file or directory
ls: cannot access heli: No such file or directory
ls: cannot access heli_res.plt: No such file or directory
root@ubuntu:~/omc-tmp# make -f heli.makefile && ./heli
make: heli.makefile: No such file or directory
make: *** No rule to make target `heli.makefile'. Stop.
Re: Openmodelica socket communication
If not even root will create the files... Something must break sooner.
I have two ideas. One is the old omc server is still running... To shut it down for sure, use exit() in telnet.
The other would be to run "omc +d=interactive,failtrace +showErrorMessages" as the server. That will produce some extra error messages that might help.
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
ok so exit() is not working only quit() and I always use it otherwise it's not possible to run omc +d=interactive & command again.
To second part: I've tried put it to terminal many ways but always giving me "help". I have try to run first omc +d=interactive and then omc +d=failtrail +showErrorMessages and also nothing, only help and omc still runnig as server in the background.
Re: Openmodelica socket communication
It does for me, so yes it should. I might try to build a deb-package soon anyway.
Which reminds me... The deb package is weird. It doesn't set OPENMODELICAHOME env variable. You need to call omc-start for that to happen.
What is "env | grep OPENMODELICAHOME" ?
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
I checked the deb file today and /usr/bin/omc-start is a script that sets OPENMODELICAHOME. I think the omshell, etc scripts also set it.
So either use the script or put "export OPENMODELICAHOME=/usr/lib/omc" in your ~/.bashrc file.
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
Unix doesn't do COM Objects
There are more ways to get simulation data though. But reading the file is probably easiest; else you could always convert it to gnuplot with a python-script and let gnuplot output the image
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
yeah I know that COM objects are not available under Unix I was just looking for plan B if this will not working. COM seems to be easier.
I dont have much time so studying python is not good idea for me. I'm doing it with php. But problem is that when I send simulate command I get empty output. First time I thought that If I solve this problem with simulation thru telnet then it will work also thru browser. It's really big problem for me. Probably I will read the file right thru sript and not sending it thru socket but still this simulation is needed to create this file. It drives me crazy.
Anyway is it nessesary to always execute omc-start after rebooting system? Because I always have to run it. The last command in this script is not working by the way. It gives me "help" option.
Is anything telling you this error? -- [11:13]: error: expecting EOF, found 'simulate' --
Re: Openmodelica socket communication
That probably means you are missing a newline before the simulate command?
- sjoelund.se
- 1700 Posts
Re: Openmodelica socket communication
hi,
so I solve this. I made mistake in permissons. The simulate was running always but problem was that omc was not able to create new file. I have to change default /var/www folder for another with standard user permissons.
Just in case if anybody will have the same problem.
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Openmodelica socket communication