diff --git a/DepositSMUCv2.xaml.cs b/DepositSMUCv2.xaml.cs index e61214c..e1c82e6 100644 --- a/DepositSMUCv2.xaml.cs +++ b/DepositSMUCv2.xaml.cs @@ -105,53 +105,61 @@ namespace SafeBagDE70 } cCmdRsp = new CCmdRsp(serialPortDE70); AppData.cCmdRsp = cCmdRsp; - // LoginUsingQRCode(); - InitSerialPorts(); - //Subscrible to the DataReveied event\ - bInitialized = InitSession(); - InitTimers(); - - notesInSession = new NotesInSession(); - spNotesInSession.DataContext = notesInSession; + bool bInitSP = InitSerialPorts(); + if(bInitSP) + { + bInitialized = InitSession(); + InitTimers(); - - ResetButtons(); - btnStart.IsEnabled = true; - btnLogout.IsEnabled = true; - ResetTimers(); - var state=GetCDMState(); - if(state.GetSR2()==0x1C) - { - StopTimers(); - ShowError(state.CDMStatus); - } - - var data= AppData.GetCassetteData(); - if (transactionCode != null) - { - - AppData.DeviceStatus.Description = $"[CASSETTE]" + AppData.GetNotesString(data); - APIModels.SendEvent(AppData.DeviceStatus); - } + notesInSession = new NotesInSession(); + spNotesInSession.DataContext = notesInSession; + + + ResetButtons(); + btnStart.IsEnabled = true; + btnLogout.IsEnabled = true; + ResetTimers(); + var state = GetCDMState(); + if (state.GetSR2() == 0x1C) + { + StopTimers(); + ShowError(state.CDMStatus); + } + + var data = AppData.GetCassetteData(); + if (transactionCode != null) + { + AppData.DeviceStatus.Description = $"[CASSETTE]" + AppData.GetNotesString(data); + APIModels.SendEvent(AppData.DeviceStatus); + } + } } catch (Exception ex) { - if(AppData.DeviceStatus!=null) - { - AppData.DeviceStatus.CDMStatus = (int)CDMStatusCode.DISCONNECT_SERIALPORT; - APIModels.SendEvent(AppData.DeviceStatus); - Log.Fatal(ex, "LỖI CỔNG KẾT NỐI"); - ShowError("LỖI CỔNG KẾT NỐI, VUI LÒNG KIỂM TRA LẠI CỔNG KẾT NỐI"); - } - + AppData.DeviceStatus.Description = "LỖI KHỞI TẠO GIAO DỊCH"; + APIModels.SendEvent(AppData.DeviceStatus); + Log.Fatal(ex, "LỖI KHỞI TẠO GIAO DỊCH"); + ShowError("LỖI KHỞI TẠO GIAO DỊCH"); } } - private void InitSerialPorts() + private bool InitSerialPorts() { - InitSerialPortDE70(); - InitSerialPortSensor(); + try + { + InitSerialPortDE70(); + InitSerialPortSensor(); + return true; + } + catch(Exception ex) + { + AppData.DeviceStatus.CDMStatus = (int)CDMStatusCode.DISCONNECT_SERIALPORT; + APIModels.SendEvent(AppData.DeviceStatus); + Log.Fatal(ex, "LỖI CỔNG KẾT NỐI"); + ShowError("LỖI CỔNG KẾT NỐI, VUI LÒNG KIỂM TRA LẠI CỔNG KẾT NỐI"); + } + return false; } private void InitSerialPortSensor()