Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accessing user shared memory from C
#1
Question: How do I access Sys.Fdata memory from a bgcplc? What I specifically need to do is to read in data from an array in Sys.fdata memory. I don't want to declare pointers to every block in the array, just to increment a pointer.

Answer:
Here is how to do it: (be careful if you decide to use double, since it is 64bit and it will use up the user shared memory in batches of 2 32bit locations at a time)

Code:
#include <RtGpShm.h>
#include <stdio.h>
#include <dlfcn.h>
void user_plcc()

{
      float *myfloat;
      myfloat = (float*)pushm; // setting the address from void pointer pushm casted as float pointer
      *myfloat=5.5; // equivalent of sys.fdata[0] – you can also write it as myfloat[0]=5.5;
      myfloat[3]=3.141592;    // equivalent of sys.fdata[3]
}


Sina Sattari
Hardware Engineering Manager
Delta Tau Data Systems, Inc.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)