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);
AppData.cCmdRsp = cCmdRsp;
// LoginUsingQRCode();
InitSerialPorts();
//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)
bool bInitSP = InitSerialPorts();
if(bInitSP)
{
StopTimers();
ShowError(state.CDMStatus);
}
bInitialized = InitSession();
InitTimers();
var data= AppData.GetCassetteData();
if (transactionCode != null)
{
notesInSession = new NotesInSession();
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)
{
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()