Receive serial data in Hex
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Prashant Funde
le 5 Avr 2016
Commenté : Walter Roberson
le 6 Avr 2016
I wanted to write data received from serial port in text file. I want received data in the form
40 00 20 00 10 00 08 00 00 0A 0F 0D 10
but i am getting data in the test file as 40 0 20 0 10 0 8 0 0 A F D 10.
Please tell me what should i use to get data as i received.
I am using following code
Rcvd = fread(serConn,45000,'char');
hexpass=sprintf(num2str('%3X', Rcvd));
header1 = '';
file_id=fopen('MyFile.txt','w');
fprintf(file_id,[header1 '\n']);
fprintf(file_id,'%s',hexpass);
Please suggest me to get the data in txt file as
40 00 20 00 10 00 08 00 00 0A 0F 0D 10
Thanks in adavance
0 commentaires
Réponse acceptée
Walter Roberson
le 5 Avr 2016
hexpass = num2str(Rcvd, '%02X ');
hexpass(end) = ''; %get rid of trailing space
2 commentaires
Walter Roberson
le 6 Avr 2016
hexpass = num2str(Rcvd(:).', '%02X ');
hexpass(end) = ''; %get rid of trailing space
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!