False data received through serial port
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I'm working on controlling linear actuator with Matlab through serial port. It has seemed to be working right. But recently I've got some problem.
fwrite(port,[1 60 0 0 0 0]);
bpos1=fread(port,6)'
The above is to ask actuator the reply the current position and actuator supposed to reply its current position right away. After writing fwrite, I can get reply from actuator by using fread func. Eventually I get the right reply, but before receiving that right value, it replies wrong value for several second.And I keep entering fread till get the right value. It sometime takes few second or more than 10 second.
So to figure this out, I did some cable work and connected the cable to second computer at a time and looked at the date coming out from actuator by using serial terminal software. And in first computer I saw wrong value, but in second computer I couldn't see any wrong value. i.e, actuator replies right value. Than problem is on somewhere in computer side. I changed the serial-usb adapter and it didn't work. So the reason of this issue I'm thinking is
1. due to using serial-usb adapter 2. Matlab
I'll try 1 with other computer which has serial port. But regarding Matlab, I can't seem to find any reason.
Following is whole the function I use to get the current position data from actuator. Almost same as above.
function[pos]=CurrentPos(port)
fwrite(port,[1 60 0 0 0 0]); %-> To ask actuator to reply back the current position
bpos1=fread(port,6)' %-> store the replied data.
bpos2=bitsToNumber(bpos1(3),bpos1(4),bpos1(5),bpos1(6));
bpos3=MicroToMil(bpos2);
pos=floor(bpos3)+1; % last 3 lines are to convert bit to number.
I asked actuator manufacturer and they were not sure, but mentioned that it might be some buffer problem of Matlab.
Could anybody help me?
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 General Applications에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!