5656from PyQt5 .QtWidgets import QInputDialog
5757
5858from MLC .arduino .protocol import ProtocolConfig , ProtocolSetupException , ProtocolIOException
59- from MLC .arduino .protocol import ArduinoInterfaceSingleton
59+ from MLC .arduino .protocol import ArduinoUserInterface
6060from MLC .arduino .connection .base import invalid_connection_builder
6161from MLC .arduino .connection .serialconnection import ConnectionException , serial_connection_builder
6262from MLC .arduino .connection .base import BaseConnection
@@ -126,7 +126,7 @@ def __init__(self, mlc_local,
126126
127127 # Arduino board configurations
128128 self ._board_config , self ._serial_conn = mlc_local .get_board_configuration (self ._experiment_name )
129- ArduinoInterfaceSingleton .set_connection_builder (serial_connection_builder )
129+ ArduinoUserInterface .set_connection_builder (serial_connection_builder )
130130
131131 # Update the arduino board group for the first case
132132
@@ -150,19 +150,19 @@ def on_start_button_clicked(self):
150150 .format (self ._experiment_name ))
151151
152152 try :
153- ArduinoInterfaceSingleton .get_instance (protocol_config = self ._board_config ,
154- conn_setup = self ._serial_conn )
153+ ArduinoUserInterface .get_instance (protocol_config = self ._board_config ,
154+ conn_setup = self ._serial_conn )
155155
156156 except (ProtocolSetupException , ConnectionException ) as err :
157157 logger .debug ('[EXPERIMENT {0}] [BOARD_CONFIG] - '
158158 'Serial port could not be initialized. Error Msg: {1}'
159159 .format (self ._experiment_name , err ))
160160 selection = QMessageBox .warning (self , "Connection failure" ,
161- "The current connection arduino setup failed during initialization "
162- "(Error: {0}), this may generate an error in your experiment.\n "
163- "Do you want to continue?" .format (err ),
164- QMessageBox .Yes | QMessageBox .No ,
165- QMessageBox .Yes )
161+ "The current connection arduino setup failed during initialization "
162+ "(Error: {0}), this may generate an error in your experiment.\n "
163+ "Do you want to continue?" .format (err ),
164+ QMessageBox .Yes | QMessageBox .No ,
165+ QMessageBox .Yes )
166166 if selection == QMessageBox .No :
167167 logger .debug ('[EXPERIMENT {0}] [START_BUTTON] - Experiment cancelled by user before start' .format (
168168 self ._experiment_name ))
@@ -226,7 +226,8 @@ def on_start_button_clicked(self):
226226 progress_dialog .start ()
227227
228228 def on_prev_gen_button_clicked (self ):
229- logger .debug ('[EXPERIMENT {0}] [PREV_GEN_BUTTON] - Executing on_prev_gen_button_clicked function' .format (self ._experiment_name ))
229+ logger .debug (
230+ '[EXPERIMENT {0}] [PREV_GEN_BUTTON] - Executing on_prev_gen_button_clicked function' .format (self ._experiment_name ))
230231 experiment_info = self ._mlc_local .get_experiment_info (self ._experiment_name )
231232 number_of_gens = experiment_info ["generations" ]
232233
@@ -237,7 +238,8 @@ def on_prev_gen_button_clicked(self):
237238 self ._update_scatter_chart ()
238239
239240 def on_next_gen_button_clicked (self ):
240- logger .debug ('[EXPERIMENT {0}] [NEXT_GEN_BUTTON] - Executing on_next_gen_button_clicked function' .format (self ._experiment_name ))
241+ logger .debug (
242+ '[EXPERIMENT {0}] [NEXT_GEN_BUTTON] - Executing on_next_gen_button_clicked function' .format (self ._experiment_name ))
241243 experiment_info = self ._mlc_local .get_experiment_info (self ._experiment_name )
242244 number_of_gens = experiment_info ["generations" ]
243245
@@ -571,13 +573,16 @@ def on_disable_arduino_toggle(self, active):
571573 self ._autogenerated_object .board_config_button .setDisabled (active )
572574
573575 if active :
574- ArduinoInterfaceSingleton .disable_interface ()
576+ ArduinoUserInterface .disable_interface ()
575577 else :
576578 # FIXME In the future, some logic to get the old connection builder must be implemented
577- ArduinoInterfaceSingleton .set_connection_builder (serial_connection_builder )
579+ ArduinoUserInterface .set_connection_builder (serial_connection_builder )
578580
579- ArduinoInterfaceSingleton .get_instance (protocol_config = self ._board_config ,
580- conn_setup = self ._serial_conn )
581+ try :
582+ ArduinoUserInterface .get_instance (protocol_config = self ._board_config ,
583+ conn_setup = self ._serial_conn )
584+ except (ProtocolSetupException , ConnectionException ) as err :
585+ pass
581586
582587
583588################################### VIEW AND MODEL METHODS #########################################
@@ -919,8 +924,8 @@ def _store_board_configuration(self, board_config, serial_conn):
919924
920925 # Init the arduino singleton
921926 try :
922- ArduinoInterfaceSingleton .get_instance (protocol_config = self ._board_config ,
923- conn_setup = self ._serial_conn )
927+ ArduinoUserInterface .get_instance (protocol_config = self ._board_config ,
928+ conn_setup = self ._serial_conn )
924929
925930 # Update board configuration in the DB
926931 self ._mlc_local .save_board_configuration (self ._experiment_name , self ._board_config , self ._serial_conn )
@@ -930,11 +935,11 @@ def _store_board_configuration(self, board_config, serial_conn):
930935 'Serial port could not be initialized. Error Msg: {1}'
931936 .format (self ._experiment_name , err ))
932937 selection = QMessageBox .warning (self , "Connection failure" ,
933- "The current connection setup failed during initialization. "
934- "Do you want to change this configuration? "
935- "(Choosing \" no\" means that the board will not be usable in the experiment)" ,
936- QMessageBox .Yes | QMessageBox .No ,
937- QMessageBox .Yes )
938+ "The current connection setup failed during initialization. "
939+ "Do you want to change this configuration? "
940+ "(Choosing \" no\" means that the board will not be usable in the experiment)" ,
941+ QMessageBox .Yes | QMessageBox .No ,
942+ QMessageBox .Yes )
938943 if selection == QMessageBox .Yes :
939944 self .on_board_config_button_clicked ()
940945 else :
0 commit comments