LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to transfer file from PC to PC via serial port using labview

Solved!
Go to solution
I need to transfer files(.txt, .doc, .xls) from PC to PC via serial port using LabVIEW. Is it possible to transfer files, if so how to transfer?
0 Kudos
Message 1 of 20
(12,604 Views)
Solution
Accepted by Technical_details

Yes, it is possible to transfer files with the serial port using LabVIEW.  Files are just collections of bytes and the serial port is pretty good at shipping bytes from one PC to another.  You need to connect the serial ports together with a null modem cable.

 

First, take a look at the example for serial communication.   In LabVIEW, go to the Help menu and select "Find Examples...".  From there you can search for "serial" or navigate to Hardware Input and Output >> Serial.  Select the "Basic Serial Write and Read.vi".  Experiment with that example to gain confidence on the serial communication methods.

 

Next, it's time to learn about how to read and write files.  For that, the examples could be somewhat confusing since they all deal with files that are presumed to have data of a specific type in them.  I would recommend just getting familiar with the functions on the File I/O palette.  Specifically, get to know the following functions.

 

  1. Open/Create/Replace File - On your destination side, you'll need to create the copy of the file that you are trying to transfer
  2. Close File - When you are finished reading from or writing to a file, you should close it.  It cleans up the memory being used and finalizes any write operations that are still floating in the write buffer.
  3. Read From Binary File - The best way to read from a file when you do not really care what type of file it is.  In your case, you just want to get those bytes read and sent out so they can be written down at the destination.
  4. Write to Binary File - At the destination side, this is what will store those bytes to the file you created with number 1.
  5. Get File Size (under the Advanced File Functions sub-palette) - You need to know how big the file is so you know when you are finished.

OK, so once you are able to create files, write bytes to them, and read bytes from existing files you can move on to transferring.

 

The basic method I would suggest is to have the user specify a source file on the source PC and a destination folder on the destination PC.  Then, find out the size of the source file using number 5.  Divide that size number by the number of bytes you feel like transferring at once.  The serial buffers are usually around 32k (if I remember correctly) so do not exceed that.  Now begin sending data by reading some number of bytes and wiring that string output to the VISA Write function.  On the destination side, you'll want to be monitoring the serial port for bytes and reading them when they arrive.  Wire that string to the Write to Binary File function to add them to your destination file.

 

That is the basic outline of how to do it.  You have to be careful not to overload the write and read buffers on the serial ports.  Initially you can use delays on the sending side to make sure the reading side has enough time to digest.  To get things moving faster, you can bring in some flow control.

 

If all that sounds a bit intimidating, there are Alliance Member companies out there (such as PrimeTest Automation) who can write such code for you and even provide a turnkey solution for you.

 

Happy wiring,

 

Dan Press

Certified LabVIEW Architect

PrimeTest Automation

Message 2 of 20
(12,588 Views)

Hi thanks for the solution suggested.

 

But already i am aware of serial port communication. I even achieved character transfer from PC to PC using LabVIEW software. I face no problems in that. Also i am aware of File I/O palette functions too. But then i suffer in sending already existing file on the PC. I want to know exactly how to convert the existing files into binary bytes and then how to send that data via serial port. If u can give me some procedure to be followed to achieve file transfer or if any sample program available let me know.

 

Padhu.

0 Kudos
Message 3 of 20
(12,531 Views)
If you've already achieved transferring characters from one PC to another with LabVIEW and you know about the File I/O functions, then what is the issue? The Read From Binary File will return by default a string which is the data in the file as a stream of bytes. This can be wired directly to VISA Write, although I suspect that you may want to do some throttling of the data transfer (i.e., do it in chunks).
0 Kudos
Message 4 of 20
(12,519 Views)
Just curious, but why would you choose to do such a slow method of transferring files? You can just as easily connect two pc's with a network cable. Even if you needed them, the cost of a couple of extra NICs is next to nothing.
0 Kudos
Message 5 of 20
(12,516 Views)

Hi

 

I have few queries on this binary file conversion. While writing the data into binary file using "write to Binary file" i am getting few space at the begining of my data. how to avoid that blank space. For reference i have attached the text file with this.

Second query: during binay file read operation the size of the file can be known through "Get File Size", after that why we need to divide and give the quotion to the count of "read from binary file". We can even give the file size directly to count of "read from binary file"

 

Padhu.

0 Kudos
Message 6 of 20
(12,477 Views)

The text file is pretty worthless. What about the file that you read and the VI you use? Are you prepending the array or string size? That's the default.

 

I don't understand your second question. I thought you wanted to read the entire file. You would use the file size and divide by the byte count if you wanted to read x number of bytes.

0 Kudos
Message 7 of 20
(12,463 Views)

Hi,

 

Here by i have attached vi with write to binary file operation. Create a new text file with extension ".txt" and then run this VI, enter some text on string control. after exeution open and see the text file saved you could find few blank space before the string you have entered which you could also refer with my text file attached along with this. My doubt is this why this blank space is getting created. Is it possible to avoid it and how to avoid it.

 

Secong Doubt: I have attached vi with read from binary file operation. I need to read the complete file for which i suppose that i should connect the complete file size to the byte count of the read icon. the division is required only if i need to read only few bytes from the file. (I guess i am right in my understanding).

 

Note: Run the write to binary file vi first and save it as text file. then you read the same text file using read from binary file VI. here u can notice few blank spaced occured before your string typed because of write to binary file operation.

 

Padhu.

Download All
0 Kudos
Message 8 of 20
(12,431 Views)

Technical,

 

Have you tried the VISA Write From File.vi and VISA Read to File.vi ?

0 Kudos
Message 9 of 20
(12,418 Views)
I asked you to check on the Prepend Array or String Size input. You did not comment on that and you have it set to True. Don't do that. Set it to false. You also seem intent on wiring up the file size to the count input. Read the help. You just have to wire a -1 to read the entire file.
0 Kudos
Message 10 of 20
(12,404 Views)