var reponse= {trame:"",longueur:0};
s.setup(9600,{rx:B6, tx:B5});
s.on('data', function(data) {
reponse.trame+= data;
if (reponse.trame.length >= reponse.longueur) {
switch (reponse.trame.charCodeAt(1)) {
case 0x01: // status
console.log("status:",reponse.trame.charCodeAt(3));
break;
case 0x09: // status
console.log("check Drive:",reponse.trame.charCodeAt(3));
break;
case 0x12: //Check the total numbers of audio in all folders(12)
console.log("nbr total audios:",(reponse.trame.charCodeAt(3)<<8 ^ reponse.trame.charCodeAt(4)));
break;
case 0x0C: //Check the total audios(0C)
console.log("nbr total audios:",(reponse.trame.charCodeAt(3)<<8 ^ reponse.trame.charCodeAt(4)));
break;
case 0x0D: //current audio
console.log("nom fichier audio:",reponse.trame.charCodeAt(3),reponse.trame.charCodeAt(4));
break;
case 0x24: //duration audio
console.log("Duréé: "+reponse.trame.charCodeAt(3)+"H "+reponse.trame.charCodeAt(4)+"mn "+reponse.trame.charCodeAt(5)+"s");
break;
default:
break;
}
}
});
and each command sent, fill the reponse.longeur with the appropriate value...
function Duration() {
var command = [0xAA, 0x24, 0x00, 0xCE];
// Return: AA 24 03 hour minute second SM
reponse.longueur = 7;
reponse.trame = "";
s.write(command);
}
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
i've written something like that
and each command sent, fill the
reponse.longeur
with the appropriate value...Not Tested
Thanks for your help @allObjects.