Jump to content

Unable to Access Shared Variable Programmatically on CompactRIO Real Time Target


PLeVasseur

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 comment

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 comment

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 comment

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 comment

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 comment

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 comment

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 comment

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.

×
×
  • Create New...

Important Information

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