Files
DE70/Services/PrinterManager.cs
T
Nguyen Dinh Thuan 2b4a509e3a try catch Init printer
Đảo thử tự InitUsers
Kiểm tra đầu đọc QR
2024-09-16 15:08:10 +07:00

82 lines
2.2 KiB
C#

using Custom.CuCustomWndAPI;
using HandyControl.Data;
using SafeBagDE70.API;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace SafeBagDE70.Services
{
public class PrinterManager
{
CuCustomWndDevice? dev = null;
CuCustomWndAPIWrap? customWndAPIWrap =null;
PrinterStatus? status = null;
public PrinterManager()
{
try
{
customWndAPIWrap = new CuCustomWndAPIWrap(CuCustomWndAPIWrap.CcwLogVerbosity.CCW_LOG_FATAL, null);
customWndAPIWrap.InitLibrary();
USBDevice[] usbArray = customWndAPIWrap.EnumUSBDevices();
dev = customWndAPIWrap.OpenPrinterUSB(usbArray[0]);
Log.Information("[PRINTER] Khởi tạo thành công");
}
catch (Exception ex)
{
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
{
var status = dev.GetPrinterFullStatus();
return status.StsNEARENDPAP;
}
catch(Exception ex)
{
return true;
}
}
public bool IsPaperOut()
{
try
{
var status = dev.GetPrinterFullStatus();
return status.StsNOPAPER;
}
catch (Exception ex)
{
return true;
}
}
public void Release()
{
if (dev != null)
dev.Terminate();
}
}
}