Difference between revisions of "Example"

From Proview Wiki
Jump to: navigation, search
m (Added section to start application automatically)
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<div class="mw-content-ltr" dir="ltr" lang="en">
+
These are the step by step instructions to create the C++ program from the Proview [http://www.proview.se/doc/en_us/man_dg.pdf "Designer's Guide"] Chapter 14 - Application Programming
<p>Proview Designer's Guide Chapter 13</p>
+
 
<p><strong>Open Proview</strong></p>
+
Key: MB1 = Left Mouse Button, MB2 = Middle Mouse Button, MB3 = Right Mouse Button
<ul>
+
 
<li> Ctrl+E </li>
+
'''Open Proview'''
<li> MB1 $Hier </li>
+
* Ctrl+E
<li> MB2 right panel </li>
+
* MB1 $Hier
<li> right key on Oxx $Hier </li>
+
* MB2 right panel
<li> ObjectName application </li>
+
* right arrow key on Oxx $Hier
<li> MB1 ProjectReg </li>
+
* ObjectName application
<li> MB2 in application $Hier </li>
+
* MB1 ProjectReg
<li> right key on Oxx $ProjectReg </li>
+
* MB2 in application $Hier
<li> ObjectName cpp </li>
+
* right arrow key on Oxx $ProjectReg
<li> Ctrl+E </li>
+
* ObjectName cpp
<li> Yes </li>
+
* Ctrl+E
<li> Yes </li>
+
* Yes
<li> MB3 cpp Open Project... </li>
+
* Yes
<li> Next </li>
+
* MB3 cpp Open Project...
<li> Next </li>
+
* Next
<li> No </li>
+
* Next
<li> Next </li>
+
* No
<li> Next </li>
+
* Next
<li> Next </li>
+
* Next
<li> Next </li>
+
* Next
<li> Yes </li>
+
* Next
</ul>
+
* Yes
<p><strong>Configure RootVolume</strong></p>
+
'''Configure RootVolume'''
<ul>
+
* Next
<li> Next </li>
+
* Next
<li> Next </li>
+
* Next
<li> Next </li>
+
 
</ul>
+
* MB1 Plant -> $PlantHier
<ul>
+
* MB2 right panel
<li> MB1 Plant -&gt; $PlantHier </li>
+
* right arrow key on Oxx $PlantHier
<li> MB2 right panel </li>
+
* ObjectName plant
<li> right key on Oxx $PlantHier </li>
+
* MB1 AllClases -> pwrb -> XyCurve
<li> ObjectName plant </li>
+
* MB2 in plant $PlantHier
<li> MB1 AllClases -&gt; pwrb -&gt; XyCurve </li>
+
* right arrow key on Oxx XyCurve
<li> MB2 in plant $PlantHier </li>
+
* ObjectName curve
<li> right key on Oxx XyCurve </li>
+
* Ctrl+E
<li> ObjectName curve </li>
+
* Yes
<li> Ctrl+E </li>
+
 
<li> Yes </li>
+
'''''/usr/local/pwrp/cpp/src/appl/ra_myappl.cpp'''''
</ul>
+
<nowiki>
<p><em><strong>/usr/local/pwrp/cpp/src/appl/ra_myappl.cpp</strong></em></p>
+
#include <math.h>
<table border="0">
+
#include "pwr.h"
<tbody>
+
#include "pwr_baseclasses.hpp"
<tr>
+
#include "rt_gdh.h"
<td>
+
 
<p>#include &lt;math.h&gt;<br />#include "pwr.h"<br />#include "pwr_baseclasses.hpp"<br />#include "rt_gdh.h"<br /><br /><br />class ra_myappl {<br />&nbsp;pwr_Class_XyCurve *curve_ptr;<br />&nbsp;pwr_tRefId dlid;<br />public:<br />&nbsp;ra_myappl() {}<br />&nbsp;void init();<br />&nbsp;void scan();<br />&nbsp;void close();<br />};<br /><br />void ra_myappl::init()<br />{<br />&nbsp;pwr_tStatus sts;<br />&nbsp;pwr_tOName name = "plant-curve";<br />&nbsp;<br />&nbsp;// Connect to database<br />&nbsp;sts = gdh_Init( "ra_myappl");<br />&nbsp;if ( EVEN(sts)) exit(0);<br /><br />&nbsp;// Direct link to curve object<br />&nbsp;sts = gdh_RefObjectInfo( name, (void **)&amp;curve_ptr, &amp;dlid, sizeof(*curve_ptr));<br />&nbsp;if ( EVEN(sts)) exit(0);<br />}<br /><br />void ra_myappl::scan()<br />{<br />&nbsp;for ( unsigned int i = 0;;i++) {<br />&nbsp; if ( i % 5 == 0) {<br />&nbsp;&nbsp; // Calculate x and y coordinates for a sine curve every fifth second<br />&nbsp;&nbsp; for ( int j = 0; j &lt; 100; j++) {<br />&nbsp;&nbsp;&nbsp; curve_ptr-&gt;XValue[j] = j;<br />&nbsp;&nbsp;&nbsp; curve_ptr-&gt;YValue[j] = 50 + 50 * sin( 2.0 * M_PI * (j + i) / 100);<br />&nbsp;&nbsp; }<br />&nbsp;&nbsp; // Indicate new curve to graph<br />&nbsp;&nbsp; curve_ptr-&gt;Update = 1;<br />&nbsp;}<br />&nbsp;else if ( i % 5 == 2)<br />&nbsp; curve_ptr-&gt;Update = 0;<br />&nbsp;sleep(1);<br />&nbsp;if ( i &gt; 360)<br />&nbsp; i = 0;<br />&nbsp;}<br />}<br /><br />void ra_myappl::close()<br />{<br />&nbsp;gdh_UnrefObjectInfo( dlid);<br />}<br /><br /><br />int main()<br />{<br />&nbsp;ra_myappl myappl;<br />&nbsp;<br />&nbsp;myappl.init();<br />&nbsp;myappl.scan(); <br />&nbsp;myappl.close();<br />}</p>
+
 
</td>
+
class ra_myappl {
</tr>
+
pwr_Class_XyCurve *curve_ptr;
</tbody>
+
pwr_tRefId dlid;
</table>
+
public:
<br />
+
ra_myappl() {}
<p><strong>On terminal</strong></p>
+
void init();
$ sdf cpp $ cd /usr/local/pwrp/cpp/src/appl/ $ g++ -g -c ra_myappl.cpp -o $pwrp_obj/ra_myappl.o -I$pwr_inc -DOS_LINUX=1 -DOS=linux -DHW_X86=1 -DHW=x86 $ g++ -g -o $pwrp_exe/ra_myappl $pwrp_obj/ra_myappl.o $pwr_obj/pwr_msg_rt.o -L$pwr_lib -lpwr_rt -lpwr_co -lpwr_msg_dummy -lrt
+
void scan();
<p><br /> <strong>On proview</strong></p>
+
void close();
<ul>
+
};
<li> Shift+Ctrl+B Node + B </li>
+
 
<li> Tools -&gt; Runtime Monitor </li>
+
void ra_myappl::init()
<li> Start Runtime </li>
+
{
<li> File -&gt; Start Runtime Navigator </li>
+
pwr_tStatus sts;
<li> right key Database </li>
+
pwr_tOName name = "plant-curve";
<li> right key plant </li>
+
<li> MB3 curve Object Graph </li>
+
// Connect to database
</ul>
+
sts = gdh_Init( "ra_myappl");
<p><br /> <strong>On terminal</strong></p>
+
if ( EVEN(sts)) exit(0);
$ ra_myappl</div>
+
 
 +
// Direct link to curve object
 +
sts = gdh_RefObjectInfo( name, (void **)&curve_ptr, &dlid, sizeof(*curve_ptr));
 +
if ( EVEN(sts)) exit(0);
 +
}
 +
 
 +
void ra_myappl::scan()
 +
{
 +
for ( unsigned int i = 0;;i++) {
 +
  if ( i % 5 == 0) {
 +
  // Calculate x and y coordinates for a sine curve every fifth second
 +
  for ( int j = 0; j < 100; j++) {
 +
    curve_ptr->XValue[j] = j;
 +
    curve_ptr->YValue[j] = 50 + 50 * sin( 2.0 * M_PI * (j + i) / 100);
 +
  }
 +
  // Indicate new curve to graph
 +
  curve_ptr->Update = 1;
 +
}
 +
else if ( i % 5 == 2)
 +
  curve_ptr->Update = 0;
 +
sleep(1);
 +
if ( i > 360)
 +
  i = 0;
 +
}
 +
}
 +
 
 +
void ra_myappl::close()
 +
{
 +
gdh_UnrefObjectInfo( dlid);
 +
}
 +
 
 +
 
 +
int main()
 +
{
 +
ra_myappl myappl;
 +
 +
myappl.init();
 +
myappl.scan();  
 +
myappl.close();
 +
}
 +
 
 +
</nowiki>
 +
 
 +
Create file /usr/local/pwrp/cpp/src/appl/ra_myappl.h (this file just needs to exist, it should be empty)
 +
 
 +
'''On the terminal'''
 +
 
 +
$ sdf cpp
 +
$ cd /usr/local/pwrp/cpp/src/appl/
 +
$ g++ -g -c ra_myappl.cpp -o $pwrp_obj/ra_myappl.o -I$pwr_inc -DOS_LINUX=1 -DOS=linux -DHW_X86=1 -DHW=x86 -DOS_POSIX
 +
$ g++ -g -o $pwrp_exe/ra_myappl $pwrp_obj/ra_myappl.o $pwr_obj/pwr_msg_rt.o -L$pwr_lib -lpwr_rt -lpwr_co -lpwr_msg_dummy -lrt -pthread
 +
 
 +
'''On Proview'''
 +
* Shift+Ctrl+B Node + B
 +
* Tools -> Runtime Monitor
 +
* Start Runtime
 +
* File -> Start Runtime Navigator
 +
* right arrow key Database
 +
* right arrow key plant
 +
* MB3 curve Object Graph
 +
 
 +
 
 +
'''On the terminal'''
 +
$ ra_myappl
 +
 
 +
'''Automatically Starting the Application When Proview Starts'''
 +
* Open the file /usr/local/pwrp/cpp/bld/common/load/ld_appl_***.txt
 +
* In the User applications section, add the line:
 +
  ra_myappl, ra_myappl, noload, run, ra_myappl, 12, nodebug, ""

Latest revision as of 07:57, 16 July 2014

These are the step by step instructions to create the C++ program from the Proview "Designer's Guide" Chapter 14 - Application Programming

Key: MB1 = Left Mouse Button, MB2 = Middle Mouse Button, MB3 = Right Mouse Button

Open Proview

  • Ctrl+E
  • MB1 $Hier
  • MB2 right panel
  • right arrow key on Oxx $Hier
  • ObjectName application
  • MB1 ProjectReg
  • MB2 in application $Hier
  • right arrow key on Oxx $ProjectReg
  • ObjectName cpp
  • Ctrl+E
  • Yes
  • Yes
  • MB3 cpp Open Project...
  • Next
  • Next
  • No
  • Next
  • Next
  • Next
  • Next
  • Yes

Configure RootVolume

  • Next
  • Next
  • Next
  • MB1 Plant -> $PlantHier
  • MB2 right panel
  • right arrow key on Oxx $PlantHier
  • ObjectName plant
  • MB1 AllClases -> pwrb -> XyCurve
  • MB2 in plant $PlantHier
  • right arrow key on Oxx XyCurve
  • ObjectName curve
  • Ctrl+E
  • Yes

/usr/local/pwrp/cpp/src/appl/ra_myappl.cpp

#include <math.h>
#include "pwr.h"
#include "pwr_baseclasses.hpp"
#include "rt_gdh.h"


class ra_myappl {
 pwr_Class_XyCurve *curve_ptr;
 pwr_tRefId dlid;
public:
 ra_myappl() {}
 void init();
 void scan();
 void close();
};

void ra_myappl::init()
{
 pwr_tStatus sts;
 pwr_tOName name = "plant-curve";
 
 // Connect to database
 sts = gdh_Init( "ra_myappl");
 if ( EVEN(sts)) exit(0);

 // Direct link to curve object
 sts = gdh_RefObjectInfo( name, (void **)&curve_ptr, &dlid, sizeof(*curve_ptr));
 if ( EVEN(sts)) exit(0);
}

void ra_myappl::scan()
{
 for ( unsigned int i = 0;;i++) {
  if ( i % 5 == 0) {
   // Calculate x and y coordinates for a sine curve every fifth second
   for ( int j = 0; j < 100; j++) {
    curve_ptr->XValue[j] = j;
    curve_ptr->YValue[j] = 50 + 50 * sin( 2.0 * M_PI * (j + i) / 100);
   }
   // Indicate new curve to graph
   curve_ptr->Update = 1;
 }
 else if ( i % 5 == 2)
  curve_ptr->Update = 0;
 sleep(1);
 if ( i > 360)
  i = 0;
 }
}

void ra_myappl::close()
{
 gdh_UnrefObjectInfo( dlid);
}


int main()
{
 ra_myappl myappl;
 
 myappl.init();
 myappl.scan(); 
 myappl.close();
}


Create file /usr/local/pwrp/cpp/src/appl/ra_myappl.h (this file just needs to exist, it should be empty)

On the terminal

$ sdf cpp
$ cd /usr/local/pwrp/cpp/src/appl/
$ g++ -g -c ra_myappl.cpp -o $pwrp_obj/ra_myappl.o -I$pwr_inc -DOS_LINUX=1 -DOS=linux -DHW_X86=1 -DHW=x86 -DOS_POSIX
$ g++ -g -o $pwrp_exe/ra_myappl $pwrp_obj/ra_myappl.o $pwr_obj/pwr_msg_rt.o -L$pwr_lib -lpwr_rt -lpwr_co -lpwr_msg_dummy -lrt -pthread

On Proview

  • Shift+Ctrl+B Node + B
  • Tools -> Runtime Monitor
  • Start Runtime
  • File -> Start Runtime Navigator
  • right arrow key Database
  • right arrow key plant
  • MB3 curve Object Graph


On the terminal

$ ra_myappl

Automatically Starting the Application When Proview Starts

  • Open the file /usr/local/pwrp/cpp/bld/common/load/ld_appl_***.txt
  • In the User applications section, add the line:
 ra_myappl, ra_myappl, noload, run, ra_myappl, 12, nodebug, ""
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox