try catch Init printer
Đảo thử tự InitUsers Kiểm tra đầu đọc QR
This commit is contained in:
+22
-1
@@ -1,5 +1,6 @@
|
||||
using DE70_CMDv2;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SafeBagDE70.API;
|
||||
using SafeBagDE70.Model;
|
||||
using Serilog;
|
||||
using System;
|
||||
@@ -39,7 +40,6 @@ namespace SafeBagDE70
|
||||
{
|
||||
try
|
||||
{
|
||||
InitUsers();
|
||||
CDMSTATE = new CDMSTATE();
|
||||
DeviceStatus = new DeviceStatus
|
||||
{
|
||||
@@ -52,15 +52,25 @@ namespace SafeBagDE70
|
||||
Notes = "",
|
||||
OtherError = 0,
|
||||
};
|
||||
InitUsers();
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "AppInit: "+ex.Message);
|
||||
if(DeviceStatus != null)
|
||||
{
|
||||
DeviceStatus.Description = "Exception in AppInit: "+ex.Message;
|
||||
APIModels.SendEvent(DeviceStatus);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void InitUsers()
|
||||
{
|
||||
try
|
||||
{
|
||||
customerAccounts = new List<CustomerAccount>();
|
||||
using (var context = new CDMDbContext())
|
||||
@@ -80,6 +90,17 @@ namespace SafeBagDE70
|
||||
}
|
||||
CurrentCustomerAccount = customerAccounts[0];
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "InitUsers: " + ex.Message);
|
||||
if (DeviceStatus != null)
|
||||
{
|
||||
DeviceStatus.Description = "Exception in InitUsers: " + ex.Message;
|
||||
APIModels.SendEvent(DeviceStatus);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static CDMSTATE? CDMSTATE = null;
|
||||
private static DateTime CutOffTime = new DateTime(1, 1, 1, 12, 0, 0); // 12:00 noon as cut-off time
|
||||
|
||||
+10
-1
@@ -75,7 +75,7 @@ namespace SafeBagDE70
|
||||
int countTimer = 0;
|
||||
CCmdRsp cCmdRsp = null;
|
||||
bool bInitialized = false;
|
||||
bool bOpenPort = true;
|
||||
bool bOpenPort = false;
|
||||
bool bIsMaintain = false;
|
||||
MainWindow mainWindow = null;
|
||||
Thread thread = null;
|
||||
@@ -117,6 +117,7 @@ namespace SafeBagDE70
|
||||
AppData.IsInTransaction = true;
|
||||
ResetButtons();
|
||||
btnStart.IsEnabled = true;
|
||||
btnLogout.IsEnabled = true;
|
||||
ResetTimers();
|
||||
var state=GetCDMState();
|
||||
if(state.GetSR2()==0x1C)
|
||||
@@ -134,6 +135,8 @@ namespace SafeBagDE70
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if(AppData.DeviceStatus!=null)
|
||||
{
|
||||
AppData.DeviceStatus.CDMStatus = (int)CDMStatusCode.DISCONNECT_SERIALPORT;
|
||||
APIModels.SendEvent(AppData.DeviceStatus);
|
||||
@@ -143,6 +146,8 @@ namespace SafeBagDE70
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void InitSerialPorts()
|
||||
{
|
||||
InitSerialPortDE70();
|
||||
@@ -361,6 +366,8 @@ namespace SafeBagDE70
|
||||
|
||||
var status = printerManager.GetStatus();
|
||||
var strPrinterMessage = "";
|
||||
if(status!=null)
|
||||
{
|
||||
if (status.StsNOPAPER)
|
||||
{
|
||||
AppData.DeviceStatus.PrinterStatus = (int)PrinterStatusCode.PAPEROUT;
|
||||
@@ -379,6 +386,8 @@ namespace SafeBagDE70
|
||||
APIModels.SendEvent(AppData.DeviceStatus);
|
||||
prevPrinterStatus = AppData.DeviceStatus.PrinterStatus;
|
||||
}
|
||||
}
|
||||
|
||||
AppData.DeviceStatus.Description = AppData.CDMSTATE.CDMStatus;
|
||||
AppData.DeviceStatus.DeviceTime = DateTime.Now;
|
||||
APIModels.SendHealthCheck(AppData.DeviceStatus);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Custom.CuCustomWndAPI;
|
||||
using HandyControl.Data;
|
||||
using SafeBagDE70.API;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -23,19 +24,28 @@ namespace SafeBagDE70.Services
|
||||
customWndAPIWrap.InitLibrary();
|
||||
USBDevice[] usbArray = customWndAPIWrap.EnumUSBDevices();
|
||||
dev = customWndAPIWrap.OpenPrinterUSB(usbArray[0]);
|
||||
Log.Information("[PRINTER] Init Printer Successfully");
|
||||
Log.Information("[PRINTER] Khởi tạo thành công");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// System.Windows.MessageBox.Show(ex.ToString());
|
||||
Log.Information("[PRINTER] Không thể khởi tạo máy in");
|
||||
|
||||
AppData.DeviceStatus.PrinterStatus = 3;
|
||||
AppData.DeviceStatus.Description = "[PRINTER] Không thể khởi tạo máy in";
|
||||
APIModels.SendEvent(AppData.DeviceStatus);
|
||||
}
|
||||
}
|
||||
|
||||
public PrinterStatus? GetStatus()
|
||||
{
|
||||
if(dev!=null)
|
||||
{
|
||||
var status = dev.GetPrinterFullStatus();
|
||||
return status;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
public bool IsNearPaperOut()
|
||||
{
|
||||
try
|
||||
|
||||
+18
-25
@@ -1,4 +1,6 @@
|
||||
using CoreScanner;
|
||||
using SafeBagDE70.API;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -16,6 +18,7 @@ using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace SafeBagDE70
|
||||
{
|
||||
@@ -103,31 +106,11 @@ namespace SafeBagDE70
|
||||
}
|
||||
private async void PinCodeButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//var onScreenKeyboardProcess = new ProcessStartInfo("osk.exe")
|
||||
//{
|
||||
// UseShellExecute = true
|
||||
//};
|
||||
try
|
||||
{
|
||||
//var progFiles = @"C:\Program Files\Common Files\Microsoft Shared\ink";
|
||||
//var keyboardPath = System.IO.Path.Combine(progFiles, "TabTip.exe");
|
||||
//Process.Start(keyboardPath);
|
||||
// AutomationElement.FromHandle(-1);
|
||||
|
||||
// string keyboardPath = @"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe";
|
||||
// Process.Start(keyboardPath);
|
||||
//await Launcher.LaunchUriAsync(new Uri("ms-inputapp://"));
|
||||
|
||||
//var onScreenKeyboardProcess = new ProcessStartInfo(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe")
|
||||
//{
|
||||
// UseShellExecute = true
|
||||
//};
|
||||
//Process.Start(onScreenKeyboardProcess);
|
||||
|
||||
QrCodePanel.Visibility = Visibility.Collapsed;
|
||||
PinCodePanel.Visibility = Visibility.Visible;
|
||||
|
||||
|
||||
cCoreScannerClass.BarcodeEvent -= new _ICoreScannerEvents_BarcodeEventEventHandler(OnBarcodeEvent);
|
||||
}
|
||||
catch {
|
||||
@@ -157,13 +140,15 @@ namespace SafeBagDE70
|
||||
int status; // Extended API return code
|
||||
|
||||
cCoreScannerClass.Open(0, scannerTypes, numberOfScannerTypes, out status);
|
||||
|
||||
// Subscribe for barcode events in cCoreScannerClass
|
||||
|
||||
|
||||
short numberOfScanners; // Number of scanners expect to be used
|
||||
int[] connectedScannerIDList = new int[255]; // List of scanner IDs to be returned
|
||||
string outXML;
|
||||
cCoreScannerClass.GetScanners(out numberOfScanners, connectedScannerIDList, out outXML, out status);
|
||||
if (numberOfScanners > 0)
|
||||
{
|
||||
// Let's subscribe for events
|
||||
int opcode = 1001; // Method for Subscribe events
|
||||
string outXML; // XML Output
|
||||
//string outXML; // XML Output
|
||||
string inXML = "<inArgs>" +
|
||||
"<cmdArgs>" +
|
||||
"<arg-int>1</arg-int>" + // Number of events you want to subscribe
|
||||
@@ -173,6 +158,14 @@ namespace SafeBagDE70
|
||||
|
||||
cCoreScannerClass.ExecCommand(opcode, ref inXML, out outXML, out status);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Information("Không tìm thấy đầu đọc QR");
|
||||
AppData.DeviceStatus.OtherError = 1;
|
||||
AppData.DeviceStatus.Description = "Không tìm thấy đầu đọc QR";
|
||||
APIModels.SendEvent(AppData.DeviceStatus);
|
||||
}
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
Console.WriteLine("Something wrong please check... " + exp.Message);
|
||||
|
||||
Reference in New Issue
Block a user