try catch init serial port

This commit is contained in:
Nguyen Dinh Thuan
2024-09-17 09:27:25 +07:00
parent b3ad51909d
commit a995db3860
+43 -35
View File
@@ -105,53 +105,61 @@ namespace SafeBagDE70
} }
cCmdRsp = new CCmdRsp(serialPortDE70); cCmdRsp = new CCmdRsp(serialPortDE70);
AppData.cCmdRsp = cCmdRsp; AppData.cCmdRsp = cCmdRsp;
// LoginUsingQRCode(); bool bInitSP = InitSerialPorts();
InitSerialPorts(); if(bInitSP)
//Subscrible to the DataReveied event\
bInitialized = InitSession();
InitTimers();
notesInSession = new NotesInSession();
spNotesInSession.DataContext = notesInSession;
ResetButtons();
btnStart.IsEnabled = true;
btnLogout.IsEnabled = true;
ResetTimers();
var state=GetCDMState();
if(state.GetSR2()==0x1C)
{ {
StopTimers(); bInitialized = InitSession();
ShowError(state.CDMStatus); InitTimers();
}
var data= AppData.GetCassetteData(); notesInSession = new NotesInSession();
if (transactionCode != null) spNotesInSession.DataContext = notesInSession;
{
AppData.DeviceStatus.Description = $"[CASSETTE]" + AppData.GetNotesString(data);
APIModels.SendEvent(AppData.DeviceStatus); 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) catch (Exception ex)
{ {
if(AppData.DeviceStatus!=null) AppData.DeviceStatus.Description = "LỖI KHỞI TẠO GIAO DỊCH";
{ APIModels.SendEvent(AppData.DeviceStatus);
AppData.DeviceStatus.CDMStatus = (int)CDMStatusCode.DISCONNECT_SERIALPORT; Log.Fatal(ex, "LỖI KHỞI TẠO GIAO DỊCH");
APIModels.SendEvent(AppData.DeviceStatus); ShowError("LỖI KHỞI TẠO GIAO DỊCH");
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");
}
} }
} }
private void InitSerialPorts() private bool InitSerialPorts()
{ {
InitSerialPortDE70(); try
InitSerialPortSensor(); {
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() private void InitSerialPortSensor()