LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I transfer a file through a TCP connection?

Hi,
I want to transfer pictures and text or spreadsheet files using a TCP connection. The NI website has a TCP file transfer example, but it is for labview version 7.1, and I am using version 8.5, so I get an error saying the files (client and server) are too old to work with 8.5. If anyone knows how to get around this, or can just explain directly how to do file transfer, I would really appreciate it. Thanks!
0 Kudos
Message 1 of 38
(8,592 Views)
What that example does is sets up a good method for sending information via TCP.  Before sending any information, you always want to send the size of the information first (and the size will always be 4 bytes in size, as an I32).  So if I'm sending a .txt file that is 1024 bytes, first I would send 1024 as an I32, then I would send the actual information in the .txt file (typecast to a string, of course).
 
On the receiving end, your system knows that any TCP communication will always have an I32 size descriptor first, and that the size descriptor will always be 4 bytes.  So your receiver knows to read 4 bytes and typecast it to I32, which then becomes the size of the next file to read.  The next file is read and typecast to the appropriate datatype and presto, you have transferred a file.
0 Kudos
Message 2 of 38
(8,585 Views)
Where is this example that you're referring to? LabVIEW 8.5 is capable of opening VIs written in LabVIEW 7.1. Are you sure it's not LabVIEW 5.1?

There are also data transfer examples that ship with LabVIEW. Open the Example Finder (Help -> Find Examples), and search for "TCP/IP". The "Simple Data Client" and "Simple Data Server" is one such example.
0 Kudos
Message 3 of 38
(8,581 Views)
If you turn on the "Include ni.com examples" you can find a TCP File send/recieve example under Networking > TCP & UDP. They are both stored in something like "C:\Program Files\National Instruments\LabVIEW 8.5\examples\Downloads\9E2FC850FA96D010VGNVCM200000A90AA482RCRD\TCP File Client.vi"
0 Kudos
Message 4 of 38
(8,580 Views)
Thanks for your help everybody!
I thought 7.1 examples should work w/ 8.5, but here is what happens:
I go to the example finder and search for "TCP". I also check the box that says "include examples from ni.com"
I get a list of all the TCP stuff, and I clicked on the one that said "sending files through TCP/IP with labview".
Then I get this message:
    "This web example from ni.com could not be opened.

Downloads/9E2FC850FA96D010VGNVCM200000A90AA482RCRD/TCP File Server.vi"
So then I went to NI.com to download it, and when I do that I save it on my computer, unzip it etc. Then when I click on the icon for the vi (I saved them on my desktop), I get this message:
"LabVIEW: VI version is too early to convert to the current labVIEW version.

An error occurred loading VI 'TCP File Server.vi'. LabVIEW load error code 10: VI version (7.1.1) is too old to convert to the current LabVIEW version (8.5)."

umm....where do I go from here?
Thanks!
0 Kudos
Message 5 of 38
(8,570 Views)
Thanks for the help! I have a couple more questions about what you said. You said I would need to typecast the information in the text file to a string, and I was wondering is there a function for that or how would I go about doing that exactly? Also, how do I deal with sending information in a picture file, or a spreadsheet? Thanks again 🙂
0 Kudos
Message 6 of 38
(8,566 Views)
Hi ekarl,
use the type cast vi. See the attached picture.
Mike
0 Kudos
Message 7 of 38
(8,560 Views)
Thanks so much, that helps a lot!
0 Kudos
Message 8 of 38
(8,555 Views)
That's strange about the example. I can open it just fine in 8.2. Attached is the file in 8.2, so you should be able to open it.

Regarding the typecast: If you're transferring a file the file type is irrelevant. You're transferring bytes. The only typecast that is necessary is for when you have to presend the number of bytes that are about to be transferred/received. When you read the file using the binary file read functions you get exactly what you need to provide to the TCP Read. Take a look at the resaved example.
Message 9 of 38
(8,548 Views)
The TCP Write function will only accept ascii strings as an input, so some typecasting may be necessary depending on what file you are transferring.
0 Kudos
Message 10 of 38
(8,535 Views)