LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP Read Too Slow in LabVIEW

Solved!
Go to solution

It's impressive how much an Express VI can slow down data acquisition. With your solution, reading the data is so much faster!

 

I'm now writing using the "Write Binary File" block as you suggested, but when I process the data to make it readable, I get what seem like random values in the range of: 7.98E-157, 5.80601E+11, 1.75E-219, -3.43E-243, 1.97E-256, -1.65E-274.


However, the values should be oscillating between 0 and 1.

0 Kudos
Message 11 of 18
(370 Views)

How do you process the data?

 

All you need is read from binary file:

Read from Binary FileRead from Binary File

 

By default, LabVIEW saves data with big-endian byte order as in Yamaedas example.

Message 12 of 18
(357 Views)

I'm just creating the file in LabVIEW, and then I use a Python script to read the binary file and write all the data into a CSV file. I'm not very confident with creating a binary file in LabVIEW, closing it, and then—after the while loop—reopening it to write all the binary data into an .xlsx file. I tried doing it that way:

 

Ouinon_0-1749051103572.png

 

…but the .xlsx file was always empty. (I also tried using the "Obtain queue")

 

When I use a TCP server written in C to receive data from the client and write it to a binary file, then use a Python script to convert the binary file into a CSV file, the values are in the correct range. But when I use LabVIEW… they are not.

 

I've attached my VI, my C-based TCP server (which does what I want to reproduce in LabVIEW), and my Python script.

Download All
0 Kudos
Message 13 of 18
(329 Views)

I fixed some bugs, try this

- "string" was prepended to actual data with write to binary file

- file was read from the end. either set the file position to the beginning or close and then read

- read the exact amount of data you expect, at least in multiples of channels*sizeof double, otherwise data is not aligned (does not matter too much in this case but do it anyway.)

- wrong endianness (python script uses little endian)

 

0 Kudos
Message 14 of 18
(312 Views)

@Ouinon wrote:

It's impressive how much an Express VI can slow down data acquisition. With your solution, reading the data is so much faster!

 

I'm now writing using the "Write Binary File" block as you suggested, but when I process the data to make it readable, I get what seem like random values in the range of: 7.98E-157, 5.80601E+11, 1.75E-219, -3.43E-243, 1.97E-256, -1.65E-274.


However, the values should be oscillating between 0 and 1.


The Express VI opens and closes the file between every write, by opening before the loop and closing after it keeps the reference open and the file position.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 15 of 18
(290 Views)

@Ouinon wrote:

I'm just creating the file in LabVIEW, and then I use a Python script to read the binary file and write all the data into a CSV file. I'm not very confident with creating a binary file in LabVIEW, closing it, and then—after the while loop—reopening it to write all the binary data into an .xlsx file. I tried doing it that way:

 

Ouinon_0-1749051103572.png

 

 


You can't use a file reference after you've closed it ... Also, where do you think the File pointer is after having written all the values? That's where it'll start to read.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 16 of 18
(289 Views)

To familiarized myself with reading binary files, and I'm now writing a simple VI. I don't know what I'm doing wrong, but at the end, I get random values. However, I should be getting values between 0 and 1 for the first three values, and a value that represent the time passing for the fourth one.

My binary file is a 1D array of floats structured like this:
[Value1 Value2 Value3 time Value1 Value2 Value3 time Value1 Value2 Value3 time ...]

 

I’ve attached my VI and the binary file I’m working on.

 

Download All
0 Kudos
Message 17 of 18
(257 Views)
Solution
Accepted by topic author Ouinon

The actual structure is the following:

- 1 4-byte integer  (= 256)

- 8192 8-byte double precision

- 1 4-byte integer (again = 256)

- 8192 8-byte double precision

...

and so on. All binary numbers are little endian.

 

read_binary_data.png

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 18 of 18
(247 Views)