Page 1 of 1

TCP Writer

Posted: Tue May 07, 2019 3:14 pm
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.

Re: TCP Writer

Posted: Thu May 09, 2019 10:28 am
by Thibaut
I don't understand your edit^^, your problem is solved ?