Jump to content
OMRON Forums

User Buffer Size


daves

Recommended Posts

Is there any way to get the size of the user buffer in a c program?

 

I just realised my custom communications driver has no issue with something like the following when the buffer is 1MB:

 

unsigned char bData[1];
unsigned char *iMy = (unsigned char *) pushm;

memcpy(&iMy[30000000], bData, 1);

 

i.e. writing well past the end of ushm.

 

Not even a segmentation fault which normally happens when I do anything wrong. What critical stuff is this destroying?

 

I would like to trap this.

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

 

You can use the "size" and "free" commands to check how much maximum and how much available User Buffer memory there is, respectively, in bytes. Send either of these commands to PMAC's script parser using the GetResponse() function and then parse the response in C. Below are descriptions of "size", "free," and GetResponse() for your reference:

 

size

Function: Report total buffer memory size

 

Scope: Global

 

Syntax: size

 

The size command causes Power PMAC to report the total number of bytes of memory present, used or unused, in several user memory buffers in RAM. The related free command returns the number of still unused bytes of memory for each of these memory buffers. The buffer sizes are set by directives in the pp_proj.ini file of the IDE project manager.

 

Example

size // Query total buffer memory

 

Program Buffer = 16777216

User Buffer = 1048576

Table Buffer = 1048576

LookAhead Buffer = 16777216

SyncOps Buffer = 1048576

Symbols Buffer = 1048576

 

free

Function: Report buffer free memory

 

Scope: Global

 

Syntax: free

 

The free command causes Power PMAC to report the number of bytes of memory still available (unused) in several user memory buffers in RAM. The related size command returns the total number of bytes of memory, used or unused, for each of these memory buffers.

 

Example

free // Query free buffer memory

Program Buffer = 16646144

User Buffer = 1048576

Table Buffer = 1048576

LookAhead Buffer = 16777216

SyncOps Buffer = 917504

Symbols Buffer = 1048512

 

int GetResponse (char * pinstr, char * poutstr, size_t outlen, unsigned char EchoMode)

Performs a string send to with an expected return from the Pmac Command Processor

 

The input string must have PMAC compatible commands Note: Doesn't handle "gpascii" commands like "$$$" or "reboot"

 

Parameters:

*pinstr - ptr to input string

 

outlen - max length of output string

 

EchoMode - PMAC "echo" parameter which determines the format of the response

 

*poutstr - ptr to output string

 

Returns:

0 == OK, - == error number

Link to comment
Share on other sites

Thanks for the information. How would you recommend I parse the response safely (and future proof)? Is there a specification for the format of the response? Or can I assume each line will always be

 

"NAME [whitespace] = [whitespace] VALUE"

 

and look for NAME = "User Buffer"?

 

BTW where did your quote come from (it matches the actual response from 1.5.8.0)? The August 10, 2012 Software Reference manual and IDE Help (1.5.0.21) differ in response:

 

size // Query total buffer memory

Program Buffer = 16777216 // Power PMAC response

User Buffer = 1048576

Table Buffer = 1048576

Lookahead Buffer = 16777216

 

size // Query total buffer memory

 

Program Buffer = 16777216

User Buffer = 1048576

Table Buffer = 1048576

LookAhead Buffer = 16777216

SyncOps Buffer = 1048576

Symbols Buffer = 1048576

 

There are extra fields and the capitalisation of lookahead is different...

 

Thanks for the help,

Dave

Link to comment
Share on other sites

Hi,

 

One of our firmware engineers just informed me that there's a much easier way to check the User Buffer size. Just access the variable directly like this in C. Example:

 

pshm->UserBufSize

 

It's the allocated user buffer size in bytes.

 

#include    // Global Gp Shared memory pointer
#include "../../Include/pp_proj.h"

int main(void) 
{
InitLibrary();
pshm->P[1]=(double)pshm->UserBufSize; // Copy user buffer size [bytes] into P1
CloseLibrary();	
return 0;
}

 

You still need to keep track of how much space you've consumed, however, to make sure you don't exceed the boundary you defined. You can allocate more space by right-clicking your project in the Solution Explorer in the IDE, then go to Properties, and then choose a larger User Buffer size.

Link to comment
Share on other sites

That's great. Thank you!

 

I'm sorry I didn't find that myself I normally scan the dtlibs h files for the stuff I'm looking for but must have had a fail in my choice of search terms!

 

Please could I make a request that the RtGpShm.h documentation in the help is expanded. There is what looks like an auto-generated description of the structures but with nothing useful to a developer. The fields are not indexed into the search which contributed to me not finding this answer. Also, is any of the PowerPMACLanguageManual in the Software Reference or User Guide, I couldn't see it.

 

Finally, it seems vital to me that all fields should show up in the Intellisense (I think you are working on this for the next release but I would upvote the fix). For me (and maybe my system is broken) pshm-> only shows Coord[], EncTable[], Macro, Motor[], Plc[], Prog[]. There is much more to SHM...

 

Dave

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...