You are reading a single comment by @Mrbbp and its replies. Click here to read the full conversation.
  • Hello Markus,
    a Happy new Year.

    i've found that in the forum and it do the job as i expect.

    console.log("hex:",d.charCodeAt().toStri­ng(16));
    

    the module send some char and the last one is the SUM of the transmitted string.
    i wrote something like that (i did not test it on the espruino)

    let sum=0;
    let buf = new Uint8Array();
    
    function checkAnswer(buff) {
      console.log(buff.toString(16));
     switch (buff[1]) {
       case 0x01: // status
         console.log("status:",buff[3]);
         break;
       case 0x0C: //total audios
         console.log("total audios:",buff[3],buff[4]);
         break;
       case 0x0D: //current audio
         console.log("current audio:",buff[3],buff[4]);
         break;
       default:
         break;
      }
      // reset first buffer
      buf = new Uint8Array();
    }
    
    s.setup(9600,{rx:B6, tx:B5});
      s.on('data', function(d) {
        console.log("hex",d.charCodeAt().toStrin­g(16).toUpperCase());
        let nd = d.charCodeAt();
        buf.push(nd);
        sum+= nd;
        if (sum == nd && buf.length >1) {
          // fin de la transmission
          buf.pop(); // efface le sum du buffer
          sum = 0;
          checkAnswer(buf);
        }
      });
    
    

    regards

About

Avatar for Mrbbp @Mrbbp started