@@ -694,9 +694,11 @@ function onClosed(result) {
694694
695695 MSP . clearListeners ( ) ;
696696
697- serial . removeEventListener ( 'receive' , read_serial_adapter ) ;
698- serial . removeEventListener ( 'connect' , connectHandler ) ;
699- serial . removeEventListener ( 'disconnect' , disconnectHandler ) ;
697+ if ( PortHandler . portPicker . selectedPort !== 'virtual' ) {
698+ serial . removeEventListener ( 'receive' , read_serial_adapter ) ;
699+ serial . removeEventListener ( 'connect' , connectHandler ) ;
700+ serial . removeEventListener ( 'disconnect' , disconnectHandler ) ;
701+ }
700702
701703 CONFIGURATOR . connectionValid = false ;
702704 CONFIGURATOR . cliValid = false ;
@@ -782,53 +784,24 @@ function startLiveDataRefreshTimer() {
782784}
783785
784786export function reinitializeConnection ( callback ) {
785- const isVirtual = CONFIGURATOR . virtualMode && GUI . connected_to == 'virtual' && CONFIGURATOR . connectionValid && serial . connectionId === 'virtual' ;
786-
787- gui_log ( i18n . getMessage ( 'deviceRebooting' ) ) ;
788-
789- // Close connection gracefully if it still exists.
790- const previousTimeStamp = connectionTimestamp ;
791-
792- if ( serial . connectionId ) {
793- if ( GUI . connected_to || GUI . connecting_to ) {
794- $ ( 'a.connect' ) . trigger ( 'click' ) ;
795- } else {
796- serial . disconnect ( ) ;
797- }
798- }
799787
800788 // In virtual mode reconnect when autoconnect is enabled
801- if ( isVirtual ) {
802- return setTimeout ( ( ) => {
803- if ( PortHandler . portPicker . autoConnect ) {
804- $ ( 'a.connect' ) . trigger ( 'click' ) ;
805- }
806- if ( typeof callback === 'function' ) {
807- callback ( ) ;
808- }
789+ if ( PortHandler . portPicker . selectedPort === 'virtual' && PortHandler . portPicker . autoConnect ) {
790+ return setTimeout ( function ( ) {
791+ $ ( 'a.connect' ) . trigger ( 'click' ) ;
809792 } , 500 ) ;
810793 }
811794
812- // Wait for serial or tcp connection to be available
813- let attempts = 0 ;
814- const reconnect = setInterval ( waitforSerial , 100 ) ;
795+ MSP . send_message ( MSPCodes . MSP_SET_REBOOT , false , false ) ;
815796
816- function waitforSerial ( ) {
817- if ( ( connectionTimestamp !== previousTimeStamp && CONFIGURATOR . connectionValid ) || GUI . active_tab === 'firmware_flasher' ) {
818- console . log ( `Serial connection available after ${ attempts / 10 } seconds` ) ;
819- clearInterval ( reconnect ) ;
820- gui_log ( i18n . getMessage ( 'deviceReady' ) ) ;
797+ gui_log ( i18n . getMessage ( 'deviceRebooting' ) ) ;
821798
822- if ( typeof callback === 'function' ) {
823- callback ( ) ;
824- }
825- } else {
826- attempts ++ ;
827- if ( attempts > 100 ) {
828- clearInterval ( reconnect ) ;
829- console . log ( `failed to get serial connection, gave up after 10 seconds` ) ;
830- gui_log ( i18n . getMessage ( 'serialPortOpenFail' ) ) ;
831- }
832- }
799+ // wait for the device to reboot
800+ setTimeout ( function ( ) {
801+ gui_log ( i18n . getMessage ( 'deviceReady' ) ) ;
802+ } , 2000 ) ;
803+
804+ if ( callback ) {
805+ callback ( ) ;
833806 }
834807}
0 commit comments