LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Shared Variables from PC to RT

Solved!
Go to solution

Hello,

 

I am working with a myRIO project where data is communicated from a PC VI through Shared Variables to an RT Host VI which writes them for the FPGA Target. The PC Front Panel has a cluster for Settings and a cluster for Data, and each of these clusters are type defined clusters that include shared variables (which are also clusters) inside of them. These shared variables and these type defined clusters are referenced in the RT VI.

 

If I want the values on the PC VI to propagate through the shared variables to the RT Host VI, should I set the cluster on the PC front panel to have a Data Binding of "Shared Variable Engine: Write Only", or should I have the shared variable clusters inside of the type definitions as "Shared Variable Engine: Write Only"? Both the clusters and the shared variables initially had data binding settings of "Unbounded", but I am unsure if this is correct. Would "unbounded" be correct for this type of application?

 

On trying to test the initial settings of these VI's, I was able to have type defined boolean controls (not clusters) with data binding set to "Shared Variable Engine: Read/Write", and these communicated data to the RT. However, the type defined clusters that I previously mentioned did not communicate the information written to the front panel.

 

 

 

 

Picture of PC Front:

 

Settings_TypeDefinedCluster_FrontPanel.jpg

 

 

Picture of TypeDefined Settings cluster SharedVariable (from PC). This is the shared variable that is inside the type defined cluster:

 

Settings_SharedVariable_InsideTypeDefined.jpg

 

Picture of RT Block Diagram cluster that I'd like to read the value in the Shared Variable:

RT_TypeDefinedCluster_FilledWithSharedVar.jpg

 

Picture of RT Front that displays error since the RT read a 0 due to no values written (this produced a condition to divide by 0, hence an error):

RT_Front_ErrorSinceNothingRead.jpg

 

 

 

 

I am working on getting a zipfile to share here so that the code may be used directly, but I am still working on getting it set up.

 

- Best regards, 2001J

0 Kudos
Message 1 of 16
(2,385 Views)

Personally, I think Network Published Shared Variables are evil.  Instead, use TCP/IP or Network Streams to pass data between your PC and RT.  I personally prefer using the TCP/IP route using the STM library.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 16
(2,333 Views)

Hello crossruiz,

 

Thank you for your timely response. I appreciate the heads up about the TCP/IP route through the STM library, as I have not yet heard of that method of data communication.

 

However, do you know how I would be able to do this with the Network published shared variables? This project is for a laboratory, and I want the utilized software libraries to be immediately accessible by all lab members who are using LabVIEW software. Basically, I'd rather not complete this project through downloadable content.

 

- Best regards, 2001J

0 Kudos
Message 3 of 16
(2,325 Views)

I just stated that I like to use the STM library since it creates the message framework for you.  You can set up your own protocol.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 16
(2,322 Views)

It's fine, I just saw that the "Simple Messaging (STM) Reference Library" requires a download, and I would prefer to refrain from downloadable content for this project. But may I ask why you believe that network published shared variables are evil?

 

- Thank you, 2001J

 

0 Kudos
Message 5 of 16
(2,313 Views)

Hi J,

 


@2001J wrote:

But may I ask why you believe that network published shared variables are evil?


Because they always provide problems with firewalls. You need to configure access to them on each client as well as on the host.

Because they need quite a lot of resources, which is a huge problem when hosted on cRIO targets. (You need to install one more software component onto the target, and they require a lot of memory. On an old cRIO907x they took ~20MB of the 64MB available RAM…)

 

TCP or UDP comes "mostly" for free as they are supported even with the base software installation.

You only need to implement some message handling - or install the STM library to get that for free.

 


@2001J wrote:

I would prefer to refrain from downloadable content for this project.


Why do you?

When you are one of a team of programmers you should use a SCC system anyway, and it's quite easy to include additional downloads into the SCC repository so all participants get access to those functions…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 16
(2,308 Views)

About a decade ago, I tried using Shared Variables.  I found them "problematic".  For doing really simple things (like transferring one or two elements, once or twice), they "often" worked, but for any serious transfer of data from Machine A to Machine B, they were unreliable, sometimes working, sometimes failing.

 

Around LabVIEW 2011, I started to use Network Streams.  Turns out there was a strange bug that was fixed by the time NI Week rolled around in August -- I managed to cause LabVIEW to crash (the famous "We apologize for the inconvenience ..." error) when editing one of my Network Streams sub-VIs, literally moving a wire.  Managed to work around this (I think I printed the VI, deleted it, then re-created it from my printout), but have been using Network Streams ever since when I needed to communicate within a LabVIEW RT framework (I'm working on one such project now).

 

I don't consider Shared Variables "evil".  I do consider them unreliable and unsuitable for serious work, at least in my experience.

 

Bob Schor

Message 7 of 16
(2,307 Views)

@2001J wrote:

But may I ask why you believe that network published shared variables are evil?


To add to the list:

1.  They are SLOW.  Just try writing to one and immediately read (you will get the old value).  The system has to wait for a buffer to fill up or a timeout (I think in the 100ms range) before the updated values are sent to the server.  Then the clients will have to get the update from the server.  So EXTREMELY slow.

 

2. No security at all.  Anybody on the network can update the value.  This can cause disastrous situations.

 

3. A common of both of the above: very weird race conditions.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 16
(2,300 Views)

Thank you for the information GerdW, Bob Schor, and, of course, crossruiz.

 

As for using this communication system, I am a bit intimidated by it at the moment, so I was wondering if I could receive some assistance with implementing it.

 

If that is alright, I am programming a single 1900-myRIO to communicate 1 cluster of settings from the PC to the RT host, 1 cluster of data from the RT host to the PC, and 3 boolean variables from the PC to the RT host. Both clusters include numeric data. When I say host, I am referring to the host of an FPGA Target, but I am not reading/writing with it through Shared Variables nor STM, it communicates through "Read/Write Control" at the moment.

 

From reading some documentation (link: http://www.ni.com/tutorial/53683/en/), it seems that I must first create a connection between the client and the target, then write an array of Strings describing the data to the "STM Write Meta Data"s "Meta Data" connection. Afterwards, I must write the respective data's description to the "STM Write Message"s "Connection Info", then write the actual data (converted to String) to the respective "STM Write Message"s "Data" connection. Considering that I am writing numeric data, then these data must all be strings. But when it is eventually read, I must have a Case Structure to convert that specific data instance (as specified earlier by its respective string index that was written to the "STM Write Meta Data"s "Meta Data" connection) to its correct data type. Does this logic seem alright?

 

Assuming that this is in the PC VI, then I would have part of it doing the writing and part of it doing the reading, as I need it to both write settings and read data. Does this setup seem accurate? I am referring to the following picture for the writing:

2001J_0-1598296652132.png

 

Later today, I can post a zipfile of a project that I would like to implement this communication. It currently has shared variables. If you would like to view this code, use the "RT Main.vi" Host, the "LIA_myRIO-1 Control Panel.vi" PC, and the "FPGA_LIA_2ChPhase__Question.vi".

 

 

- Thank you, 2001J

 

0 Kudos
Message 9 of 16
(2,294 Views)

As stated previously, here is a zipfile for the project that I would like to implement this STM communication into.

 

However, I have run into an issue with my implementation. If someone is willing to help, then I'd be grateful. Also, if someone would be willing to look over my attempt to implement STM, I would also be grateful. My PC VI seems to run alright, but my RT Target encounters an error

 

1. I encounter Error 63 "TCP Open Connection in RT_STM Test.vi" when I have the RT Target IP Address for the "TCP Open Connection VI" blank or "localHost". I had it blank because of the following documentation: "if you do not specify an address, LabVIEW establishes a connection to the local computer." And I tried "localHost" because it had been the default value.

 

I am unsure of where the issues in my code are, but I feel that they are with connecting my PC with my myRIO so that they can communicate. If you're curious the PC VI in the zip is "STM__LIA-myRIO_Control Panel.vi" while the RT Host is "RT_STM Test.vi".

 

- Best regards, Justin Burzachiello

0 Kudos
Message 10 of 16
(2,268 Views)