Jump to content
OMRON Forums

share data between cplc


FEIR

Recommended Posts

Hello,

 

I'm trying to share data between to different cplcs without storing the data in ScriptPLC variables. Is there a possibility to do that?

 

Basically i'm filling an Array with data in a bgcplc1 for example.

Now i want to use the filled array in a different bgcplc2.

 

Hope you can help

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

You can use the user shared memory buffer, a buffer for general purpose, whose memory is shared between C and Script programs, and whose size you can adjust.

 

In your C program, first declare pointer variables to pushm. This is the base of the user shared memory. You should always use an index greater than 0 in the user shared memory because index 0 is used by PMAC for various things. You can add an integer to pushm to move over to that index, and the ++ operator works as well if you want to just go to the next index in the user shared memory array (or -- to go in reverse).

 

Examples:

 

int *MyUshmIntVar;
double *MyUshmDarray;
MyUshmIntVar = (int *) pushm + 9;  // point to same address as Sys.Idata[9], integer format user shared memory
*MyUshmIntVar=1234; // Write 1234 to Sys.Idata[9]
MyUshmIntVar--; // Move to previous element (8) in ushm buffer
MyUshmDarray = (double *) pushm + 8192;       // point to same address as Sys.Ddata[8192], double format user shared memory
*MyUshmDarray =43.05; // Write 43.05 to Sys.Ddata[8192]
MyUshmDarray++; // Move to next element (8193) in ushm buffer 

 

You can access this buffer from any CPLC if you put these same pointer declarations in each CPLC you want to access the shared memory buffer (e.g. MyUshmDarray = (double *) pushm + 8192 will look at Sys.Ddata[8192] regardless of which CPLC you put this into).

 

You can adjust the amount of shared memory allocated by clicking on your Solution in the Solution Explorer in the IDE, then right clicking and going to Properties. In the Properties Window, you can adjust “User Buffer” in units of Megabytes to change the size of your user buffer (see screenshot below):

 

ushm.png.65e1a8f0b5f2c8a10559d3d3f6a3312a.png

 

You can read the attached slides for more information also.

12-Power PMAC Shared Memory 2011-05.ppt

Link to comment
Share on other sites

Hello,

 

I'm trying to share data between to different cplcs without storing the data in ScriptPLC variables. Is there a possibility to do that?

 

Basically i'm filling an Array with data in a bgcplc1 for example.

Now i want to use the filled array in a different bgcplc2.

 

Hope you can help

 

You can also use unused P vars. I do this for a non volatile memory interface I wrote. Its a bit safer than shared memory in that there are no pointers involved (so to speak). In other words, P variables are a general purpose double floating point array that you can tap into. Just don't use the upper region set up in your IDE for auto assigned vars, which defaults to P8192.

 

example to fill P0-P999 with constant:

#define MY_CONST 1234.56789
int i;
for(i=0; i++, i<1000)
{
   pshm->P[i]=MY_CONST;
}

If you want to get tricky you can get a pointer to any P var as well, just do this:

 

&pshm->P[0]

 

Frankly, working with array indeces is ALOT safer!

 

YMMV...

 

KEJR

 

 

 

 

Link to comment
Share on other sites

Frankly, working with array indeces is ALOT safer!

 

Note that using shared memory is a great deal faster than using P vars.

 

As an aside - if you are using the latest version of the IDE you should be able to delare your variable in script:

 

global MyPvar1

 

and then when the project is built it includes the definition of MyPvar1 to the correct number so:

 

pshm->P[MyPvar1]

 

points to this pvar.

 

 

Link to comment
Share on other sites

  • 2 years later...

In your C program, first declare pointer variables to pushm. This is the base of the user shared memory. You should always use an index greater than 0 in the user shared memory because index 0 is used by PMAC for various things.

 

I'm astonished to learn that pushm + 0 is used by the PMAC itself. Is this documented somewhere? I looked at the Software Reference Manual and the description of Sys.Idata indicates i can be "in the range 0 to ...", with no prohibition about using 0.

Link to comment
Share on other sites

Note that using shared memory is a great deal faster than using P vars.

 

How is that possible? From C, the P-vars are just an array of doubles within "struct SHM". Is the difference between "pushm + index" and "pshm->P[index]" significant in your application?

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...