From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP - LabVIEW (Client) to Arduino (Server)

Solved!
Go to solution

Hello LabVIEW community.  I had considered posting this in the Arduino Community, but I figured LabVIEW community more likely to know the answer.  Course...copy paste really not that difficult.  Anyways...
I am wanting to create a VI that will allow me to stream data from my Arduino over the network.  My thoughts: Have Arduino be a TCP server and have LabVIEW be the client.  I've got Arduino Server code.  I went ahead and tried to use the TCP Data Client (and various other LabVIEW TCP examples) in an attempt to connect to the Arduino just to prove that it was capable b4 moving on with this project.  No luck.  IP is correct as well as port.  So I am clearly doing something wrong.  Questions: Is this possible?  Is there a better (or just a different in general) way to do exactly what it is I am wanting to do?  Is there any example out there (I've looked vigorously) that could get me started down the path of debugging?  Why is the sky blue?  Any help would be greatly appreciated.

0 Kudos
Message 1 of 16
(10,196 Views)

Perhaps the real question here is...How does one send data from Arduino to LabVIEW over a network?

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

Anyone?  It would seem like this question would be as simple as maybe describing how LabVIEW communicates with cRIO.  In the famous words of Jar Jar Binks, "Any help here would be hot!"  I'm serious, ANY HELP!

0 Kudos
Message 3 of 16
(10,155 Views)

I don't have any experience with the Arduino, but I have a lot of experience with TCP communications in LabVIEW. A LabVIEW example such as the simple data client won't just work, even with the right IP address and port number; both sides have to agree on how they're going to communicate. Do you have any further information about the TCP server on the Arduino end? Once a connection is established, do you need to send it commands to receive data, or does it continuously send data over the connection? Within LabVIEW, if you open a connection to the Arduino's IP address and port, can you establish a connection (TCP open succeeds with no errors)?

0 Kudos
Message 4 of 16
(10,134 Views)

Well, with LabVIEW I use highlight execution to see if LabVIEW ever makes it past the TCP Open Connection VI.  It does, it errors out at TCP Read and the error is a timeout.  But...what I don't understand is that on my Arduino side of things, it is waiting for a client.  Nothing will execute until a client has been determined.  At no point does my arduino make any indication that there is a client.  Now, I'm wondering then if this has something to do with the TCP Open Connection.  Does that send a couple bytes of data communicating that it has connected and wishes to receive data?  Or does it just listen to that IP and do I need to just simply send data and LabVIEW will just listen for it?

0 Kudos
Message 5 of 16
(10,113 Views)

You can think of TCP Open as being a bit like making a phone call, with caller ID. When the server side "picks up the phone" (accepts the connection) it knows the IP address of the remote side. Both sides know that the communication channel is open, and then it's up to your application and the server to start talking to each other. It sounds like you're successfully placing the call, but then neither end says anything (which is why you get a timeout from the TCP Read). I don't know anything about the Arduino server. Maybe it's waiting for a command from your LabVIEW application before it sends anything in response.

0 Kudos
Message 6 of 16
(10,096 Views)

Yeah, that's exactly what was going on.  I went ahead and sent a single byte of data from LabVIEW and for whatever reason, that's what the Arduino is looking for.  I guess it's some sort of handshake.  If an Arduino person is ever needing help w/ this, send me an email or something.

0 Kudos
Message 7 of 16
(10,082 Views)

Hey, l encounter a simliar problem as you. Can you explain or even better show me the block diagram and programming of your Arduino. Thanks you!

0 Kudos
Message 8 of 16
(9,985 Views)
Solution
Accepted by topic author DailyDose

I guess what it comes down to (and this is my limited knowledge of networking and TCP) is that you are not streaming data from the Arduino.  You are basically taking momentary shots.  So I have also attached my TCP code on the Arduino.  Note: The TCP code needs to be independent of the rest of your code.  As you will notice, it's an If Statement.  The code available in the examples uses a While.  I have this code set up to do just 10ms pings for data.  You will have to do some editing I am sure.  I chopped a lot of my initial code out of it because it wouldn't have made any sense.  But this should really help.

 

PS: I had to put the code in a .txt file because this forum doesn't know what an .ino is.

Download All
0 Kudos
Message 9 of 16
(9,944 Views)

Without seeing the rest of your code I can't be completely sure of what's happening here, but... why do you reconnect to the Arduino on every event structure timeout? You'll land up with a lot of connections that never close, which could eventually cause you networking problems. You should close every connection you open, not just the last one (which is what will happen now since the TCP Close is outside the loop), and it would be better to reuse the same connection repeatedly rather than opening a new one over and over again.

0 Kudos
Message 10 of 16
(9,937 Views)