title: how can i use serial port Synchronously in Node js ?
body: <p>i use serialport module in node js , and execute the code like this, but error occurred.</p>
  
  <pre><code>for(i=0; i&lt;5; i++){
      a(i) ; 
  }
  
  function a(i){
  
      port = new serialport(port_name,{
  
           baudRate:9600 ,
  
           parser: new serialport.parsers.Readline('\n')
      });
  
      port.on('open',function(){
           port.write(port_command+'\n');
           data = port.read();
           console.log(i + data);
           port.close();
      });
  }
  </code></pre>
  
  <p>but error is occurred , </p>
  
  <p>"UnhandledPromiseRejectionWarning: Error Resource temporarily unavailable Cannnot lock port"</p>
  
  <p>"UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). "</p>
  
  <p>"DeprecationWarning: Unhandled promise rejections are deprecated. In the future, 
  promise rejections that are not handled will terminate the Node. js process with 
  a non-zero exit code.</p>
  
  <p>I want them to run in order like </p>
  
  <p>a(0) port open , write , read , close</p>
  
  <p>a(1) port open , write , read , close</p>
  
  <p>a(2) port open , write , read , close</p>
  
  <p>a(3) port open , write , read , close</p>
  
  <p>a(4) port open , write , read , close</p>
  
  <p>i think a(0) open, a(1) open so error .. how can i solve this problem? </p>