필터 지우기
필터 지우기

Why do the functions fread and fwrite take so long to run in Matlab?

조회 수: 8 (최근 30일)
David
David 2013년 6월 27일
Hi,
I am working on reading and writing data to a piece of hardware from Matlab. Time is an issue for me. I was running a Matlab code that uses the functions fread and fwrite. Using profile report, I saw that these functions take quite a long time. I was wondering what type of stuff are happening under the hood when I call fread and fwrite that are making it take so long. FYI, I am using fread and fwrite to read and write to the COM port.
Thanks in advance, David
  댓글 수: 2
Walter Roberson
Walter Roberson 2013년 6월 27일
How much data at a time are you fwrite() ? Is the COM port a USB device emulating a serial port?
David
David 2013년 6월 28일
I am sending anywhere from 11 to 99 bytes. I am using a virtual com port. I hope that answered the question.

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

채택된 답변

Jan
Jan 2013년 6월 27일
편집: Jan 2013년 6월 27일
Then the speed is not limited by the commands fread and fwrite, but by the COM port setup.
  댓글 수: 2
David
David 2013년 6월 28일
I am not too familiar with this area. But is there a way to optimize the COM port setup. And is the reason fread and fwrite are taking so long to run because the COM port is not setup well. Can you shed some more light on this. Why then is the "serial" command not the limiting factor.
Thanks for the quick response.
Jan
Jan 2013년 6월 28일
When you setup the COM port by the command serial to run with 9600 Baud, fread and fwrite are limited by this speed. So please show us the code you use to initialize the serial connection. Seeing the rest of the the code might reveal further problems also, which cannot be guessed blindly.

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

추가 답변 (1개)

Ravi
Ravi 2013년 6월 28일
Why cant you use S-functions & i am reading some 1 lakh data line or values within seconds.... Firstly you send your code & what u have done till now.. Then we can discuss further..
static void mdlOutputs(SimStruct *S, int_T tid) { //get pointer to the block's output signal real_T *y = ssGetOutputPortSignal(S,0);
/*get pointer to array of pointers, where the first element is the address
*of the open file */
void** pwork = ssGetPWork(S);
/*read a floating point number and then the comma delimiter
*store the result in y*/
fscanf(pwork[0],"%f%*c",y);
}
we used such type of code.... So u describe ur code....
  댓글 수: 3
Ravi
Ravi 2013년 6월 28일
100000 ==> lakh data vallues we can read i mean

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

카테고리

Help CenterFile Exchange에서 Periodic Waveform Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by