NI Linux Real-Time Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading Total Physical Memory with NI System Configuration API

Solved!
Go to solution

Hi All,

I am using NI System Configuration C API to read my RT Target's total physical memory. I did not find any good example for this, after looking at nisyscfg.h, I came up with the following code:

main(){

     NISysCfgStatus status;

     NISysCfgSessionHandle session;

     double total_phys_mem;

     //Declaring session

     if (NISysCfg_Succeeded(status = NISysCfgInitializeSession("localhost",NULL,NULL,NISysCfgLocaleDefault,NISysCfgBoolTrue,10000,NULL,&session))){

     //Reading Total Physical Memory

     if (NISyscfg_Succeeded(status = NISysCfgGetSystemProperty(session,NISysCfgSystemPropertyMemoryPhysTotal,&total_phys_mem))){

          printf("\nTotal Physical Memory: %f", total_phys_mem);

          }

     }

}

When I try to run this, I get a "Segmentation fault" error. I have used the same session to create filter, set filter's property, get resourceHandle, read serial number, CPU Load etc. without any problem, but reading total physical memory is becoming difficult. May be this code is wrong, so can anyone please show me the right way to do this with this C API?

Thanks.

Message 1 of 7
(5,233 Views)

I want to test your code. Which target are you using and what version of NI System Configuration do you have on your target?

Tim A.
Message 2 of 7
(4,201 Views)

My target is sbRIO-9651, and version of NI System Configuration is 14.5.0.

0 Kudos
Message 3 of 7
(4,201 Views)

Thanks for the info, rkjulfiker.

The only peculiar thing I noticed in your code was a spelling issue. Your second if statement has a "NISyscfg_Succeeded" when I believe it should be "NISysCfg_Succeeded".

After I corrected this I was able to compile (cross compiling from Eclipse CDT) and execute it on my target 9637 with the 15.0 software set. Testing on a different arm target with 14.5 next to make sure that works as well.

Are you compiling on target or from another host machine?

Tim A.
Message 4 of 7
(4,201 Views)

I typed the code here, not copied, I mistyped that "NISyscfg_Succeeded". Sorry if that caused you any trouble. My original code has correct spelling though, and I also used eclipse to compile. It builds successfully, but I still get the same error when try to run it.

0 Kudos
Message 5 of 7
(4,201 Views)
Solution
Accepted by rkjulfiker

Found the error, it was in the function list, there was a typo in the function name, so the function could not be found on the runtime. I appreciate the help.

Message 6 of 7
(4,201 Views)

I am using NI System Configuration C API to read my RT Target's total physical memory. I did not find any good example for this, after looking at nisyscfg.h, I came up with the following code:

As on any Linux machine, you can read that data from /proc/meminfo.

Linux Embedded / Kernel Hacker / BSP / Driver development / Systems engineering
0 Kudos
Message 7 of 7
(3,262 Views)