Error For Send and Receive
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I have a question. I have this piece of code for send and receive using serial port. However, I found out that the received file have the same size as the original file but error occured when playback of the file. Hence, I think my formation of file are not correct. My requirement is to convert any file into binary format and transmit 16bits each with 10kB. Can someone let me know what is the problem existed to make the bits received is not the same as the received bits?Is this really MATLAb limtitations?
For my sending part:
file_selected=handles.file; fid=fopen(file_selected,'rb'); A=fread(fid,'uint16'); B=dec2bin(A); F=B';
[M N]=size(A);
looptimes=fix(M/5000);
last=rem(M, 5000);
send_count=1;
loop_count=0;
Idk=(1+5000*(send_count-1)):(5000*send_count);
C=zeros(16,(M-last));
for i=1:length(Idk)
C(:,i)=F((-15+16*(Idk(i))):16*(Idk(i)));
end
C=char(C);
C=reshape(C,1,16*(M-last));
fprintf(s,C)
send_count=1+send_count;
Hence is my received part: received_count=1; loop_count=0; file=[];
received=fgetl(s);
file=[file received];
received_count=received_count+1;
loop_count=0;
size_byte=fix(size(file)/16);
M=size_byte(2);
Video_bin=zeros(M,16);
for j=1:M
b=16*(j);
a=-15+b;
Video_bin(j,:)= file(a:b);
end
Video_bin=char(Video_bin);
D=reshape(Video_bin,16,M);
Video_dec=bin2dec(D).';
fid1=fopen (Save_file, 'wb');
count=fwrite(fid1, Video_dec, 'uint16');
Could anyone let me know which i had done wrong and causes my whole file to be corrupted? I could receive full file size but it doesn't give the correct output.
0 commentaires
Réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!