Jump to content

Unable to Access Shared Variable Programmatically on CompactRIO Real Time Target


Go to solution Solved by Neil Pate,

Recommended Posts

I would like to use programmatic access to manipulate shared variables on a computer and an NI cRIO 9033, but cannot get programmatic access to shared variables on the cRIO.
I have boiled the situation down to a simple example to try to explain what I am seeing. The shared variables are hosted on the cRIO. I am using the same VI to perform the accesses on the computer and the cRIO. On the computer, access to the shared variable via a shared variable node and programmatic access both work. On the cRIO, access to the shared variable via a shared variable node is functional, but programmatic access to the shared variable does not work.
The error code received when trying to to a Read Variable or Open Variable Connection on the cRIO to the shared variable is -1950678943. The error text reads "Timed out while attempting to open a connection to the variable."
I'm quickly becoming confused as to why the cRIO should have trouble reading a shared variable programmatically that is hosted on itself. The web searches I have done haven't turned up such a simple scenario causing this error, so I'm wondering if I've stumbled into a beginner mistake. I have attached the source code to this post, so if someone could please take a look that would really help!
Block Diagram:
post-53795-0-96854300-1437659630.jpg
Result of running on computer (programmatic and shared variable node access both work):
post-53795-0-92563900-1437659631.jpg
Result of running on NI cRIO 9033 (programmatic shared variable access does not work, shared variable node access does work):
post-53795-0-39160200-1437659632.jpg

Test Access to Shared Variable from cRIO.zip

Link to post
Share on other sites

It may be down to the fact that the hostname portion of your variable URL (i.e. RT CompactRIO Target) does not make sense when running the code in the context of the cRIO.

 

Try something along the lines of ni.var.psp://localhost/ etc etc

 

I am not a big fan of shared variables, and try and avoid them whenever possible.

Edited by Neil Pate
Link to post
Share on other sites

Thanks for the suggestion Neil. I tried doing this previously by first turning a shared variable node into the Target Relative mode, then replacing with programmatic access, which resulted in a URL like you mentioned (ni.var.psp://localhost/...). I still received the same error code (-1950678943).

 

I am open to other ideas as to how to accomplish sharing data between the computer and the cRIO. Do you have some tips you could share? It seemed that shared variables would be an easy way to do that, but I can't seem to get programmatic access to them to work from the cRIO (though access via shared variable nodes works fine).

Link to post
Share on other sites
  • Solution

Sorry, sounds like you know more than I do about shared variables. Can you see the variables using the Distributed System Manager?

 

Have you taken a look at Network Streams? I find them much easier to setup and debug when things don't work. Think of them as TCP/IP with all the re-connection and other management stuff taken care of. 

Link to post
Share on other sites

On the computer, access to the shared variable via a shared variable node and programmatic access both work. On the cRIO, access to the shared variable via a shared variable node is functional, but programmatic access to the shared variable does not work.

 

I wonder if it's a race condition, since you are accessing the same variable in two places in your diagram. I'm also wondering if something got corrupted.

  1. What happens if you delete the SV node from your block diagram?
  2. What happens if you try to write to the variable without opening a connection?
  3. Right-click the SV node and select "Replace with Programmatic Access". Does this one work?
  4. What happens if you undeploy everything from your cRIO, and then deploy the variables again?
  5. What happens if you undeploy everything from your cRIO, and then create a new project with new variables?
  6. (Drastic measures) What happens if you reformat your cRIO, install your software from scratch, and try again?
Link to post
Share on other sites

I appreciate the suggestions, JKSH.

Answering your questions in order:

  1. What happens if you delete the SV node from your block diagram?
    • Same error code (-1950678943).
  2. What happens if you try to write to the variable without opening a connection?
    • Same error code (-1950678943).
  3. Right-click the SV node and select "Replace with Programmatic Access". Does this one work?
    • I tried this previously, but it didn't work out. Same error code (-1950678943).
  4. What happens if you undeploy everything from your cRIO, and then deploy the variables again?
    • Tried this previously, too. I tried undeploying and then deploying again, but same error code.
  5. What happens if you undeploy everything from your cRIO, and then create a new project with new variables?
    • Nope, same error code. Verified that all shared variables were not deployed prior to creating the new project by using the Distributed Systems Manager.
  6. (Drastic measures) What happens if you reformat your cRIO, install your software from scratch, and try again?
    • Just tried this too, unfortunately no success.

The situation remains as follows

Computer:

Shared Variable Node - Success

Programmatic Access - Success

cRIO:

Shared Variable Node - Success

Programmatic Access - Failure (Error Code -1950678943, Error message: "Timed out while attempting to open a connection to the variable.")

Link to post
Share on other sites

Sorry, sounds like you know more than I do about shared variables. Can you see the variables using the Distributed System Manager?

 

Have you taken a look at Network Streams? I find them much easier to setup and debug when things don't work. Think of them as TCP/IP with all the re-connection and other management stuff taken care of. 

 

Well, after working at it for a while longer, in the end I couldn't get programmatic access to shared variables to work on the CompactRIO.

I spent some time reworking the code to function with Network Streams and I'm pretty happy with the result (since it works!).

Thanks Neil.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By torekp
      DLL functions or shared variables?  Or something else?
      I have a Labview 2014-64 executable (or I can build a DLL) that runs one piece of equipment, the X-ray.  The other engineer has a large CVI Labwindows 2015 + MS Visual Studio 2012 (C++) executable that runs everything else.  I want the Labview code to be a slave of the CVI code, accepting commands to turn X-ray On or Off, reporting failures, and the like.  Translating the X-ray code into C++ would be possible in principle, but not fun.
      Shared variables look easy, but I'm kinda scared of them.  I would define all the shared variables in my LV code, since I'm more familiar with LV, then use them in both.  There's a thread in here called "Shared Variable Woes" so maybe I should be scared.  In the alternative, I tried building a proof-of-concept DLL in Labview, and calling its functions in CVI/C++, and it works, but it's kinda clunky.  (I'm attaching it below in case you want to play, or advise.)
      Your advice would be appreciated.
      XrayDLL.zip
    • By grjgrj
      Hello. I need change some code for SbRIO-9626 with LabVIEW 2018. I have code from LabVIEW 2015. Right now I have only LabVIEW 2018. And I worked with it for SbRIO-9627.
      LabVIEW FPGA, LabVIEW Real-Time, NICRIO1800 driver istalled.
      And I install Xilinx ISE 11.5 Compilation Tool too. 
      When I start compilation FPGA VI I got error about problem with compilation too (see attachment picture).
      Could you tell me how I can solve this problem? 
      It is very important. 

    • By Tim_S
      Thought I'd pass this along and see if anyone can reproduce with different versions of LabVIEW. Appreciate it if anyone has seen this and has a fix.
      I'm using shared variables to communicate between applications (1:N). I'd been seeing some memory creep that was inconsistent and somewhat bizarre. Eventually managed to track it down to that I'm programmatically opening a connection to a shared variable in one loop, then reading the value in a different loop (the different loops have to do with reconnecting on connection loss and startup). There is a functional global used to pass the variable to the second loop. The Read Variable primitive deallocates all but 4 bytes of memory for the previous loop handle and then allocates memory for a new handle on each iteration of the while loop, hence creating a leak. This behavior does not occur if there is only one loop where there is an open, while loop with a read, and a close.
      Main.vi demonstrates the issue. Main 2.vi is more like the NI example.
      I've got service request #7728859 with NI going, but I think I got the guy's first day.
      LabVIEW 2015 SP1 32-bit on Win7 64-bit. Shared Variables memory leak.zip
    • By ensegre
      More out of curiosity than of hope: has anybody any idea why SVs are almost unsupported on linux? By almost I mean that controls and indicators cannot be bound to shared variables, and that shared variables cannot be programmatically created and looked up. I know that SVs hosted on windows can be accessed in linux LV using datasocket nodes, but that is all it gets. And it has been said that datasocket is despicable. What are the missing pieces that make SV windows-only?
      I didn't find much in the canonical places, so I posted a dumb zero-kudos attracting idea.
    • By Alexander Kocian
      Hello
      Currently, I stream and proecess audio (for medical purposes) on my PC (i7-4790T with 8 cores) using LABVIEW 2013. To improve performance, the 8 cores could be shared between MS Windows and the real-time operating system RTX by IntervalZero.
      Please, how can I tell LABVIEW to use the (deterministic) RTX cores instead of the (stochastic) MS Windows cores, to stream audio?  
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.