Another way:
In your "global definitions.pmh" you have your M-ptr definition
ptr MyPtrVar1->*;
In your "C" program you would have something like
#include
#include // Global Rt/Gp Shared memory pointers
//-------------------------------------------------------------
// The following is a projpp created file from the User defines
//-------------------------------------------------------------
#include "../../Include/pp_proj.h"
int main(void)
{
double MyMvar;
InitLibrary();
//Put your code here
MyMvar = GetPtrVar(MyPtrVar1);
CloseLibrary();
return 0;
}
[quote='CharlesP' pid='826' dateline='1289435593']
[quote='Amir' pid='824' dateline='1289428140']
How do you access an M variable from a C PLC (user_plcc())?
[/quote]
One way is to use the function GetPmacVar, whose prototype is as such:
int GetPmacVar (char * pinstr, double * pdata)
For example, to read M400, one could use this code snippet inside the CPLC:
[code]
int ErrorCode;
double M_Var_Result;
ErrorCode = GetPmacVar("M400",&M_Var_Result);
if(ErrorCode != 0)
{
printf("\nThere was an error in reading the M-Variable.\n");
}
[/code]
After running that, the value in M400 should be stored in your C variable "M_Var_Result". Note that in this example, I used a string literal to input "M400" into the GetPmacVar function. One could also use the sprintf function to dynamically create the string to pass into GetPmacVar if needed.
[/quote]