@@ -4,6 +4,8 @@ import store from '../../store';
44// import avrdude from './stk500';
55import avrdude from './avrgirl' ;
66
7+ const asyncTimeout = ( timeout ) => new Promise ( ( resolve ) => setTimeout ( ( ) => resolve ( timeout ) , timeout ) ) ;
8+
79class Uploader extends EventEmitter {
810 install ( Vue ) {
911 // eslint-disable-next-line no-param-reassign
@@ -23,6 +25,12 @@ class Uploader extends EventEmitter {
2325 return ! ! get ( this . toolMap , toolProt ) && get ( this . toolMap , tool ) . isValid ( board ) ;
2426 }
2527
28+ async waitForClose ( serial , count = 0 ) {
29+ if ( ! serial . serial . isOpen || count > 50 ) return null ;
30+ await asyncTimeout ( 100 ) ;
31+ return this . waitForClose ( serial , count + 1 ) ;
32+ }
33+
2634 async upload ( hex , config ) {
2735 const serial = this . Vue . $serial ;
2836 const existBaud = serial . baud ;
@@ -40,6 +48,7 @@ class Uploader extends EventEmitter {
4048 debug : ( message ) => this . Vue . $compiler . emit ( 'console.log' , message ) ,
4149 } ) ;
4250
51+ await this . waitForClose ( serial ) ;
4352 await serial . setBaud ( existBaud ) ;
4453 await serial . connect ( ) ;
4554 await serial . setMute ( false ) ;
0 commit comments