필터 지우기
필터 지우기

Slow communication with NA though LAN cable, using the fread fucntion

조회 수: 1 (최근 30일)
Milad Mom
Milad Mom 2017년 8월 7일
댓글: Milad Mom 2017년 8월 14일
Slow communication with NA, I use direct Lan cable for connection: I use the TCPIP to connect to a Network Analyzer using the following code:
obj_e5080_ = tcpip('169.254.64.111', 5025); obj_e5080_.InputBufferSize = 1e5; obj_e5080_.OutputBufferSize = 1e5; obj_e5080_.ByteOrder = 'littleEndian';
Then I want to check the elapsed time for reading the data using this code:
tic fprintf(obj_e5080_, ':INITiate:IMMediate'); opc1 = sscanf(query(obj_e5080_, '*OPC?'), '%d'); fprintf(obj_e5080_,':CALCulate:MEASure:DATA:SDATa?'); sdata1 = fread(obj_e5080_,81,'double'); toc
However, the results are not good and it is very slow: Elapsed time = 0.2 seconds, can Anyone help please?
I attached the real time results as well

답변 (1개)

Tony Mohan Varghese
Tony Mohan Varghese 2017년 8월 14일
The issue may be related to this line:
sdata1 = fread(obj_e5080_,81,'double');
fread function will read data as double precision and stores them as double array. This is a memory heavy operation and is thus slow. I would suggest to read the data as characters and convert them back to double array later.
It was also observed that fread takes much longer to execute when the default terminator setting is used / Terminator is not empty (“”). This behavior is mentioned in the FREAD doc page:
See "Note: Set the terminator property to '' (null), if appropriate, to ensure efficient throughput of binary data." Try to use a null/empty terminator .
  댓글 수: 1
Milad Mom
Milad Mom 2017년 8월 14일
Thank you Tony,
I applied your comment adding the obj_e5080_.Terminator = ' '; command to fasten the fread function, however, the results were the same. Actually, we noticed that the fread gives us wrong results from time to time, so I used binblockread instead which gives us correct answers all the times. But the problem of slow reading is still there. Here is the code: (please note that I just read 5 data points from the instrument) 
tic  fprintf(obj_e5080_, ':INITiate:IMMediate');  fprintf(obj_e5080_,':CALCulate:MEASure:DATA:FDATa?');  toc  [A,count,msg] = binblockread(obj_e5080_, 'double');  toc   
%and the results:
Elapsed time is 0.000920 seconds.  Elapsed time is 0.222298 seconds. 
>> count
count =
     9
which is still very slow. I appreciate your help.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by