LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

cRIO TCP real-time application not working

So I am trying to follow this example to create TCP communications between a Python and LabVIEW. The difference is I am trying to do it on the cRIO as a real-time application that communicates via shared variables. The Python script runs without errors so I'm assuming the mistake is in my LabVIEW code, more specifically my RT.vi is where I think my problem is. The event structure probably has something wrong with it, I've messed around in a couple of different ways, but I couldn't get it to work with the shared variables. I attached the LabVIEW code for you all to take a look at. 

 

My configuration:

- Using the cRIO IPv4 Ethernet Adapter eth0 (Primary) for the IP address 

- Using the port number that is assigned to TCP/IP under "VI Server" in the cRIO properties

 

It's just meant to be a simple example of how to use TCP in RT on the cRIO, but I am having a ton of trouble so if someone could fix the code or do it in a better/simplified way I would really appreciate it!

Download All
0 Kudos
Message 1 of 8
(2,753 Views)

It seems to me like you have your Host and RT VIs swapped:  the Host should have the Event Structure instead of polling..

 

1. Unless you enabled the embedded display on the cRIO (I think the 9035 has that), the Event Structure does not work at all on an RT system since there is no panel to get events from.

2. I recommend against using Shared Variables in nearly any capacity.  They are slow and can have some really weird race conditions.  Use TCP or Network Streams to send messages to your RT system telling it to do something.


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 8
(2,712 Views)

I am using the cRIO 9035

@crossrulz wrote:

 I recommend against using Shared Variables in nearly any capacity.  They are slow and can have some really weird race conditions.  Use TCP or Network Streams to send messages to your RT system telling it to do something.

I'm only familiar with the shared variables and the TCP/Network Stream examples that come with the cRIO aren't making sense to me.

 

Is there any way you can modify the program I posted so that it uses TCP or Network Streams?

 

My end goal here is to be able to send JSON file to LabVIEW from my Python script. Here is the Python code that I will be using. I eventually just want to be able to write # values from Python into JSON and then extract them from the JSON file in LabVIEW to send through a FPGA VI. So the velocity mentioned in this Python script corresponds with an A/O voltage on the cRIO (i.e. a flow controller).

 

Then I want the data read in LabVIEW, from let's a thermocouple or pressure gauge, to be sent back to my Python script for further analysis.

0 Kudos
Message 3 of 8
(2,699 Views)

Especially as a first step, I would first try and get your Python code and your LabVIEW code talking on your development machine, before trying to deploy the code to an RT target. Do you understand the standard TCP examples? 

0 Kudos
Message 4 of 8
(2,696 Views)

@atokad wrote: I'm only familiar with the shared variables and the TCP/Network Stream examples that come with the cRIO aren't making sense to me.

Ok, first get the TCP to work on your own PC.  I am a big fan of the STM library.  There are a couple of examples included in it that are pretty straight forward that you can learn how to do it.


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 5 of 8
(2,691 Views)

To both crossrulz and paul.ross I am able to use the TCP/IP code on my computer, but I can't seem to get it working on the cRIO even when I do not make it a RT target.

 

@paul.ross I am not understanding the standard TCP examples. I have a good idea of how it works first link I provided, but I don't understand how to get it working on the cRIO.

0 Kudos
Message 6 of 8
(2,683 Views)

How do you want data to flow through your programs? From Python, to the Host Application, then to the cRIO? Or directly from Python to cRIO? And your host application is just a UI to communicate with the cRIO? 

 

I am not sure where you have more experience, but just to simplify the problem, I would reduce the number of variables. Get LabVIEW communicating with Python on your PC. Sounds like you have that done. Now, get your cRIO application communicating with your host LabVIEW application over TCP, then you can easily set it up to talk to Python. It looks like Python will be your server, so setup your host application to be a server, and then you can just swap host for python.

 

Is there something specific in the standard TCP examples you dont understand? I am referring to the 'Simple TCP' and 'TCP Multiple Connections' in the example finder. (Networking>TCP & UDP).

 

A couple of notes on your RT code. You have the address setup as all 0s.. that cant be right? You need to give it the address of your host application you want to talk to. In this case, it will be the address of your development machine. Also, in the 'Play' value change case. This will never execute by changing the value from the host application. The play button network variable is only read if that case executes. The case only executes when the value changes.. Which you are trying to change by reading the network variable. I would probably get rid of the event structure all together. 

0 Kudos
Message 7 of 8
(2,665 Views)

@paul.r wrote:

How do you want data to flow through your programs? From Python, to the Host Application, then to the cRIO? Or directly from Python to cRIO? And your host application is just a UI to communicate with the cRIO? 

 


I want it to go directly from Python to the cRIO, having the host act as a UI

0 Kudos
Message 8 of 8
(2,658 Views)