How to read data every second in serial communications using matlab
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello, I would like to read data every one second from the device but i am unable to do it. I have tried with the following code. Here is the code...
s=serial('COM1','BAU',9600,'parity','none','databits',8,'stopbits',1,'terminator','CR/LF')
fopen(s)
fid2=fopen('pressure1.txt','w')
fprintf(fid2,'%s\t\t\t %s\n','time','pressure')
fprintf(s,'%s\r\n','PR1')
while true
out2=fscanf(s)
sr2=datestr(clock,0)
if ~isempty(out2)
fprintf(fid2,'%s: %s\n',sr2,out2)
pause(1)
end
end
fclose(fid2)
댓글 수: 0
답변 (1개)
Walter Roberson
2015년 8월 31일
fprintf(s,'PR1')
The default format is '%s\n' . Each \n is replaced with the terminator you configured so you do not need to specifically send \r\n when you have configured CR/LF as the terminator. Notice you did not specifically send \r\n in your later fprintf
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!