LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a File and by using TCP/IP transfer protocol?

I have a Lab View data file from a DAQ card NI-4451. I would like to take this file and transfer it over TCP/IP Server/Client protocol and open the file to see the results.
0 Kudos
Message 1 of 9
(4,513 Views)
What specifically is your question?

It's commonly done, but there's no built-in function for it.

Here's one way:
On the server side, you
1... Wait for connection
2... Open the file
3... Remainder = determine file size (in bytes)
4... Repeat
5... N = remainder
6... If N > 1024, N = 1024 (limit chunk size )
7... Read N bytes from file.
8... Flatten N to a string of four bytes.
9... Write string to connection.
10... Write N bytes to connection.
11... Remainder = Remainder - N
12... until N = 0.
13... Flatten 0 to a string of four bytes.
14... Send 4-byte string (end-of-file marker).
15... Close File.
16... Close connection.


On the client side, you:
1... Open connection to server.
2... Create (or overwrite) local
file.
3... repeat
4... Read 4 bytes from connection.
5... Unflatten 4 bytes to I32 (N = size of chunk).
6... If N > 0
7... Read N Bytes from connection.
8... Write N bytes to file.
9... until N=0, or error.
10... Close connection.
11... Close file.


You will need to add error-checking to that, but that's the basic idea.

The chunk size can be no more than approx 1500 bytes (I forget the exact number), per IP rules.

If you run both client and server on the same machine, you can use 127.0.0.1 as the IP address, and it will copy a file from one place to another. Use that to test it before bothering with two machines.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 9
(4,512 Views)
CoastalMaineBird wrote:

> You will need to add error-checking to that, but that's the basic
> idea.
>
> The chunk size can be no more than approx 1500 bytes (I forget the
> exact number), per IP rules.

While it is a good idea to break down large files in smaller chunks to
be transmitted the chunk size of 1500 bytes is only an IP limitation and
for that not even a strict one. If you are using dialup connections this
can get down to a few hundred bytes.

However TCP on top of IP has its own routing and connection control
layer which makes the underlaying IP layer completely transparent. There
is no problem in trying to send 10kB big chunks or for that matter even
1MB chunks if you like to wait possibly for a long time for the TCP
functions to return
control back to your application.

Now if you would be using UDP as transport layer that would be another
story as UDP has no out of order correction and no guaranteed package
transmission, so bigger packets have a higher probability to simply get
lost on their way to the data sink.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 3 of 9
(4,512 Views)
Thanks for your input.

Basically, what I am trying to do a wireless connections b/w two PC's by using TCP/IP connection to send a RAW data. The RAW data will be generated at the Server side and I want to display it on Remote Client side. The RAW data will be 5 different graphs that need to display on the Client side. So far I have study and looked the TCP/IP Server/Client side to see how things are generated and displayed. On the example TCP/IP server side, it has a stacked sqeu. That is generating the graph and its sending to Client to display it.

That is the basic idea behind my application.
0 Kudos
Message 4 of 9
(4,512 Views)
Then I don't understand why you asked about files.

The TCP/IP examples show how to transmit data blocks.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 5 of 9
(4,512 Views)
Perhaps it�s the Lab View architecture that I am not still clear with yet!!

So in TCP/IP Server/Client I can insert 5 different subVI's and called them with 0 through 4 case and send to display it on Client side? Those subVI's can be anything denstation PC.
Thanks..
0 Kudos
Message 6 of 9
(4,512 Views)
If you have ONE client and ONE server machine then you don't want to have FIVE TCP connections.

1... Design a data structure. It should hold your five values, plus a timestamp, or whatever else you want. Make it a TypeDef, for ease of changes, if you want.

On the server (where the data comes from):
2... I would have a single loop to collect your data and put it into this data structure, at whatever rate you need. This loop runs regardless of whether there is a TCP connection or not. It also sets a flag called NEW DATA.
3... Conn ID = invalid CONN ID (Initialize a shift reg) on 2nd WHILE loop
3... Repeat
4... If shift reg is not VALID conn ID:
Wait for connection - assign conn ID
else

if NEW DATA flag NOT set
wait 20 mSec (or something)
else
Flatten latest data cluster into string.
Clear the NEW DATA flag.
Write string to connection.
5... until done.

On the client, you:
1... Open a connection.
2... S = flatten your Data Cluster into a string.
3... N = size of (S). Do not hardwire this constant, let it be figured for you.
4... Repeat
5... Read N bytes from connection.
6... Unflatten string into your data type.
7... Display, store, whatever.
8... until done.
9... Close connection.

You'll have to add error checking, what to do if the connection breaks, etc.
But that's the idea.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 7 of 9
(4,512 Views)
How about just serving and action engine that can read files and return the contents. It can have selector that lets the caller determine what files to read. Note, files are not required and will actually be slower than just ftetching a buffer.

Use VI server call by reference and you are done!

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 9
(4,512 Views)
Actually, I have ONE server and ONE client machine only. The server machine will take input data from NI-4451 and process them at the server machine. I want to show 5 different data graphs. I do not want to send the data to client machine. I will gather all my data at the server machine and process at the server machine. I just want to show the result at client. Similar to TCP/IP server/client example.

Do I still need to do:

"If you have ONE client and ONE server machine then you don't want to have FIVE TCP connections.
1... Design a data structure. It should hold your five values, plus a timestamp, or whatever else you want. Make it a TypeDef, for ease of changes, if you want.
On the server (where the d
ata comes from):
2... I would have a single loop to collect your data and put it into this data structure, at whatever rate you need. This loop runs regardless of whether there is a TCP connection or not. It also sets a flag called NEW DATA.
3... Conn ID = invalid CONN ID (Initialize a shift reg) on 2nd WHILE loop
3... Repeat
4... If shift reg is not VALID conn ID:
Wait for connection - assign conn ID
else
if NEW DATA flag NOT set
wait 20 mSec (or something)
else
Flatten latest data cluster into string.
Clear the NEW DATA flag.
Write string to connection.
5... until done.
On the client, you:
1... Open a connection.
2... S = flatten your Data Cluster into a string.
3... N = size of (S). Do not hardwire this constant, let it be figured for you.
4... Repeat
5... Read N bytes from connection.
6... Unflatten string into your data type.
7...
Display, store, whatever.
8... until done.
9... Close connection.
You'll have to add error checking, what to do if the connection breaks, etc.
But that's the idea."
0 Kudos
Message 9 of 9
(4,512 Views)