TCP Writer

Concerning processing components: filters, file load/save, visualizations, communication ...
Post Reply
Nico A.
Posts: 8
Joined: Thu Mar 07, 2019 8:05 am

TCP Writer

Post by Nico A. »

What kind of encoding is the raw data of TCP Writer? I try to decode it with a Python script. "utf-8" and "utf-16" did not work.

edit: I figured out what I wanted.

You can index the data received ("recv" in Python):

Code: Select all

data = socket_from_tcp_writer.recv(buf_size) # important to set up socket before
len(data) # = 8*number channels*chunk size (e.g. 1 channel, 4 samples per chunk --> 32)
Now, every "chunk" of 8 numbers in this list has to be converted to "double" variable type in Python:
(sadly the indentation was lost) Moderator Edit : the code tag instead quote tag for code.^^

Code: Select all

# buf_size_sc: samples per chunk set in scenario or acquisition server
for factor in range(buf_size_sc):
    # append to list
    to_convert = []
    for i in range(8):
        to_convert.append(data[factor*8 + i])
    # convert
    converted = bytearray(to_convert)
    # readout actual number
    floatval_tuple = struct.unpack('d', converted)
    floatval = floatval_tuple[0]
    chunk_vals.append(floatval)
chunk_vals is now a list containing all floating point values of the chunk.

Thibaut
Posts: 264
Joined: Wed Oct 31, 2018 9:14 am

Re: TCP Writer

Post by Thibaut »

I don't understand your edit^^, your problem is solved ?

Post Reply