spc-kiosk-pb/Agent/OLEDevice/DevicePosPrinter.cs
2019-06-16 14:12:09 +09:00

5701 lines
332 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
#define PRT_ERROR //적용시 주석 해제
//출력 할때 마다 open, close 하는 부분 한번만 하도록 수정
//#define PRT_OPENCLOSE //적용시 주석 해제
//전체 버퍼 한번에 출력 하도록 수정
//#define PRT_ALLWRITE //적용시 주석 해제
//프린터 ErrorReceived
//#define PRT_RECVERR //적용시 주석 해제
//Printer Thread Event Wait
//#define PRT_WAITEVENT //적용시 주석 해제
//#20180329 프린터 간헐적 미출력 증상 수정 end
//20180611 프린터 미출력 개선 02Printer.exe start
//O2Printer.exe 통해 프린터 출력
#define PRT_O2PRINTER // 적용시 주석 해제
//20180611 프린터 미출력 개선 02Printer.exe end
using System;
using System.IO;
using System.IO.Ports;
using System.ComponentModel;
using Cosmos.UserFrame;
using Cosmos.BaseFrame;
using Cosmos.Common;
using Cosmos.CommonManager;
using Microsoft.PointOfService;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Runtime.InteropServices;
using System.Threading;
/*-----------------------------------------------------------------------------------------------*/
// 설 명 : PosPrinter 제어
// 작 성 자 :
// 변경 이력 :
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.OLEDevice
{
/// <summary>
/// PosPrinter 제어 CLASS
/// </summary>
public class DevicePosPrinter : IPosPrinterUs
{
public enum Printer_Interface
{
_USB_ = 0,
_COM_,
};
/// <summary>
///
/// </summary>
public enum Barcode_Type
{
_UPC_A_,
_UPC_E_,
_JAN13_EAN13_,
_JAN8_EAN8_,
_CODE39_,
_ITF25_,
_CODABAR_,
_CODE93_, //1~255byte
_CODE128_ //2~255byte
};
/// <summary>
///
/// </summary>
public enum AlignmentR { _Align_left_, _Center_, _Align_right }
/// <summary>
/// 영수증 프린터 오픈 함수
/// </summary>
[DllImport("REXOD_SDK.dll")]
public static extern bool REXOD_Setup_Printer(Printer_Interface nType, int dirverNum, int nbps);
/// <summary>
/// 영수증 프린터 초기화 함수
/// </summary>
[DllImport("REXOD_SDK.dll")]
public static extern int REXOD_Printer_DeInit();
/// <summary>
/// 영수증 프린터 출력 함수
/// </summary>
[DllImport("REXOD_SDK.dll")]
public static extern int REXOD_Print_CharW([MarshalAs(UnmanagedType.LPWStr)] string printData);
/// <summary>
/// 영수증 프린터 enum 함수
/// </summary>
[DllImport("REXOD_SDK.dll")]
public static extern int REXOD_Enum_Printer(Printer_Interface nType, int[] list);
/// <summary>
/// 영수증 프린터 용지 자르기 함수
/// </summary>
[DllImport("REXOD_SDK.dll")]
public static extern int REXOD_Part_Cut();
/// <summary>
/// 영수증 프린터 용지 자르기(전체) 함수
/// </summary>
[DllImport("REXOD_SDK.dll")]
public static extern int REXOD_Full_Cut();
/// <summary>
/// 영수증 프린터 마지막 라인 추가 함수
/// </summary>
[DllImport("REXOD_SDK.dll")]
public static extern int REXOD_Enter_With_nLine(int lineCount);
/// <summary>
/// 영수증 프린터 라인 볼드 처리 함수
/// </summary>
[DllImport("REXOD_SDK.dll")]
public static extern int REXOD_Bold_Word(bool bold);
/// <summary>
/// 영수증 프린터 라인 오른쪽으로 이동 함수
/// </summary>
[DllImport("REXOD_SDK.dll")]
public static extern bool REXOD_Set_This_Line_Start_Position(int leftMargin);
/// <summary>
/// 영수증 프린터 바코드 높이 조절 함수
/// </summary>
[DllImport("REXOD_SDK.dll")]
public static extern bool REXOD_Set_Barcode_Height(byte height);
/// <summary>
/// 영수증 프린터 바코드 출력 함수
/// </summary>
[DllImport("REXOD_SDK.dll")]
public static extern bool REXOD_Print_Barcode(Barcode_Type BarcodeType, byte[] pDate, int DateNum);
/// <summary>
/// 영수증 프린터 바코드 출력 함수
/// </summary>
[DllImport("REXOD_SDK.dll")]
public static extern bool REXOD_Select_Barcode_Alignment(AlignmentR newAlignment);
/// <summary>
///
/// </summary>
/// <param name="newAlignment"></param>
/// <returns></returns>
[DllImport("REXOD_SDK.dll")]
public static extern bool REXOD_Select_Alignment(AlignmentR newAlignment);
/// <summary>
/// 영수증 프린터 이미지 출력 함수
/// </summary>
/// <param name="bitmapImage"></param>
/// <returns></returns>
[DllImport("REXOD_SDK.dll")]
//public static extern bool REXOD_Print_Bitmap(IntPtr bitmapImage);
public static extern bool REXOD_Print_Bitmap(IntPtr bitmapImage);
/// <summary>
/// 영수증 프린터 폰트 2배
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
[DllImport("REXOD_SDK.dll")]
public static extern bool REXOD_Double_Height(bool state);
/// <summary>
/// 영수증 프린터 폰트 2배
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
[DllImport("REXOD_SDK.dll")]
public static extern bool REXOD_Double_Width(bool state);
private enum BarcodeType { CODE93, CODE128 };
private enum Alignment { CENTER, LEFT, RIGHT };
private enum HRIPosition { NO_PRINT, ABOVE, BELOW, ABOVE_BELOW };
/// <summary>
/// StateServer Object (StateServer 객체)
/// </summary>
public StateServer StateObject = (StateServer)StateServer.GetInstance();
/// <summary>
/// Device 상태 정보 객체
/// </summary>
public DeviceStatus devStatus = null;
public PosStatus m_cPosStatus = null;
/// <summary>
/// Posfor.Net PosPrinter 객체
/// </summary>
private PosPrinter posprinter = null;
/// <summary>
/// Pos for .Net의 Device 정보를 가져오기 위한 객체
/// </summary>
private PosExplorer posExplorer = null;
/// <summary>
/// StatusUpdateEvent의 Status 정보 저장
/// </summary>
private int m_sUpdateStatus = 0;
///// <summary>
///// Bitmap 상단 Logo 설정 성공 여부 플래그
///// <para>true:SetBitmap성공, false:SetBitmap실패</para>
///// </summary>
//private bool SetTopLogo = false;
///// <summary>
///// Bitmap 하단 Logo 설정 성공 여부 플래그
///// <para>true:SetBitmap성공, false:SetBitmap실패</para>
///// </summary>
//private bool SetBottomLogo = false;
///// <summary>
///// ErrorEvent의 Error응답 정보 저장
///// </summary>
//private ErrorResponse m_sErrorResponse;
/// <summary>
/// RS232통신을 위한 시리얼포트 객체
/// </summary>
private SerialPort m_serialPort = null;
private BackgroundWorker bw = null;
// Printer Status/Error 응답 이벤트
private string DELIMETER = "^:|";
private bool m_bFreeEvents;
public bool FreeEvents
{
get { return m_bFreeEvents; }
set { m_bFreeEvents = value; }
}
/// <summary>
/// Printer Daemon 작동 여부
/// </summary>
private bool m_PrinterDaemonRunning = true;
/// <summary>
/// Printer Daemon Thread
/// </summary>
private Thread m_tPrtDaemon = null;
/// <summary>
/// Thread Waiting Time(스레드 대기시간)
/// </summary>
private int m_ThreadSleepTerm = 1000;
private static ArrayList m_PrtBuffer;
private const string CMD_OPEN_CASHDRAWER = "_OPEN_A_CASHDRAWER_";
//20180611 프린터 미출력 개선 02Printer.exe start
//변경
#if(PRT_O2PRINTER)
int lRecvLen = 20;
byte[] bytRecvBuff = new byte[1024];
int lTimeout = 1000;
private TcpSocket m_cPrtSocket = null;
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
#if(PRT_WAITEVENT)
private AutoResetEvent m_AutoResetEvent = null;
#endif
/// <summary>
/// 생성자
/// </summary>
public DevicePosPrinter()
{
try
{
try
{
#if(PRT_WAITEVENT)
// TEST::Printer Thread Event Wait
m_AutoResetEvent = new AutoResetEvent(false);
#endif
posExplorer = new PosExplorer();
}
catch (Exception ex) { }
devStatus = (DeviceStatus)StateObject.DEVICE;
m_cPosStatus = (PosStatus)StateObject.POS;
DeviceStatusInit();
bw = new BackgroundWorker();
}
catch(Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
/// <summary>
/// Printer StateServer 정보 초기화
/// </summary>
private void DeviceStatusInit()
{
devStatus.Printer.TopLogoFileName = "";
devStatus.Printer.BottomLogoFileName = "";
devStatus.Printer.DeviceName = "";
devStatus.Printer.Status = "";
devStatus.Printer.ErrorStatus = "";
devStatus.Printer.Open = false;
}
#region PrinterDaemon Start/Stop
/// <summary>
/// Printer Daemon Start
/// </summary>
public void StartPrinterDaemon()
{
try
{
m_PrtBuffer = new ArrayList();
m_tPrtDaemon = new Thread(new ThreadStart(ThreadPrtDaemonRun));
m_PrinterDaemonRunning = true;
m_tPrtDaemon.Start();
}
catch(Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
/// <summary>
/// Printer Daemon Stop
/// </summary>
public void StopPrinterDaemon()
{
try
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Printer Daemon Stop!!!");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Printer Daemon Stop!!!");
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Printer Daemon Stop!!!");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
// 통신서버 Send Terminated (SC Send 종료)
m_PrinterDaemonRunning = false;
#if(PRT_WAITEVENT)
m_AutoResetEvent.Set();
#endif
int count = 0;
//while (count < 10)
while (count < 5)
{
if (m_tPrtDaemon != null && m_tPrtDaemon.IsAlive) m_PrinterDaemonRunning = false;
else break;
count++;
Thread.Sleep(300);
}
if (count >= 10)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Force Printer Daemon Stop!!!");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Force Printer Daemon Stop!!!");
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Force Printer Daemon Stop!!!");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
m_tPrtDaemon.Abort();
}
}
catch (Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
#endregion PrinterThread Start/Stop
#region Printer Buffer
/// <summary>
/// Printer Buffer 초기화
/// </summary>
public void PrinterBufferClear()
{
try
{
m_PrtBuffer.Clear();
}
catch (Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :"+ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :"+ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
public ArrayList GetPrinterBuffer()
{
return m_PrtBuffer;
}
public void AddToPrinterBuffer(byte[] arData)
{
try
{
m_PrtBuffer.Add(arData);
#if(PRT_WAITEVENT)
m_AutoResetEvent.Set();
#endif
}
catch (Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :"+ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :"+ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
#endregion
#region Printer Daemon Main
/// <summary>
/// Printer Daemon Run
/// </summary>
private void ThreadPrtDaemonRun()
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//출력 할때 마다 open, close 하는 부분 한번만 하도록 수정
#if(PRT_OPENCLOSE) //프린터 포트 동작 변경시
bool bClsRet = false;
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
bool bRet = false;
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Printer Daemon Run!!");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Printer Daemon Run!!");
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Printer Daemon Run!!");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
while(m_PrinterDaemonRunning)
{
try
{
#if(PRT_WAITEVENT)
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"▶▶▶ Printer Device Thread Event WaitOne ");
m_AutoResetEvent.WaitOne();
m_AutoResetEvent.Reset();
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"▶▶▶ Printer Device Thread Event Run ");
#endif
ArrayList alBuffer = GetPrinterBuffer();
if(alBuffer.Count > 0)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Prineter Buffer Count : " + alBuffer.Count);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Prineter Buffer Count : " + alBuffer.Count);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Prineter Buffer Count : " + alBuffer.Count);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
bRet = OpenDevice(PosConst.OPOS_DEVICE.POSPRINTER, PosConst.OPOS_LDN.POSPRINTER);
if( bRet == false)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Failed to open printer device ...");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Failed to open printer device ...");
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Failed to open printer device ...");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
System.Threading.Thread.Sleep(100);
if (devStatus.Printer.Open == true)
{
//MemoryStream stream = new MemoryStream();
//BinaryWriter bw = new BinaryWriter(stream);
bool bCheckPrinter = true;
//#20171212 프린터 상태 체크 여부 추가 start
//0: 체크, 1: 체크안함
//기존
/*
if (m_cPosStatus.Base.OlePosPrinterModel == PosConst.POS_DEVICE_LIST.POS_PRINTER._1_EPSON)
{
bCheckPrinter = CheckPrinter();
}
*/
//변경
if (m_cPosStatus.Base.OlePosPrinterModel == PosConst.POS_DEVICE_LIST.POS_PRINTER._1_EPSON &&
m_cPosStatus.Base.OlePosPrinterCheckYn == "0")
{
bCheckPrinter = CheckPrinter();
}
//#20171212 프린터 상태 체크 여부 추가 end
//if (CheckPrinter() == true)
if(bCheckPrinter == false)
{
//프린터 상태 체크 실패 시에도 Port Close(20170508-조충연K)
WinManager.ConfirmMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0691));
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"CheckPrinter() Failed...");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"CheckPrinter() Failed...");
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"CheckPrinter() Failed...");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
//else
//{
//헬스체크 후 응답값과 상관없이 프린트 출력업무 수행.
for (int nBufCnt = 0; nBufCnt < alBuffer.Count; nBufCnt++)
{
if (devStatus.Printer.Open == false) break;
byte[] arPrtData = (byte[])alBuffer[nBufCnt];
//#20180123 프린터 다운 현상 관련 로그 추가 start
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Prineter nBufCnt : " + nBufCnt);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Prineter nBufCnt : " + nBufCnt);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Prineter nBufCnt : " + nBufCnt);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
//#20180123 프린터 다운 현상 관련 로그 추가 end
if (Encoding.UTF8.GetString(arPrtData).Equals(CMD_OPEN_CASHDRAWER) == true)
{
switch (m_cPosStatus.Base.OlePosPrinterModel)
{
case PosConst.POS_DEVICE_LIST.POS_PRINTER._1_EPSON:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._6_P2C:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._7_1NR://2018.01.22;"7:4610_1NR" 모델 추가, 처리는 _1_EPSON 과 동일;girak.kim
default:
//bw.Write(PosConst.ESCP_COMMAND.OPEN_CASHDRAWER);
TransmitCommand(PosConst.ESCP_COMMAND.OPEN_CASHDRAWER);
break;
case PosConst.POS_DEVICE_LIST.POS_PRINTER._2_TOSHIBA:
//bw.Write(PosConst.ESCP_COMMAND.OPEN_CASHDRAWER_FOR_TOSHIBA);
TransmitCommand(PosConst.ESCP_COMMAND.OPEN_CASHDRAWER_FOR_TOSHIBA);
break;
}
}
else
{
//bw.Write(arPrtData);
//bw.Write(string.Format("{0}{1}", (char)13, (char)10));
TransmitCommand(arPrtData);
}
}
//}
//bw.Flush();
//TransmitCommand(stream.ToArray());
PrinterBufferClear();
}
//#20180329 프린터 간헐적 미출력 증상 수정 start
//출력 할때 마다 open, close 하는 부분 한번만 하도록 수정
//기존
/*
bRet = CloseDevice();
if(bRet == false)
{
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Failed to close printer device ...");
}
*/
//변경
#if(PRT_OPENCLOSE) //프린터 포트 동작 변경시
#else
bRet = CloseDevice();
if(bRet == false)
{
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Failed to close printer device ...");
}
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
#if(PRT_WAITEVENT)
#else
int nNowSleepTerm = 0;
while (nNowSleepTerm < m_ThreadSleepTerm)
{
if (m_PrinterDaemonRunning == false) break;
Thread.Sleep(100);
nNowSleepTerm += 100;
}
#endif
}
catch(Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Printer Daemon Exception : " + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Printer Daemon Exception : " + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Printer Daemon Exception : " + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Printer Daemon Exit!!");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Printer Daemon Exit!!");
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Printer Daemon Exit!!");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
//#20180329 프린터 간헐적 미출력 증상 수정 start
//출력 할때 마다 open, close 하는 부분 한번만 하도록 수정
#if(PRT_OPENCLOSE) //프린터 포트 동작 변경시
bClsRet = CloseDevice();
if (bClsRet == false)
{
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Failed to close printer device ...");
}
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
#endregion
#region Convert Graysacle Image
[DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("user32.dll")]
public static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);
[DllImport("gdi32.dll")]
public static extern int DeleteDC(IntPtr hdc);
[DllImport("gdi32.dll")]
public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
[DllImport("gdi32.dll")]
public static extern int BitBlt(IntPtr hdcDst, int xDst, int yDst, int w, int h, IntPtr hdcSrc, int xSrc, int ySrc, int rop);
static int SRCCOPY = 0x00CC0020;
[DllImport("gdi32.dll")]
static extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPINFO bmi, uint Usage, out IntPtr bits, IntPtr hSection, uint dwOffset);
static uint BI_RGB = 0;
static uint DIB_RGB_COLORS = 0;
[StructLayout(LayoutKind.Sequential)]
private struct BITMAPINFO
{
public uint biSize;
public int biWidth, biHeight;
public short biPlanes, biBitCount;
public uint biCompression, biSizeImage;
public int biXPelsPerMeter, biYPelsPerMeter;
public uint biClrUsed, biClrImportant;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
public uint[] cols;
}
#endregion
#region OPEN/RESET/CLOSE
/// <summary>
/// 디바이스 Open시 처리함수
/// </summary>
/// <param name="sDeviceType">장비종류(ex- "Msr","PosPrinter","Scanner"...)</param>
/// <param name="sLogicalName">레지스트리 항목(ex- "DefaultMsr","DefaultPosPrinter","DefaultScanner"...)</param>
/// <returns></returns>
public bool OpenDevice(string sDeviceType, string sLogicalName)
{
bool bRet = false;
try
{
if (devStatus.Printer.UseYn == false)
{
return bRet;
}
switch(m_cPosStatus.Base.OlePosPrinterController)
{
case PosConst.POS_DEVICE_CONTROLLER.OPOS:
bRet = OpenDeviceByOPOS(sDeviceType, sLogicalName);
break;
case PosConst.POS_DEVICE_CONTROLLER.RS232:
bRet = OpenDeviceByRS232(m_cPosStatus.Base.OlePosPrinterSerialPortNumber, m_cPosStatus.Base.OlePosPrinterSerialBaudRate);
break;
}
}
catch(Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
return bRet;
}
/// <summary>
/// OPOS사용 디바이스 Open시 처리함수
/// </summary>
/// <param name="sDeviceType">장비종류(ex- "Msr","PosPrinter","Scanner"...)</param>
/// <param name="sLogicalName">레지스트리 항목(ex- "DefaultMsr","DefaultPosPrinter","DefaultScanner"...)</param>
/// <returns></returns>
public bool OpenDeviceByOPOS(string sDeviceType, string sLogicalName)
{
bool bRet = false;
//SetTopLogo = false;
//SetBottomLogo = false;
try
{
if(devStatus.Printer.Open == true)
{
return true;
}
DeviceInfo devinfo = null;
if (sDeviceType == DeviceType.PosPrinter && sLogicalName == PosConst.OPOS_LDN.POSPRINTER)
devinfo = posExplorer.GetDevice(DeviceType.PosPrinter, PosConst.OPOS_LDN.POSPRINTER);
else
{
devStatus.Printer.Open = false;
devStatus.Printer.Status = "DEVICE INFO ERROR";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return bRet;
}
if (devinfo == null)
{
devStatus.Printer.Open = false;
devStatus.Printer.Status = "DEVICE INFO ERROR";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return bRet;
}
posprinter = (PosPrinter)posExplorer.CreateInstance(devinfo);
if (posprinter != null)
{
posprinter.StatusUpdateEvent += new StatusUpdateEventHandler(Printer_StatusUpdateEvent);
posprinter.ErrorEvent += new DeviceErrorEventHandler(Printer_ErrorEvent);
try
{
posprinter.Open();
}
catch (Exception ex)
{
devStatus.Printer.Status = "OPEN FAIL";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"Exception :" + "DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return bRet;
}
try
{
posprinter.Claim(1000);
}
catch (Exception ex)
{
devStatus.Printer.Status = "CLAIM FAIL";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"Exception :" + "DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return bRet;
}
try
{
posprinter.DeviceEnabled = true;
}
catch (Exception ex)
{
devStatus.Printer.Status = "DEVICE ENABLED FAIL";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"Exception :" + "DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return bRet;
}
try
{
posprinter.AsyncMode = true;
posprinter.RecLineChars = 42;
posprinter.RecLetterQuality = true;
posprinter.RecLineSpacing = 20;
}
catch (Exception ex)
{
devStatus.Printer.Status = "RecLetterQuality 설정 Fail";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"Exception :" + "DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", devStatus.Printer.Status);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return bRet;
}
devStatus.Printer.DeviceName = devinfo.ServiceObjectName;
devStatus.Printer.Open = true;
devStatus.Printer.Status = "SUCCESS";
devStatus.Printer.ErrorStatus = "OK";
bw.DoWork += OlePosHandler;
bRet = true;
}
}
catch (Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"Exception :" + "DevicePosPrinter.OpenDeviceByOPOS()", ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.ERROR_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.OpenDeviceByOPOS()", ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
devStatus.Printer.Open = false;
devStatus.Printer.Status = "DEVICE OPEN EXCEPTION";
bRet = false;
}
return bRet;
}
/// <summary>
/// RS232사용 디바이스 Open시 처리함수
/// </summary>
/// <param name="sSerialPort">SerialPort 번호</param>
/// <param name="lBaudrate">Baudrate</param>
/// <returns></returns>
public bool OpenDeviceByRS232(string sSerialPort, long lBaudrate)
{
bool bRet = false;
try
{
//20180611 프린터 미출력 개선 02Printer.exe start
//변경
#if(PRT_O2PRINTER)
int iRet = OpenPrtTcpDevice("127.0.0.1", 9110);
if (iRet == UserCom.OK)
{
devStatus.Printer.Open = true;
devStatus.Printer.Status = "SUCCESS";
devStatus.Printer.ErrorStatus = "OK";
ResetDevice();
bRet = true;
}
else
{
devStatus.Printer.Open = false;
devStatus.Printer.Status = "TCP CONNECT ERROR";
bRet = false;
}
return bRet;
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
//#20180329 프린터 간헐적 미출력 증상 수정 start
//출력 할때 마다 open, close 하는 부분 한번만 하도록 수정
//기존
/*
if (m_serialPort != null)
{
// add by wani(20170914) - Serial Port Close 보완(Buffer 초기화 추가)
m_serialPort.DiscardInBuffer();
m_serialPort.DiscardOutBuffer();
m_serialPort.Close();
m_serialPort.Dispose();
System.Threading.Thread.Sleep(50);
m_serialPort = null;
}
*/
//변경
#if(PRT_OPENCLOSE) //프린터 포트 동작 변경시
if (m_serialPort != null)
{
if (m_serialPort.IsOpen == false)
{
// add by wani(20170914) - Serial Port Close 보완(Buffer 초기화 추가)
m_serialPort.DiscardInBuffer();
m_serialPort.DiscardOutBuffer();
m_serialPort.Close();
m_serialPort.Dispose();
System.Threading.Thread.Sleep(50);
m_serialPort = null;
}
else
{
bRet = true;
return bRet;
}
}
#else
if (m_serialPort != null)
{
// add by wani(20170914) - Serial Port Close 보완(Buffer 초기화 추가)
m_serialPort.DiscardInBuffer();
m_serialPort.DiscardOutBuffer();
m_serialPort.Close();
m_serialPort.Dispose();
System.Threading.Thread.Sleep(50);
m_serialPort = null;
}
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
if( m_serialPort == null )
{
//m_serialPort = new SerialPort(m_cPosStatus.Base.OlePosPrinterSerialPortNumber, (int)m_cPosStatus.Base.OlePosPrinterSerialBaudRate);
m_serialPort = new SerialPort();
if (m_serialPort == null)
{
devStatus.Printer.Open = false;
devStatus.Printer.Status = "SERIAL PORT ERROR";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.WARNING_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
devStatus.Printer.Status);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.WARNING_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
devStatus.Printer.Status);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.WARNING_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
devStatus.Printer.Status);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return bRet;
}
//m_serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);
//m_serialPort.PinChanged += new SerialPinChangedEventHandler(serialPort_PinChanged);
//m_serialPort.ErrorReceived += new SerialErrorReceivedEventHandler(serialPort_ErrorReceived);
m_serialPort.NewLine = "\r\n";
m_serialPort.Encoding = System.Text.Encoding.GetEncoding("ks_c_5601-1987");
//#20180329 프린터 간헐적 미출력 증상 수정 start
//전체 버퍼 한번에 출력 하도록 수정
#if(PRT_ALLWRITE) //프린터 포트 동작 변경시
m_serialPort.WriteBufferSize = 1024 * 10;
#else
m_serialPort.WriteBufferSize = 1024 * 3;
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
m_serialPort.PortName = sSerialPort;
m_serialPort.BaudRate = (int)lBaudrate;
m_serialPort.DataBits = 8;
m_serialPort.StopBits = StopBits.One;
m_serialPort.Parity = Parity.None;
//#20170808 프린터 출력 안되는 현상 수정 start
//특정 케이블에 따라 출력이 안되는 현상이 있음 전부 Handshake.none로 처리
//적용시 변경 소스로 적용
//기존
/*
if (m_cPosStatus.Base.OlePosPrinterModel == PosConst.POS_DEVICE_LIST.POS_PRINTER._6_P2C)
{
m_serialPort.Handshake = Handshake.None;
}
else
{
m_serialPort.Handshake = Handshake.RequestToSend;
}
*/
//변경
m_serialPort.Handshake = Handshake.None;
//#20170808 프린터 출력 안되는 현상 수정 end
// 프린터 NV메모리에 upload 하기 위해 WriteTimeout 값이 10초 이상 되어야 함
m_serialPort.ReadTimeout = 10000;
m_serialPort.WriteTimeout = 10000;
m_serialPort.RtsEnable = true;
m_serialPort.DtrEnable = true;
FreeEvents = false;
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"[1] Before opening port");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"[1] Before opening port");
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"[1] Before opening port");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
//#20180329 프린터 간헐적 미출력 증상 수정 start
#if(PRT_ERROR) //프린터 포트 동작 변경시
m_serialPort.Close();
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
m_serialPort.Open();
//#20180316 프린터 출력 안되는 증상 - 포트 오픈, 리셋 후 sleep 추가 start
//#20180402 프린터 출력 안되는 점포 증가로 해당 sleep 소스 주석 start
//System.Threading.Thread.Sleep(100);
//#20180402 프린터 출력 안되는 점포 증가로 해당 sleep 소스 주석 end
//#20180316 프린터 출력 안되는 증상 - 포트 오픈, 리셋 후 sleep 추가 end
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"[2] After opening port");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"[2] After opening port");
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"[2] After opening port");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
if (m_serialPort.IsOpen == false)
{
devStatus.Printer.Open = false;
devStatus.Printer.Status = "SERIAL PORT OPEN ERROR";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.WARNING_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
devStatus.Printer.Status);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.WARNING_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
devStatus.Printer.Status);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.WARNING_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
devStatus.Printer.Status);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return bRet;
}
ResetDevice();
devStatus.Printer.Open = true;
devStatus.Printer.Status = "SUCCESS";
devStatus.Printer.ErrorStatus = "OK";
bw.DoWork += OlePosHandler;
bRet = true;
}
else
{
devStatus.Printer.Open = false;
devStatus.Printer.Status = "SERIAL PORT ERROR";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.WARNING_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
devStatus.Printer.Status);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.WARNING_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
devStatus.Printer.Status);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.WARNING_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
devStatus.Printer.Status);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return bRet;
}
}
catch(Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception : "+ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception : " + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception : "+ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
return bRet;
}
/// <summary>
/// 디바이스 Rest시 처리함수
/// </summary>
public void ResetDevice()
{
try
{
switch (m_cPosStatus.Base.OlePosPrinterModel)
{
case PosConst.POS_DEVICE_LIST.POS_PRINTER._1_EPSON:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._2_TOSHIBA:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._7_1NR://2018.01.22;"7:4610_1NR" 모델 추가, 처리는 _1_EPSON 과 동일;girak.kim
TransmitCommand(PosConst.ESCP_COMMAND.INITIALIZE_PRINTER);
break;
case PosConst.POS_DEVICE_LIST.POS_PRINTER._3_IBM:
//20180611 프린터 미출력 개선 02Printer.exe start
//변경
#if(PRT_O2PRINTER)
TransmitCommand(new byte[] { (byte)0x1B, (byte)0x31,
(byte)0x1B, (byte)0x20, (byte)0x03,
(byte)0x1B, (byte)0x33, (byte)10, // 라인간격
(byte)0x1B, (byte)0x25, (byte)0x00, // Double Byte Mode
(byte)0x1B, (byte)0x20, (byte)3, // 글자간 간격
(byte)0x1B, (byte)0x54, (byte)6 });
//기존
#else
TransmitCommand(new byte[] { (byte)0x1B, (byte)0x31 });
TransmitCommand(new byte[] { (byte)0x1B, (byte)0x20, (byte)0x03 }); // 글자간 간격
TransmitCommand(new byte[] { (byte)0x1B, (byte)0x33, (byte)10 }); // 라인간격
TransmitCommand(new byte[] { (byte)0x1B, (byte)0x25, (byte)0x00 }); // Double Byte Mode
TransmitCommand(new byte[] { (byte)0x1B, (byte)0x20, (byte)3 }); //
TransmitCommand(new byte[] { (byte)0x1B, (byte)0x54, (byte)6 });
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
break;
default:
break;
}
}
catch(Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
/// <summary>A
/// 디바이스 Close시 처리함수
/// </summary>
/// <returns></returns>
public bool CloseDevice()
{
bool bRet = false;
try
{
switch(m_cPosStatus.Base.OlePosPrinterController)
{
case PosConst.POS_DEVICE_CONTROLLER.OPOS:
bRet = CloseDeviceByOPOS();
bRet = true;
break;
case PosConst.POS_DEVICE_CONTROLLER.RS232:
bRet = CloseDeviceByRS232();
break;
}
}
catch (Exception ex)
{
devStatus.Printer.Status = "CLOSE EXCEPTION";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
return bRet;
}
/// <summary>
/// OPOS사용 디바이스 Close시 처리함수
/// </summary>
public bool CloseDeviceByOPOS()
{
bool bRet = false;
try
{
if (posprinter == null)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.CloseDeviceByOPOS()", "posprinter == null");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.CloseDeviceByOPOS()", "posprinter == null");
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.CloseDeviceByOPOS()", "posprinter == null");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return bRet;
}
posprinter.DeviceEnabled = false;
posprinter.Release();
posprinter.Close();
bRet = true;
posprinter = null;
devStatus.Printer.Status = "CLOSE";
devStatus.Printer.Open = false;
//SetTopLogo = false;
//SetBottomLogo = false;
bw.DoWork -= OlePosHandler;
}
catch (Exception ex)
{
devStatus.Printer.Status = "CLOSE EXCEPTION";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
return bRet;
}
/// <summary>
/// RS232사용 디바이스 Close시 처리함수
/// </summary>
public bool CloseDeviceByRS232()
{
bool bRet = false;
bool PortOpenResult = false;
try
{
//20180611 프린터 미출력 개선 02Printer.exe start
//변경
#if(PRT_O2PRINTER)
devStatus.Printer.Status = "CLOSE";
devStatus.Printer.Open = false;
return true;
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
if (m_serialPort == null)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.CloseDeviceByRS232()", "m_serialPort == null");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.CloseDeviceByRS232()", "m_serialPort == null");
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.CloseDeviceByRS232()", "m_serialPort == null");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return bRet;
}
// add by wani(20170914) - Serial Port Close 보완(Buffer 초기화 추가)
m_serialPort.DiscardInBuffer();
m_serialPort.DiscardOutBuffer();
m_serialPort.Close();
System.Threading.Thread.Sleep(100);
PortOpenResult = m_serialPort.IsOpen;
if (PortOpenResult.Equals(true))
{
m_serialPort.Close();
System.Threading.Thread.Sleep(100);
}
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SerialPort.IsOpen => " + PortOpenResult.ToString());
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SerialPort.IsOpen => " + PortOpenResult.ToString());
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SerialPort.IsOpen => " + PortOpenResult.ToString());
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
m_serialPort.Dispose();
bRet = true;
m_serialPort = null;
devStatus.Printer.Status = "CLOSE";
devStatus.Printer.Open = false;
//SetTopLogo = false;
//SetBottomLogo = false;
bw.DoWork -= OlePosHandler;
}
catch(Exception ex)
{
devStatus.Printer.Status = "CLOSE EXCEPTION";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
return bRet;
}
#endregion
#region Printer check
/// <summary>
/// Enable transmission of automatic status.
/// </summary>
/// <returns></returns>
public bool CheckPrinter()
{
bool bRet = false;
string sTemp = "";
int nLen = 0;
string sResp = "";
byte[] bytReadData;
try
{
if (m_cPosStatus.Base.OlePosPrinterModel == PosConst.POS_DEVICE_CONTROLLER.RS232)
{
switch (m_cPosStatus.Base.OlePosPrinterModel)
{
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._1_TM_T88II:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._2_TM_T88III:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._3_TM_T88IV:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._4_TM_T88V:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._8_SRP_352PLUSIII:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._1_EPSON:
if (devStatus.Printer.Open == false)
{
if (OpenDevice(PosConst.OPOS_DEVICE.POSPRINTER, PosConst.OPOS_LDN.POSPRINTER) == false) return bRet;
}
bytReadData = new byte[1];
//20180611 프린터 미출력 개선 02Printer.exe start
//기존
#if(PRT_O2PRINTER)
#else
if (m_serialPort != null && m_serialPort.IsOpen == true)
{
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
// 프린터 초기화
TransmitCommand(PosConst.ESCP_COMMAND.INITIALIZE_PRINTER, false);
System.Threading.Thread.Sleep(10);
// Cover Check
//20180611 프린터 미출력 개선 02Printer.exe start
//기존
#if(PRT_O2PRINTER)
#else
TransmitCommand(PosConst.ESCP_COMMAND.TRANSMIT_OFFLINE_STATUS, false);
#endif
//변경
#if(PRT_O2PRINTER)
TransmitCommand(PosConst.ESCP_COMMAND.TRANSMIT_OFFLINE_STATUS, false, true);
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
System.Threading.Thread.Sleep(70);
#region
//sResp = m_serialPort.ReadExisting();
//if (sResp.Length > 0)
//{
// byte[] respByte = Encoding.Default.GetBytes(sResp);
// if (respByte[0] == PosConst.ESCP_COMMAND.STATUS_OK[0])
// {
// bRet = true;
// }
// else
// {
// return bRet;
// }
//}
//else
//{
// return bRet;
//}
#endregion
//20180611 프린터 미출력 개선 02Printer.exe start
//기존
#if(PRT_O2PRINTER)
#else
m_serialPort.Read(bytReadData, 0, 1);
if (bytReadData.Length > 0)
{
if (bytReadData[0] == PosConst.ESCP_COMMAND.STATUS_OK[0])
{
bRet = true;
}
else
{
return bRet;
}
}
else
{
return bRet;
}
#endif
//변경
#if(PRT_O2PRINTER)
if (bytRecvBuff.Length > 0)
{
if (bytRecvBuff[12] == PosConst.ESCP_COMMAND.STATUS_OK[0])
{
bRet = true;
}
else
{
return bRet;
}
}
else
{
return bRet;
}
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
// Paper Check
//20180611 프린터 미출력 개선 02Printer.exe start
//기존
#if(PRT_O2PRINTER)
#else
TransmitCommand(PosConst.ESCP_COMMAND.TRANSMIT_CONTINUOUS_PAPER_DETECTOR_STATUS, false);
#endif
//변경
#if(PRT_O2PRINTER)
TransmitCommand(PosConst.ESCP_COMMAND.TRANSMIT_CONTINUOUS_PAPER_DETECTOR_STATUS, false, true);
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
System.Threading.Thread.Sleep(70);
#region
//sResp = m_serialPort.ReadExisting();
//if (sResp.Length > 0)
//{
// byte[] respByte = Encoding.Default.GetBytes(sResp);
// if (respByte[0] == PosConst.ESCP_COMMAND.STATUS_OK[0])
// {
// bRet = true;
// }
// else
// {
// //bRet = false;
// string NEAR_END = Encoding.Default.GetString(new byte[] { 0x1E });
// string NOT_PRESENT = Encoding.Default.GetString(new byte[] { 0x72 });
// string sErrMsg = string.Empty;
// if (sResp == NEAR_END)
// {
// bRet = true;
// sErrMsg = "Local Printer : RECEIPT_PAPER_NEAR_END";
// }
// else if (sResp == NOT_PRESENT) sErrMsg = "Local Printer : RECEIPT_PAPER_NOT_PRESENT";
// else sErrMsg = "Local Printer : ETC_ERROR";
// UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
// System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
// System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
// sErrMsg);
// }
//}
//else
//{
// return bRet;
//}
#endregion
//20180611 프린터 미출력 개선 02Printer.exe start
//기존
#if(PRT_O2PRINTER)
#else
m_serialPort.Read(bytReadData, 0, 1);
if (bytReadData.Length > 0)
{
if (bytReadData[0] == PosConst.ESCP_COMMAND.STATUS_OK[0])
{
bRet = true;
}
else
{
string NEAR_END = Encoding.Default.GetString(new byte[] { 0x1E });
string NOT_PRESENT = Encoding.Default.GetString(new byte[] { 0x72 });
string sReadData = Encoding.Default.GetString(bytReadData);
string sErrMsg = string.Empty;
if (sReadData == NEAR_END)
{
bRet = true;
sErrMsg = "Local Printer : RECEIPT_PAPER_NEAR_END";
}
else if (sReadData == NOT_PRESENT) sErrMsg = "Local Printer : RECEIPT_PAPER_NOT_PRESENT";
else sErrMsg = "Local Printer : ETC_ERROR";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
sErrMsg);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
sErrMsg);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
sErrMsg);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
else
{
return bRet;
}
#endif
//변경
#if(PRT_O2PRINTER)
if (bytRecvBuff.Length > 0)
{
if (bytRecvBuff[12] == PosConst.ESCP_COMMAND.STATUS_OK[0])
{
bRet = true;
}
else
{
string NEAR_END = Encoding.Default.GetString(new byte[] { 0x1E });
string NOT_PRESENT = Encoding.Default.GetString(new byte[] { 0x72 });
string sReadData = Encoding.Default.GetString(bytRecvBuff);
string sErrMsg = string.Empty;
if (sReadData == NEAR_END)
{
bRet = true;
sErrMsg = "Local Printer : RECEIPT_PAPER_NEAR_END";
}
else if (sReadData == NOT_PRESENT) sErrMsg = "Local Printer : RECEIPT_PAPER_NOT_PRESENT";
else sErrMsg = "Local Printer : ETC_ERROR";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
sErrMsg);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
sErrMsg);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." +
System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
sErrMsg);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
else
{
return bRet;
}
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
#region
//if (sResp.Length > 0)
//{
// byte[] respByte = Encoding.Default.GetBytes(sResp);
// if (respByte[0] == PosConst.ESCP_COMMAND.STATUS_OK[1])
// {
// bRet = true;
// }
// else
// {
// return bRet;
// }
//}
//else
//{
// return bRet;
//}
#endregion
//20180611 프린터 미출력 개선 02Printer.exe start
//기존
#if(PRT_O2PRINTER)
#else
}
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
break;
#region
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._2_TOSHIBA:
// // Cover Check
// TransmitCommand(PosConst.ESCP_COMMAND.TRANSMIT_OFFLINE_STATUS, false);
// System.Threading.Thread.Sleep(100);
// sResp = m_serialPort.ReadExisting();
// if (sResp.Length > 0)
// {
// byte[] respByte = Encoding.Default.GetBytes(sResp);
// if (respByte[0] == PosConst.ESCP_COMMAND.STATUS_OK[0])
// {
// bRet = true;
// }
// else
// {
// return bRet;
// }
// }
// else
// {
// return bRet;
// }
// break;
#endregion
default:
bRet = true;
break;
}
}
}
catch(Exception ex)
{
devStatus.Printer.Status = "Status Check Error";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
return bRet;
}
//private int IsPrinterStatusOK()
//{
// int iReturn = UserCom.NG;
// byte[] bytReadData;
// string sReadData;
// BitArray arBit = null;
// try
// {
// switch(m_cPosStatus.Base.OlePosPrinterModel)
// {
// case PosConst.POS_DEVICE_LIST.POS_PRINTER._7_TRST_A00:
// if (m_serialPort != null && m_serialPort.IsOpen == true)
// {
// FreeEvents = true;
// bytReadData = new byte[1];
// // 프린터 초기화
// TransmitCommand(PosConst.ESCP_COMMAND.INITIALIZE_PRINTER, false);
// System.Threading.Thread.Sleep(10);
// // To check whether ONLINE or OFFLINE
// //TransmitCommand(PosConst.ESCP_COMMAND.TRANSMIT_PRINTER_STATUS);
// //sReadData = m_serialPort.ReadExisting();
// ////m_serialPort.Read(bytReadData, 0, 1);
// ////arBit = new BitArray(bytReadData);
// //arBit = new BitArray(Encoding.Default.GetBytes(sReadData));
// //// ONLINE/ONFFLINE Status(ONLINE : 0, OFFLINE : 1)
// //if(arBit[3] == true)
// //{
// // return UserCom.NG1;
// //}
// // To check cover status
// TransmitCommand(PosConst.ESCP_COMMAND.TRANSMIT_OFFLINE_STATUS);
// m_serialPort.Read(bytReadData, 0, 1);
// arBit = new BitArray(bytReadData);
// // Cover Status(Closed : 0, Open : 1)
// if(arBit[2] == true)
// {
// return UserCom.NG2;
// }
// // To check paper out status
// TransmitCommand(PosConst.ESCP_COMMAND.TRANSMIT_CONTINUOUS_PAPER_DETECTOR_STATUS);
// m_serialPort.Read(bytReadData, 0, 1);
// // Paper out sensor(Has paper : 0, Paper Out : 1)
// if(arBit[5] == true)
// {
// return UserCom.NG3;
// }
// iReturn = UserCom.OK;
// FreeEvents = false;
// }
// break;
// default:
// iReturn = UserCom.OK;
// break;
// }
// }
// catch (Exception ex)
// {
// FreeEvents = false;
// UserLog.WriteLogFile(UserCom.LOG_ERROR,
// System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
// System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
// System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
// ex.Message);
// return UserCom.NG;
// }
// return iReturn;
//}
#endregion
#region
private void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//프린터 ErrorReceived
/*
SerialData err = e.EventType;
string strErr = "";
switch (err)
{
case SerialData.Chars:
strErr = "문자를 받아서 입력 버퍼에 배치했습니다.";
break;
case SerialData.Eof:
strErr = "파일 끝 문자를 받아서 입력 버퍼에 배치했습니다.";
break;
default:
break;
}
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
strErr);
*/
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
private void serialPort_PinChanged(object sender, SerialPinChangedEventArgs e)
{
}
private void serialPort_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//프린터 ErrorReceived
#if(PRT_RECVERR)
SerialError err = e.EventType;
string strErr = "";
switch (err)
{
case SerialError.Frame:
strErr = "HardWare Framing Error";
break;
case SerialError.Overrun:
strErr = "Charaters Buffer Over Run";
break;
case SerialError.RXOver:
strErr = "Input Buffer OverFlow";
break;
case SerialError.RXParity:
strErr = "Founded Parity Error";
break;
case SerialError.TXFull:
strErr = "Write Buffer was Fulled";
break;
default:
break;
}
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
strErr);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
private void POSPrinter_StatusUpdateEvent(string sData)
{
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OlePosHandler(object sender, DoWorkEventArgs e)
{
try
{
if (PosOLEDevice.m_delegateOlePos != null)
PosOLEDevice.m_delegateOlePos(PosConst.OPOS_DEVICE.POSPRINTER, devStatus.Printer.Status, devStatus.Printer.ErrorStatus, string.Empty);
else
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"이벤트 전송 대상 없음");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"이벤트 전송 대상 없음");
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"이벤트 전송 대상 없음");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
catch (Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
/// <summary>
/// Printer 상태 변경에 따른 이벤트 처리
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Printer_StatusUpdateEvent(object sender, StatusUpdateEventArgs e)
{
try
{
if (!bw.IsBusy)
{
m_sUpdateStatus = e.Status;
switch (m_sUpdateStatus)
{
case PosPrinter.StatusCoverOK:
devStatus.Printer.ErrorStatus = "OK";
devStatus.Printer.Status = "COVER OK";
break;
case PosPrinter.StatusReceiptEmpty:
devStatus.Printer.ErrorStatus = "NO PAPER";
devStatus.Printer.Status = "RECEIPT EMPTY";
break;
case PosPrinter.StatusCoverOpen:
devStatus.Printer.ErrorStatus = "COVER OPEN";
devStatus.Printer.Status = "COVER OPEN";
break;
case PosPrinter.StatusReceiptNearEmpty:
devStatus.Printer.ErrorStatus = "OK";
devStatus.Printer.Status = "REC_NEAREMPTY";
break;
case PosPrinter.StatusReceiptPaperOK:
devStatus.Printer.ErrorStatus = "OK";
devStatus.Printer.Status = "REC PAPEROK";
break;
default:
devStatus.Printer.ErrorStatus = "OK";
devStatus.Printer.Status = "OK";
break;
}
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.Printer_StatusUpdateEvent()", "POS Printer Status=[" + devStatus.Printer.Status + "], ErrStatus=[" + devStatus.Printer.ErrorStatus + "]");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.Printer_StatusUpdateEvent()", "POS Printer Status=[" + devStatus.Printer.Status + "], ErrStatus=[" + devStatus.Printer.ErrorStatus + "]");
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.Printer_StatusUpdateEvent()", "POS Printer Status=[" + devStatus.Printer.Status + "], ErrStatus=[" + devStatus.Printer.ErrorStatus + "]");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
bw.RunWorkerAsync();
if (PosOLEDevice.m_delegateOlePos != null)
PosOLEDevice.m_delegateOlePos(PosConst.OPOS_DEVICE.POSPRINTER, devStatus.Printer.Status, devStatus.Printer.ErrorStatus, string.Empty);
}
else
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
UserCom.WARNING_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"프린터 이벤트 처리 전 이벤트 발생 불가");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.WARNING_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"프린터 이벤트 처리 전 이벤트 발생 불가");
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
UserCom.WARNING_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"프린터 이벤트 처리 전 이벤트 발생 불가");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
catch (Exception ex)
{
devStatus.Printer.Status = "STATUS UPDATE EVENT ERROR";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
finally
{
//posprinter.ClearOutput();
}
}
/// <summary>
/// Printer 에러이벤트 처리
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Printer_ErrorEvent(object sender, DeviceErrorEventArgs e)
{
try
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.Printer_ErrorEvent()", "ErrorEvent 발생, ErrorCode=[" + e.ErrorCode.ToString() + "], ErrorResponse=[" + e.ErrorResponse.ToString() + "]");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.Printer_ErrorEvent()", "ErrorEvent 발생, ErrorCode=[" + e.ErrorCode.ToString() + "], ErrorResponse=[" + e.ErrorResponse.ToString() + "]");
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.Printer_ErrorEvent()", "ErrorEvent 발생, ErrorCode=[" + e.ErrorCode.ToString() + "], ErrorResponse=[" + e.ErrorResponse.ToString() + "]");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
if (e.ErrorResponse == ErrorResponse.Clear)
{
if (devStatus.Printer.ErrorStatus != "ER_CLEAR")
{
//devStatus.Printer.ErrorStatus = "ER_CLEAR";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.Printer_ErrorEvent()",
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.Printer_ErrorEvent()",
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.Printer_ErrorEvent()",
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
e.ErrorCode + " " + devStatus.Printer.ErrorStatus + " " + posprinter.ErrorString);
//UserLog.WriteAMSLog("DEV", "ERR", "0302", "Printer " + e.ErrorCode.ToString() + " " + posprinter.ErrorString);
}
}
if (e.ErrorCode == ErrorCode.Failure)
{
if (devStatus.Printer.ErrorStatus != "E_FAILURE")
{
devStatus.Printer.ErrorStatus = "E_FAILURE";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.Printer_ErrorEvent()",
e.ErrorCode + " " + devStatus.Printer.ErrorStatus + " " + posprinter.ErrorString);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.Printer_ErrorEvent()",
e.ErrorCode + " " + devStatus.Printer.ErrorStatus + " " + posprinter.ErrorString);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
"DevicePosPrinter.Printer_ErrorEvent()",
e.ErrorCode + " " + devStatus.Printer.ErrorStatus + " " + posprinter.ErrorString);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
//UserLog.WriteAMSLog("DEV", "ERR", "0402", "Printer " + e.ErrorCode.ToString() + " " + posprinter.ErrorString);
}
}
posprinter.ClearOutput();
}
catch (Exception ex)
{
devStatus.Printer.Status = "ERROREVENT ERROR";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
#endregion
#region
/// <summary>
/// 바코드 아래 출력할 문구의 가운데 정렬후 리턴
/// </summary>
/// <param name="sData"></param>
/// <returns></returns>
private string TextAlignCenter(string sData)
{
string sPrtData = string.Empty;
if (m_cPosStatus.Base.OptBillPrintSize == "0") //0:42bytes
{
if (CmUtil.LenH(sData) < 42) sPrtData = CmUtil.LPadH("", 21 - (CmUtil.LenH(sData) / 2)) + sData;
}
return sPrtData;
}
/// <summary>
/// 출력할 데이터를 Line group 단위로 받아 처리
/// </summary>
/// <param name="pLinedDataGroup"></param>
private void PrintLineDataGroup(string pLineDataGroup)
{
StringBuilder sbPrintData = new StringBuilder();
string sHeader = string.Empty;
string sData = string.Empty;
//20170913 IBM 프린터 행간 축소 start
//기존
//string CrLf = string.Format("{0}{1}", (char)13, (char)10);
//변경
byte[] CrLf;
//20170913 IBM 프린터 행간 축소 end
string[] aLineDataGroup;
byte[] bytTemp = null;
try
{
MemoryStream stream = new MemoryStream();
BinaryWriter bw = new BinaryWriter(stream);
//20170913 IBM 프린터 행간 축소 start
CrLf = new byte[5];
Array.Clear(CrLf, 0, CrLf.Length);
if (m_cPosStatus.Base.OlePosPrinterModel == PosConst.POS_DEVICE_LIST.POS_PRINTER._3_IBM)
{
// LF + WIDTH_X2_OFF
CrLf[0] = 10;
CrLf[1] = 27;
CrLf[2] = 33;
CrLf[3] = 0;
}
else
{
// CRLF
CrLf[0] = 13;
CrLf[1] = 10;
}
//20170913 IBM 프린터 행간 축소 end
aLineDataGroup = pLineDataGroup.Split(new string[] { DELIMETER }, StringSplitOptions.None);
int nLoop = 0;
foreach (string sLineData in aLineDataGroup)
{
if (sLineData.Length < 5) continue;
sHeader = sLineData.Substring(0, 5);
sData = sLineData.Substring(5);
switch(sHeader)
{
case PosConst.PRT_HDR.PRT_BMP: //[BMP]
bytTemp = PrintBMP(sData);
if (bytTemp != null)
{
bw.Write(bytTemp);
}
break;
case PosConst.PRT_HDR.PRT_SGN:
bytTemp = PrintBMP(BaseCom.NxDataPath + "SIGN\\" + sData);
if (bytTemp != null)
{
bw.Write(bytTemp);
}
break;
case PosConst.PRT_HDR.PRT_TBM: //[TBM]
//if (File.Exists(BaseCom.NxImgPath + m_cPosStatus.Base.BrandDiv + "_TOP.bmp") == true)
//{
// bw.Write(PosConst.ESCP_COMMAND.CENTER_ALIGN);
// bw.Write(PrintTopLogo());
// bw.Write(PosConst.ESCP_COMMAND.LEFT_ALIGN);
//}
//2018.01.22; 1NR 모델은 상단부터 출력;girak.kim;Start
if (m_cPosStatus.Base.OlePosPrinterModel == PosConst.POS_DEVICE_LIST.POS_PRINTER._7_1NR)
{
if (m_cPosStatus.Base.TextLogoMsgUseYn == "0" && File.Exists(BaseCom.NxImgPath + m_cPosStatus.Base.BrandDiv + "_TOP.bmp") == true)
{
bw.Write(PosConst.ESCP_COMMAND.CENTER_ALIGN);
bw.Write(PrintTopLogo());
bw.Write(PosConst.ESCP_COMMAND.LEFT_ALIGN);
}
}
//2018.01.22; 1NR 모델은 상단부터 출력;girak.kim;End
break;
case PosConst.PRT_HDR.PRT_BBM: //[BBM]
if (m_cPosStatus.Base.TextLogoMsgUseYn == "0" &&
File.Exists(BaseCom.NxImgPath + m_cPosStatus.Base.BrandDiv + "_BOT.bmp") == true)
{
bw.Write(PosConst.ESCP_COMMAND.CENTER_ALIGN);
bw.Write(PrintBottomLogo());
bw.Write(PosConst.ESCP_COMMAND.LEFT_ALIGN);
}
break;
case PosConst.PRT_HDR.PRT_BAR: //[BAR]
bw.Write(Encoding.Default.GetBytes(PrintBarcodeData(BarcodeType.CODE128, Alignment.CENTER, HRIPosition.BELOW, sData)));
break;
case PosConst.PRT_HDR.PRT_BA1: //[BA1]
case PosConst.PRT_HDR.PRT_SIS:
bw.Write(Encoding.Default.GetBytes(PrintBarcodeData(BarcodeType.CODE128, Alignment.CENTER, HRIPosition.NO_PRINT, sData)));
break;
case PosConst.PRT_HDR.PRT_CUT: //[CUT]
int iMaxCnt = 0;
switch(m_cPosStatus.Base.OlePosPrinterModel)
{
case PosConst.POS_DEVICE_LIST.POS_PRINTER._1_EPSON:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._2_TOSHIBA:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._7_1NR://2018.01.22; 1NR 모델 추가 ;girak.kim
default:
iMaxCnt = 4;
break;
case PosConst.POS_DEVICE_LIST.POS_PRINTER._6_P2C:
iMaxCnt = 2;
break;
}
if (m_cPosStatus.Base.OlePosPrinterModel != PosConst.POS_DEVICE_LIST.POS_PRINTER._7_1NR)//2018.01.22; 1NR 모델은 상단에 출력하므로 조건문 추가, 그 외는 기존 처리;girak.kim;
{
//원래 소스 부분
// 영수증 상단 로고를 컷팅 바로 직전에 출력하는 것으로 변경함(20170623)
//for (int i = 0; i < iMaxCnt; i++)
//{
// bw.Write(CrLf);
//}
if (m_cPosStatus.Base.TextLogoMsgUseYn == "0" && File.Exists(BaseCom.NxImgPath + m_cPosStatus.Base.BrandDiv + "_TOP.bmp") == true)
{
bw.Write(PosConst.ESCP_COMMAND.CENTER_ALIGN);
bw.Write(PrintTopLogo());
bw.Write(PosConst.ESCP_COMMAND.LEFT_ALIGN);
}
else
{
for (int i = 0; i < iMaxCnt; i++)
{
bw.Write(CrLf);
}
}
//원래 소스 부분 끝
}
switch (m_cPosStatus.Base.OlePosPrinterModel)
{
case PosConst.POS_DEVICE_LIST.POS_PRINTER._3_IBM:
bw.Write(PosConst.ESCP_COMMAND.PAPER_CUT_1NR);
break;
default:
bw.Write(PosConst.ESCP_COMMAND.PAPER_CUT);
break;
}
break;
case PosConst.PRT_HDR.PRT_NOR: //[NOR]
bw.Write(Encoding.Default.GetBytes(sData));
bw.Write(CrLf);
break;
case PosConst.PRT_HDR.PRT_BLD: //[BLD]
bw.Write(PosConst.ESCP_COMMAND.BOLD_ON);
bw.Write(Encoding.Default.GetBytes(sData));
bw.Write(PosConst.ESCP_COMMAND.BOLD_OFF);
bw.Write(CrLf);
break;
case PosConst.PRT_HDR.PRT_LIN:
bw.Write(PosConst.ESCP_COMMAND.UNDERLINE_ON);
bw.Write(Encoding.Default.GetBytes(sData));
bw.Write(PosConst.ESCP_COMMAND.UNDERLINE_OFF);
bw.Write(CrLf);
break;
case PosConst.PRT_HDR.PRT_HOR:
bw.Write(PosConst.ESCP_COMMAND.WIDTH_X2_ON);
bw.Write(Encoding.Default.GetBytes(sData));
bw.Write(PosConst.ESCP_COMMAND.WIDTH_X2_OFF);
bw.Write(CrLf);
break;
case PosConst.PRT_HDR.PRT_VER:
bw.Write(PosConst.ESCP_COMMAND.HEIGHT_X2_ON);
bw.Write(Encoding.Default.GetBytes(sData));
bw.Write(PosConst.ESCP_COMMAND.HEIGHT_X2_OFF);
bw.Write(CrLf);
break;
case PosConst.PRT_HDR.PRT_BIG:
bw.Write(PosConst.ESCP_COMMAND.ZOOM_ON);
bw.Write(Encoding.Default.GetBytes(sData));
bw.Write(PosConst.ESCP_COMMAND.ZOOM_OFF);
bw.Write(CrLf);
break;
case PosConst.PRT_HDR.PRT_VRB:
bw.Write(PosConst.ESCP_COMMAND.HEIGHT_X2_ON);
bw.Write(PosConst.ESCP_COMMAND.BOLD_ON);
bw.Write(Encoding.Default.GetBytes(sData));
bw.Write(PosConst.ESCP_COMMAND.BOLD_OFF);
bw.Write(PosConst.ESCP_COMMAND.HEIGHT_X2_OFF);
bw.Write(CrLf);
break;
case PosConst.PRT_HDR.PRT_HRB:
bw.Write(PosConst.ESCP_COMMAND.WIDTH_X2_ON);
bw.Write(PosConst.ESCP_COMMAND.BOLD_ON);
bw.Write(Encoding.Default.GetBytes(sData));
bw.Write(PosConst.ESCP_COMMAND.BOLD_OFF);
bw.Write(PosConst.ESCP_COMMAND.WIDTH_X2_OFF);
bw.Write(CrLf);
break;
case PosConst.PRT_HDR.PRT_BGB:
bw.Write(PosConst.ESCP_COMMAND.ZOOM_ON);
bw.Write(PosConst.ESCP_COMMAND.BOLD_ON);
bw.Write(Encoding.Default.GetBytes(sData));
bw.Write(PosConst.ESCP_COMMAND.BOLD_OFF);
bw.Write(PosConst.ESCP_COMMAND.ZOOM_OFF);
bw.Write(CrLf);
break;
case PosConst.PRT_HDR.PRT_VRE :
//bw.Write(PosConst.ESCP_COMMAND.HEIGHT_X2_ON);
//bw.Write(PosConst.ESCP_COMMAND.REVERSE_MODE_ON);
//bw.Write(Encoding.Default.GetBytes(sData));
//bw.Write(PosConst.ESCP_COMMAND.REVERSE_MODE_OFF);
//bw.Write(PosConst.ESCP_COMMAND.HEIGHT_X2_OFF);
bw.Write(PosConst.ESCP_COMMAND.CENTER_ALIGN);
bw.Write(PosConst.ESCP_COMMAND.HEIGHT_X2_ON);
bw.Write(PosConst.ESCP_COMMAND.REVERSE_MODE_ON);
bw.Write(Encoding.Default.GetBytes(sData.Trim()));
bw.Write(PosConst.ESCP_COMMAND.REVERSE_MODE_OFF);
bw.Write(PosConst.ESCP_COMMAND.HEIGHT_X2_OFF);
bw.Write(CrLf);
bw.Write(PosConst.ESCP_COMMAND.LEFT_ALIGN);
break;
}
nLoop++;
}
bw.Flush();
//TransmitCommand(stream.ToArray());
AddToPrinterBuffer(stream.ToArray());
}
catch(Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
/// <summary>
/// 출력할 데이터를 1 Line 단위로 받아 처리
/// </summary>
/// <param name="pLineData"></param>
private void PrintLineData(string pLineData)
{
string sType = "";
string sLineData = "";
string CrLf = string.Format("{0}{1}", (char)13, (char)10);
string sTxtData = "";
if (pLineData.Length < 5) return;
sType = pLineData.Substring(0, 5);
sLineData = pLineData.Substring(5);
string sPosMode = string.Empty;
switch (sType)
{
case PosConst.PRT_HDR.PRT_BMP: //[BMP]
try
{
posprinter.PrintBitmap(PrinterStation.Receipt, sLineData, PosPrinter.PrinterBitmapAsIs, PosPrinter.PrinterBitmapCenter);
}
catch (Exception ex)
{
devStatus.Printer.Status = "BITMAP PRT FAIL";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BMP Exception : "+devStatus.Printer.Status + "/" + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BMP Exception : " + devStatus.Printer.Status + "/" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BMP Exception : "+devStatus.Printer.Status + "/" + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
break;
case PosConst.PRT_HDR.PRT_TBM: //[TBM]
try
{
posprinter.PrintNormal(PrinterStation.Receipt, (char)27 + "|1B"); //'Bitmap Image Print ('비트맵 이미지 출력)
}
catch (Exception ex)
{
devStatus.Printer.Status = "TOP BMP PRT FAIL";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BMP Exception : "+devStatus.Printer.Status + "/" + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BMP Exception : " + devStatus.Printer.Status + "/" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BMP Exception : "+devStatus.Printer.Status + "/" + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
break;
case PosConst.PRT_HDR.PRT_BBM: //[BBM]
try
{
posprinter.PrintNormal(PrinterStation.Receipt, (char)27 + "|2B"); //'Bitmap Image Print ('비트맵 이미지 출력)
}
catch(Exception ex)
{
devStatus.Printer.Status = "BOTTOM BMP PRT FAIL";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BBM Exception : " + devStatus.Printer.Status + "/" + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BBM Exception : " + devStatus.Printer.Status + "/" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BBM Exception : " + devStatus.Printer.Status + "/" + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
break;
case PosConst.PRT_HDR.PRT_BAR: //[BAR]
try
{
posprinter.PrintBarCode(PrinterStation.Receipt, sLineData, BarCodeSymbology.Code128, 50, 368, PosPrinter.PrinterBarCodeCenter, BarCodeTextPosition.Below);
}
catch (Exception ex)
{
devStatus.Printer.Status = "BAR PRT FAIL";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BAR Exception : " + devStatus.Printer.Status + "/" + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BAR Exception : " + devStatus.Printer.Status + "/" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BAR Exception : " + devStatus.Printer.Status + "/" + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
break;
case PosConst.PRT_HDR.PRT_BA1: //[BA1]
case PosConst.PRT_HDR.PRT_SIS:
try
{
posprinter.PrintBarCode(PrinterStation.Receipt, sLineData, BarCodeSymbology.Code128, 50, 368, PosPrinter.PrinterBarCodeCenter, BarCodeTextPosition.None);
}
catch (Exception ex)
{
devStatus.Printer.Status = "BAREx PRT FAIL";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BA1 Exception : " + devStatus.Printer.Status + "/" + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BA1 Exception : " + devStatus.Printer.Status + "/" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print BA1 Exception : " + devStatus.Printer.Status + "/" + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
break;
case PosConst.PRT_HDR.PRT_CUT: //[CUT]
try
{
for(int nLoop = 0;nLoop < 5;nLoop++)
{
posprinter.PrintNormal(PrinterStation.Receipt, (char)27 + "|N" + " " + CrLf);
}
posprinter.CutPaper(100);
}
catch (Exception ex)
{
devStatus.Printer.Status = "CUT PAPER FAIL";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print 1 Exception : " + devStatus.Printer.Status + "/" + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print 1 Exception : " + devStatus.Printer.Status + "/" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Print 1 Exception : " + devStatus.Printer.Status + "/" + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
break;
default: // Text Print (텍스트 출력)
sTxtData = "";
switch (sType)
{
case PosConst.PRT_HDR.PRT_NOR:
sTxtData = sTxtData + (char)27 + "|N" + sLineData + CrLf;
posprinter.PrintNormal(PrinterStation.Receipt, sTxtData);
break; //'Normal (보통문자)
case PosConst.PRT_HDR.PRT_BLD:
sTxtData = sTxtData + (char)27 + "|bC" + sLineData + CrLf;
posprinter.PrintNormal(PrinterStation.Receipt, sTxtData);
break; //'Bold (진하게)
case PosConst.PRT_HDR.PRT_LIN:
sTxtData = sTxtData + (char)27 + "|uC" + sLineData + CrLf;
posprinter.PrintNormal(PrinterStation.Receipt, sTxtData);
break; //'Under Line (Under Line 출력)
case PosConst.PRT_HDR.PRT_HOR:
sTxtData = sTxtData + (char)27 + "|2C" + sLineData + CrLf;
posprinter.PrintNormal(PrinterStation.Receipt, sTxtData);
break; //'2 times horizontal expansion (가로 2배 확대)
case PosConst.PRT_HDR.PRT_VER:
sTxtData = sTxtData + (char)27 + "|3C" + sLineData + CrLf;
posprinter.PrintNormal(PrinterStation.Receipt, sTxtData);
break; //'2 times vertical expansion (세로 2배 확대)
case PosConst.PRT_HDR.PRT_BIG:
sTxtData = sTxtData + (char)27 + "|4C" + sLineData + CrLf;
posprinter.PrintNormal(PrinterStation.Receipt, sTxtData);
break; //'2 times horizontal and vertical expansion (가로세로 2배 확대)
case PosConst.PRT_HDR.PRT_VRB:
sTxtData = sTxtData + (char)27 + "|bC" + (char)27 + "|3C" + sLineData + CrLf;
break; //'2 times vertical expansion and bold(진하게 세로 2배 확대)
case PosConst.PRT_HDR.PRT_HRB:
sTxtData = sTxtData + (char)27 + "|bC" + (char)27 + "|2C" + sLineData + CrLf;
break; //'2 times horizontal expansion and bold(진하게 가로 2배 확대)
case PosConst.PRT_HDR.PRT_BGB:
sTxtData = sTxtData + (char)27 + "|bC" + (char)27 + "|4C" + sLineData + CrLf;
break; //'2 times horizontal and vertical expansion, bold(진하게 가로세로 2배 확대)
}
break;
}
}
private byte[] PrintBMP(string sFilePath)
{
byte[] arRet = null;
try
{
arRet = GetSelectBitImageByte(sFilePath, 0, false);
}
catch (Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception : "+ ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception : " + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception : "+ ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
return arRet;
}
/// <summary>
/// 상단 로고 출력
/// </summary>
private byte[] PrintTopLogo()
{
byte[] arRet = null;
try
{
switch (m_cPosStatus.Base.OlePosPrinterModel)
{
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._1_TM_T88II:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._2_TM_T88III:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._3_TM_T88IV:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._4_TM_T88V:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._6_4610_1NR:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._7_TRST_A00:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._9_TP_600:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._10_GIANT_100S:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._11_P2C_All_In_One:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._1_EPSON:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._6_P2C:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._7_1NR://2018.01.22;"7:4610_1NR" 모델 추가, 이미지 처리는 _1_EPSON 과 동일;girak.kim
default:
arRet = PosConst.ESCP_COMMAND.PRINT_NV_BIT_IMAGE_1;
break;
case PosConst.POS_DEVICE_LIST.POS_PRINTER._2_TOSHIBA:
arRet = PosConst.ESCP_COMMAND.PRINT_NV_BIT_IMAGE_3;
break;
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._5_4610_TF7:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._3_IBM:
arRet = PosConst.ESCP_COMMAND.PRINT_NV_BIT_IMAGE_1_1NR;
//arRet = PosConst.ESCP_COMMAND.PRINT_NV_BIT_IMAGE_1;
break;
}
}
catch (Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"PrintTopLogo Exception : " + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + "PrintTopLogo : " + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"PrintTopLogo Exception : " + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
return arRet;
}
/// <summary>
/// 하단 로고 출력
/// </summary>
private byte[] PrintBottomLogo()
{
byte[] arRet = null;
try
{
switch (m_cPosStatus.Base.OlePosPrinterModel)
{
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._1_TM_T88II:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._2_TM_T88III:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._3_TM_T88IV:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._4_TM_T88V:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._6_4610_1NR:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._7_TRST_A00:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._9_TP_600:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._10_GIANT_100S:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._11_P2C_All_In_One:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._1_EPSON:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._6_P2C:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._7_1NR://2018.01.22;"7:4610_1NR" 모델 추가, 이미지 처리는 _1_EPSON 과 동일;girak.kim
default:
arRet = PosConst.ESCP_COMMAND.PRINT_NV_BIT_IMAGE_2;
break;
case PosConst.POS_DEVICE_LIST.POS_PRINTER._2_TOSHIBA:
arRet = PosConst.ESCP_COMMAND.PRINT_NV_BIT_IMAGE_4;
break;
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._5_4610_TF7:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._3_IBM:
arRet = PosConst.ESCP_COMMAND.PRINT_NV_BIT_IMAGE_2_1NR;
//arRet = PosConst.ESCP_COMMAND.PRINT_NV_BIT_IMAGE_2;
break;
}
}
catch (Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"PrintBottomLogo Exception:" + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + "PrintBottomLogo :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"PrintBottomLogo Exception:" + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
return arRet;
}
/// <summary>
/// 바코드 출력 함수
/// </summary>
/// <param name="btBarcodeType">바코드형태</param>
/// <param name="aAlignment">정렬위치</param>
/// <param name="hpHriPosition">HRI Character position</param>
/// <param name="sLineData">바코드데이터</param>
private string PrintBarcodeData(BarcodeType btBarcodeType, Alignment aAlignment, HRIPosition hpHriPosition, string sLineData)
{
try
{
string sBarcodeData = string.Empty;
switch(m_cPosStatus.Base.OlePosPrinterModel)
{
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._1_TM_T88II:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._2_TM_T88III:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._3_TM_T88IV:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._4_TM_T88V:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._6_4610_1NR:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._7_TRST_A00:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._9_TP_600:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._10_GIANT_100S:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._11_P2C_All_In_One:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._1_EPSON:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._2_TOSHIBA:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._6_P2C:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._7_1NR://2018.01.22;"7:4610_1NR" 모델 추가, 처리는 _1_EPSON 과 동일;girak.kim
default:
// 바코드 출력 위치 정렬
sBarcodeData += GetAlignCommandToString(aAlignment);
// Set HRI chracter print position
sBarcodeData += GetHRIPositionCommandToString(hpHriPosition);
// Set Barcode horizontal size.
sBarcodeData += String.Format("{0}{1}{2}",
Convert.ToChar(0x1D), Convert.ToChar(0x77), Convert.ToChar(0x02));
// Set Barcode height
sBarcodeData += String.Format("{0}{1}{2}",
Convert.ToChar(0x1D), Convert.ToChar(0x68), Convert.ToChar(0x32));
// Print Barcode
sBarcodeData += String.Format("{0}{1}",
Convert.ToChar(0x1D), Convert.ToChar(0x6B));
switch (btBarcodeType)
{
case BarcodeType.CODE93:
sBarcodeData += String.Format("{0}", Convert.ToChar(0x48));
sBarcodeData += Convert.ToChar(sLineData.Length);
sBarcodeData += sLineData;
break;
case BarcodeType.CODE128:
sBarcodeData += String.Format("{0}", Convert.ToChar(0x49));
int nDataLen = sLineData.Length + 2;
sBarcodeData += String.Format("{0}", Convert.ToChar(nDataLen));
sBarcodeData += String.Format("{0}", Convert.ToChar(0x7B)); // "{"
sBarcodeData += String.Format("{0}", Convert.ToChar(0x42)); // "B"
sBarcodeData += sLineData;
break;
}
break;
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._5_4610_TF7:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._3_IBM:
// 바코드 출력 위치 정렬
sBarcodeData += GetAlignCommandToString(aAlignment);
// Set HRI chracter print position
sBarcodeData += GetHRIPositionCommandToString(hpHriPosition);
// Set Barcode horizontal size.
sBarcodeData += String.Format("{0}{1}{2}",
Convert.ToChar(0x1D), Convert.ToChar(0x77), Convert.ToChar(0x02));
// Set Barcode height
sBarcodeData += String.Format("{0}{1}{2}",
Convert.ToChar(0x1D), Convert.ToChar(0x68), Convert.ToChar(50));
// Print Barcode
sBarcodeData += String.Format("{0}{1}",
Convert.ToChar(0x1D), Convert.ToChar(0x6B));
switch (btBarcodeType)
{
case BarcodeType.CODE93:
sBarcodeData += String.Format("{0}", Convert.ToChar(0x48));
sBarcodeData += Convert.ToChar(sLineData.Length);
sBarcodeData += sLineData;
break;
case BarcodeType.CODE128:
sBarcodeData += String.Format("{0}", Convert.ToChar(0x08));
sBarcodeData += sLineData;
break;
}
break;
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._4_IBM_1NR:
// // 바코드 출력 위치 정렬
// sBarcodeData += GetAlignCommandToString(aAlignment);
// // Set HRI chracter print position
// sBarcodeData += GetHRIPositionCommandToString(hpHriPosition);
// // Set Barcode horizontal size.
// sBarcodeData += String.Format("{0}{1}{2}",
// Convert.ToChar(0x1D), Convert.ToChar(0x77), Convert.ToChar(0x02));
// // Set Barcode height
// sBarcodeData += String.Format("{0}{1}{2}",
// Convert.ToChar(0x1D), Convert.ToChar(0x68), Convert.ToChar(0x50));
// // Print Barcode
// sBarcodeData += String.Format("{0}{1}",
// Convert.ToChar(0x1D), Convert.ToChar(0x6B));
// switch (btBarcodeType)
// {
// case BarcodeType.CODE93:
// sBarcodeData += String.Format("{0}", Convert.ToChar(0x48));
// sBarcodeData += Convert.ToChar(sLineData.Length);
// sBarcodeData += sLineData;
// break;
// case BarcodeType.CODE128:
// sBarcodeData += String.Format("{0}", Convert.ToChar(0x07));
// //sBarcodeData += String.Format("{0}", Convert.ToChar(0x07));
// sBarcodeData += sLineData;
// break;
// }
// break;
}
// 출력 정렬 위치 원복
sBarcodeData += GetAlignCommandToString(Alignment.LEFT);
//m_serialPort.Write(sBarcodeData);
return sBarcodeData;
}
catch(Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return "";
}
}
/// <summary>
/// Byte 배열의 HRI print position Command 를 string으로 변환
/// </summary>
/// <param name="hpHriPosition"></param>
/// <returns></returns>
private string GetHRIPositionCommandToString(HRIPosition hpHriPosition)
{
string sCommand = string.Empty;
try
{
switch(hpHriPosition)
{
case HRIPosition.NO_PRINT:
sCommand = System.Text.Encoding.Default.GetString(buildESCPCommand(PosConst.ESCP_COMMAND.HRI_PRINT_POSITION, (byte)0));
break;
case HRIPosition.ABOVE:
sCommand = System.Text.Encoding.Default.GetString(buildESCPCommand(PosConst.ESCP_COMMAND.HRI_PRINT_POSITION, (byte)1));
break;
case HRIPosition.BELOW:
sCommand = System.Text.Encoding.Default.GetString(buildESCPCommand(PosConst.ESCP_COMMAND.HRI_PRINT_POSITION, (byte)2));
break;
case HRIPosition.ABOVE_BELOW:
sCommand = System.Text.Encoding.Default.GetString(buildESCPCommand(PosConst.ESCP_COMMAND.HRI_PRINT_POSITION, (byte)3));
break;
}
}
catch(Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
return sCommand;
}
/// <summary>
/// Byte 배열의 Align Command 를 string으로 변환
/// </summary>
/// <param name="aAlignment">정렬위치</param>
/// <returns></returns>
private string GetAlignCommandToString(Alignment aAlignment)
{
string sCommand = string.Empty;
try
{
switch(aAlignment)
{
case Alignment.CENTER:
sCommand = System.Text.Encoding.Default.GetString(PosConst.ESCP_COMMAND.CENTER_ALIGN);
break;
case Alignment.LEFT:
sCommand = System.Text.Encoding.Default.GetString(PosConst.ESCP_COMMAND.LEFT_ALIGN);
break;
case Alignment.RIGHT:
sCommand = System.Text.Encoding.Default.GetString(PosConst.ESCP_COMMAND.RIGHT_ALIGN);
break;
}
}
catch(Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
return sCommand;
}
/// <summary>
/// 프린터 출력
/// </summary>
/// <param name="pPrintData">출력할 데이터 Line 단위 배열</param>
/// <param name="kiosk">해피스테이션만 사용할꺼임 2019.03.27</param>
/// <returns></returns>
public bool ReceiptPrinter(string[] pPrintData, bool kiosk)
{
bool bRet = false;
int[] List = new int[32];
int ListNum = 0;
bool Interface_opend = true;
if (m_cPosStatus.Base.OlePosPrinterController == PosConst.POS_DEVICE_CONTROLLER.RS232) //해피스테이션 rs232 사용
{
string sPrtPort = CmUtil.MidH(m_cPosStatus.Base.OlePosPrinterSerialPortNumber, 3, m_cPosStatus.Base.OlePosPrinterSerialPortNumber.Length - 3);
long baudRate = m_cPosStatus.Base.OlePosPrinterSerialBaudRate;
Interface_opend = REXOD_Setup_Printer(Printer_Interface._COM_, int.Parse(sPrtPort), (int)baudRate);
}
else if (m_cPosStatus.Base.OlePosPrinterController == PosConst.POS_DEVICE_CONTROLLER.OPOS) //해피스테이션 usb 사용
{
ListNum = REXOD_Enum_Printer(Printer_Interface._USB_, List);
if (ListNum >= 1)
{
Interface_opend = REXOD_Setup_Printer(Printer_Interface._USB_, List[0], 0);
}
}
Bitmap bitmapImage;
int iRet = 0;
string sFileName = string.Empty;
string lastPrintData = "";
string printDataGbn = "";
byte[] strBarcode = null;
for (int i = 0; i < pPrintData.Length; i++)
{
if (pPrintData[i].Length >= 5)
printDataGbn = pPrintData[i].Substring(0, 5);
if (pPrintData[i].Length >= 5)
lastPrintData = pPrintData[i].Substring(5) + "\r\n";
else
lastPrintData = "" + "\r\n";
if (printDataGbn.Equals("[BLD]")) REXOD_Bold_Word(true);
if (printDataGbn.Equals("[BAR]"))
{
strBarcode = Encoding.UTF8.GetBytes(PrintBarcodeData(BarcodeType.CODE128, Alignment.CENTER, HRIPosition.NO_PRINT, lastPrintData.Replace("\r\n", "")));
REXOD_Select_Barcode_Alignment(AlignmentR._Center_);
REXOD_Print_Barcode(Barcode_Type._CODE128_, strBarcode, strBarcode.Length);
}
else if (printDataGbn.Equals("[SGN]"))
{
sFileName = BaseCom.NxDataPath + "SIGN\\" + lastPrintData.Replace("\r\n", "");
if (File.Exists(sFileName))
{
bitmapImage = new Bitmap(sFileName);
if (bitmapImage != null)
{
// var rectangle = new System.Drawing.Rectangle(0, 0, 496, 100);
// var lastImg = bitmapImage.Clone(rectangle, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
// ImageConverter converter = new ImageConverter();
// GCHandle pinnedArray = GCHandle.Alloc((byte[])converter.ConvertTo(bitmapImage, typeof(byte[])), GCHandleType.Pinned);
// IntPtr pointer = pinnedArray.AddrOfPinnedObject();
REXOD_Select_Alignment(AlignmentR._Center_);
IntPtr hbit = bitmapImage.GetHbitmap();
REXOD_Print_Bitmap(hbit);
//REXOD_Print_Bitmap(pointer);
//pinnedArray.Free();
DeleteObject(hbit);
REXOD_Select_Alignment(AlignmentR._Align_left_);
}
}
}
else if (printDataGbn.Equals("[TBM]"))
{
sFileName = BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.RLOGO + @"PB_TOP.bmp";
if (File.Exists(sFileName))
{
bitmapImage = new Bitmap(sFileName);
if (bitmapImage != null)
{
// var rectangle = new System.Drawing.Rectangle(0, 0, 496, 100);
// var lastImg = bitmapImage.Clone(rectangle, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
// ImageConverter converter = new ImageConverter();
// GCHandle pinnedArray = GCHandle.Alloc((byte[])converter.ConvertTo(bitmapImage, typeof(byte[])), GCHandleType.Pinned);
// IntPtr pointer = pinnedArray.AddrOfPinnedObject();
REXOD_Select_Alignment(AlignmentR._Center_);
IntPtr hbit = bitmapImage.GetHbitmap();
REXOD_Print_Bitmap(hbit);
//REXOD_Print_Bitmap(pointer);
//pinnedArray.Free();
DeleteObject(hbit);
REXOD_Select_Alignment(AlignmentR._Align_left_);
}
}
}
else if (printDataGbn.Equals("[BBM]"))
{
sFileName = BaseCom.NxCDPPath + PosConst.MST_IMG_PATH.RLOGO + @"PB_BOT.bmp";
if (File.Exists(sFileName))
{
bitmapImage = new Bitmap(sFileName);
if (bitmapImage != null)
{
// var rectangle = new System.Drawing.Rectangle(0, 0, 496, 100);
// var lastImg = bitmapImage.Clone(rectangle, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
// ImageConverter converter = new ImageConverter();
// GCHandle pinnedArray = GCHandle.Alloc((byte[])converter.ConvertTo(bitmapImage, typeof(byte[])), GCHandleType.Pinned);
// IntPtr pointer = pinnedArray.AddrOfPinnedObject();
REXOD_Select_Alignment(AlignmentR._Center_);
IntPtr hbit = bitmapImage.GetHbitmap();
REXOD_Print_Bitmap(hbit);
//REXOD_Print_Bitmap(pointer);
//pinnedArray.Free();
DeleteObject(hbit);
REXOD_Select_Alignment(AlignmentR._Align_left_);
}
}
}
else if (printDataGbn.Equals("[BIG]"))
{
//RE
REXOD_Double_Height(true);
REXOD_Double_Width(true);
REXOD_Bold_Word(true);
REXOD_Set_This_Line_Start_Position(40);
iRet = REXOD_Print_CharW(lastPrintData);
REXOD_Double_Height(false);
REXOD_Double_Width(false);
REXOD_Bold_Word(false);
iRet = REXOD_Print_CharW(" " + "\r\n");
}else if (printDataGbn.Equals("[HOR]"))
{
REXOD_Double_Width(true);
REXOD_Set_This_Line_Start_Position(40);
iRet = REXOD_Print_CharW(lastPrintData);
REXOD_Double_Width(false);
}
else if (printDataGbn.Equals("[VER]"))
{
iRet = REXOD_Print_CharW(" " + "\r\n");
REXOD_Set_This_Line_Start_Position(40);
iRet = REXOD_Print_CharW(lastPrintData);
iRet = REXOD_Print_CharW(" " + "\r\n");
}
else
{
REXOD_Set_This_Line_Start_Position(40);
iRet = REXOD_Print_CharW(lastPrintData);
}
if (printDataGbn.Equals("[BLD]")) REXOD_Bold_Word(false);
}
REXOD_Enter_With_nLine(6);
REXOD_Full_Cut();
return bRet;
}
/// <summary>
/// 프린터 출력
/// </summary>
/// <param name="pPrintData">출력할 데이터 Line 단위 배열</param>
/// <returns></returns>
public bool ReceiptPrinter(string[] pPrintData)
{
bool bRet = false;
try
{
if (devStatus.Printer.ErrorStatus == "E_FAILURE") devStatus.Printer.ErrorStatus = "OK";
if(devStatus.Printer.UseYn == false)
{
return bRet;
}
//if (devStatus.Printer.Open == false)
//{
// if (OpenDevice(PosConst.OPOS_DEVICE.POSPRINTER, PosConst.OPOS_LDN.POSPRINTER) == false) return bRet;
//}
if (m_cPosStatus.Base.OlePosPrinterController == PosConst.POS_DEVICE_CONTROLLER.OPOS)
{
if (devStatus.Printer.Open == false)
{
if (OpenDevice(PosConst.OPOS_DEVICE.POSPRINTER, PosConst.OPOS_LDN.POSPRINTER) == false) return bRet;
}
// (OPOS) Begin a transaction.
posprinter.TransactionPrint(PrinterStation.Receipt, PrinterTransactionControl.Transaction);
foreach (string sLineData in pPrintData)
{
this.PrintLineData(sLineData);
}
// (OPOS) End a transaction by printing the buffered data.
posprinter.TransactionPrint(PrinterStation.Receipt, PrinterTransactionControl.Normal);
if (devStatus.Printer.ErrorStatus != "OK")
{
//프린터 상태 체크 실패 시에도 Port Close(20170508-조충연K)
CloseDevice();
devStatus.Printer.Status = "Receipt Print Fail";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"ReceiptPrinter Fail " + devStatus.Printer.ErrorStatus);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"ReceiptPrinter Fail " + devStatus.Printer.ErrorStatus);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"ReceiptPrinter Fail " + devStatus.Printer.ErrorStatus);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return bRet;
}
else
{
devStatus.Printer.Status = "Receipt Print Success";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"ReceiptPrinter SUCCESS");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"ReceiptPrinter SUCCESS");
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"ReceiptPrinter SUCCESS");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
CloseDevice();
}
else if(m_cPosStatus.Base.OlePosPrinterController == PosConst.POS_DEVICE_CONTROLLER.RS232)
{
//if (m_serialPort == null || m_serialPort.IsOpen == false)
//{
// return false;
//}
//if (CheckPrinter() == false)
//{
// //프린터 상태 체크 실패 시에도 Port Close(20170508-조충연K)
// CloseDevice();
// WinManager.ConfirmMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0691));
// return false;
//}
// PAGE MODE 에서 Print NV bit image 명령어(FS p)를 사용할 수 없으므로
// Serial I/F 사용 시에는 PAGE MODE 사용 안 함 (2016/06/16-CYCHO)
// (RS232) Begin a transaction.
//TransmitCommand(PosConst.ESCP_COMMAND.SET_PAGE_MODE);
StringBuilder sbBuffer = new StringBuilder();
int nCnt = 0;
int nEndIdx;
for (int i = 0; i < (nEndIdx = pPrintData.Length); i++)
{
sbBuffer.Append(pPrintData[i]);
sbBuffer.Append(DELIMETER);
nCnt++;
//20180611 프린터 미출력 개선 02Printer.exe start, 20180719
#if(PRT_O2PRINTER)
if(nCnt >= 1000 || i + 1 == nEndIdx)
#else
if(nCnt >= 100 || i + 1 == nEndIdx)
#endif
//20180611 프린터 미출력 개선 02Printer.exe end, 20180719
{
nCnt = 0;
this.PrintLineDataGroup(sbBuffer.ToString());
sbBuffer.Clear();
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
pPrintData.Length.ToString() + "," + i.ToString());
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
pPrintData.Length.ToString() + "," + i.ToString());
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
pPrintData.Length.ToString() + "," + i.ToString());
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"ReceiptPrinter SUCCESS");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"ReceiptPrinter SUCCESS");
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"ReceiptPrinter SUCCESS");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
//// 빚은몰 웹페이지에서 출력 기능이 존재하여 계속 물고 있을 수 없다.(안호성C - 2017.04.28)
//CloseDevice();
bRet = true;
}
catch (Exception ex)
{
devStatus.Printer.Status = "Receipt Print Fail";
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return bRet;
}
return bRet;
}
#endregion
#region Print Bitmap image
/// <summary>
/// BMP 이미지를 byte로 반환
/// </summary>
/// <param name="sFilePath"></param>
private byte[] GetSelectBitImageByte(string sFilePath, double nImgWidth, bool bImgScale)
{
byte[] bytes = new byte[0];
try
{
// BMP파일 경로가 없거나 경로에 파일이 없으면 return
if (sFilePath == "" || File.Exists(sFilePath) == false)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"BMP File not Exists : " + sFilePath);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"BMP File not Exists : " + sFilePath);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"BMP File not Exists : " + sFilePath);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return null;
}
ConvertBitmapData data = GetBitmapData(sFilePath, nImgWidth, bImgScale);
BitArray dots = data.Dots;
byte[] width = BitConverter.GetBytes(data.Width);
int offset = 0;
MemoryStream stream = new MemoryStream();
BinaryWriter bw = new BinaryWriter(stream);
// 초기화
bw.Write((char)0x1B);
bw.Write('@');
bw.Write((char)0x1B);
bw.Write('3');
bw.Write((byte)24);
bw.Write((char)0x1B);
bw.Write((char)0x61);
bw.Write((char)0x31);
while (offset < data.Height)
{
/* Select bit image mode
* [Format] ASCII ESC ✻ m nL nH d1 ... dk
* Hex 1B 2A m nL nH d1 ... dk
* Decimal 27 42 m nL nH d1 ... dk
*-------------------------------------------------
* m Mode Number of bits for Dot density Amount of data (k)
* vertical data in horizontal
* 0 8-dot single-density 8 Single-density nL + nH × 256
* 1 8-dot double-density 8 Double-density nL + nH × 256
* 32 24-dot single-density 24 Single-density (nL +nH × 256) × 3
* 33 24-dot double-density 24 Double-density (nL + nH × 256) × 3
*/
bw.Write((char)0x1B);
bw.Write('*'); // bit-image mode(0x2A)
bw.Write((byte)33); // 24-dot double-density
bw.Write(width[0]); // width low byte
bw.Write(width[1]); // width high byte
for (int x = 0; x < data.Width; ++x)
{
for (int k = 0; k < 3; ++k)
{
byte slice = 0;
for (int b = 0; b < 8; ++b)
{
int y = (((offset / 8) + k) * 8) + b;
// Calculate the location of the pixel we want in the bit array.
// It'll be at (y * width) + x.
int i = (y * data.Width) + x;
// If the image is shorter than 24 dots, pad with zero.
bool v = false;
if (i < dots.Length)
{
v = dots[i];
}
slice |= (byte)((v ? 1 : 0) << (7 - b));
}
bw.Write(slice);
}
}
offset += 24; // 24-dot double-density
bw.Write((char)0x0A);
}
// Restore the line spacing to the default of 30 dots.
bw.Write((char)0x1B);
bw.Write('3');
bw.Write((byte)30);
bw.Flush();
bytes = stream.ToArray();
}
catch (Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception : "+ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception : " + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception : "+ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
return bytes;
}
internal class ConvertBitmapData
{
public BitArray Dots { get; set; }
public int Height { get; set; }
public int Width { get; set; }
}
private ConvertBitmapData GetBitmapData(string sFilePath, double nImgWidth, bool bImgScale)
{
try
{
using(var bitmaptmp = (Bitmap)Bitmap.FromFile(sFilePath))
{
Bitmap bitmap = bitmaptmp;
var threshold = 127;
var index = 0;
if(nImgWidth <= 0)
{
nImgWidth = (double)bitmap.Width;
}
double multiplier = nImgWidth;
double scale = (double)(multiplier / (double)bitmap.Width);
if (!bImgScale)
scale = 1;
int xheight = (int)(bitmap.Height * scale);
int xwidth = (int)(bitmap.Width * scale);
var dimensions = xwidth * xheight;
var dots = new BitArray(dimensions);
for(var y = 0;y < xheight;y++)
{
for(var x = 0;x < xwidth;x++)
{
var _x = (int)(x / scale);
var _y = (int)(y / scale);
var color = bitmap.GetPixel(_x, _y);
var luminance = (int)(color.R * 0.3 + color.G * 0.59 + color.B * 0.11);
dots[index] = (luminance < threshold);
index++;
}
}
return new ConvertBitmapData() { Dots = dots, Height = (int)(bitmap.Height * scale), Width = (int)(bitmap.Width * scale) };
}
}
catch (Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" +ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" +ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
return null;
}
#endregion
#region Upload image to NV memory region
/// <summary>
/// Logo BMP 파일을 프린터 메모리에 Upload
/// </summary>
/// <returns></returns>
public bool SetLogoBmp()
{
string sTopLogoTargetFile = string.Empty;
string sBotLogoTargetFile = string.Empty;
string sTopLogoFile = string.Empty;
string sBotLogoFile = string.Empty;
string[] sLogoFiles = null;
//if (SetTopLogo && SetBottomLogo) return true;
try
{
sTopLogoFile = BaseFrame.BaseCom.NxImgPath + m_cPosStatus.Base.BrandDiv + "_TOP.bmp";
sBotLogoFile = BaseFrame.BaseCom.NxImgPath + m_cPosStatus.Base.BrandDiv + "_BOT.bmp";
if(File.Exists(sTopLogoFile))
{
if(File.Exists(sBotLogoFile))
{
sLogoFiles = new string[] { sTopLogoFile, sBotLogoFile };
}
else
{
sLogoFiles = new string[] { sTopLogoFile };
}
}
else
{
//SetTopLogo = false;
//SetBottomLogo = false;
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, " Logo file Not Exists ", sTopLogoFile + "," + sBotLogoFile);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, " Logo file Not Exists ", sTopLogoFile + "," + sBotLogoFile);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, " Logo file Not Exists ", sTopLogoFile + "," + sBotLogoFile);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return true;
}
foreach(String img in sLogoFiles)
{
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Logo file : "+img);
}
if (devStatus.Printer.Open == false) return false;
if (m_cPosStatus.Base.OlePosPrinterController == PosConst.POS_DEVICE_CONTROLLER.OPOS)
{
for (int i = 0; i < sLogoFiles.Length; i++)
{
posprinter.SetBitmap(i + 1, PrinterStation.Receipt, sLogoFiles[i], 496, PosPrinter.PrinterBitmapCenter);
System.Threading.Thread.Sleep(1000);
}
}
else if (m_cPosStatus.Base.OlePosPrinterController == PosConst.POS_DEVICE_CONTROLLER.RS232)
{
switch (m_cPosStatus.Base.OlePosPrinterModel)
{
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._1_TM_T88II:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._2_TM_T88III:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._3_TM_T88IV:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._4_TM_T88V:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._7_TRST_A00:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._9_TP_600:
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._10_GIANT_100S:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._1_EPSON:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._7_1NR://2018.01.22;"7:4610_1NR" 모델 추가, 이미지 처리는 _1_EPSON 과 동일;girak.kim
default:
SetBitmap_EPSON(sLogoFiles);
break;
case PosConst.POS_DEVICE_LIST.POS_PRINTER._2_TOSHIBA:
SetBitmap_TOSHIBA(sLogoFiles);
break;
//case PosConst.POS_DEVICE_LIST.POS_PRINTER._11_P2C_All_In_One:
case PosConst.POS_DEVICE_LIST.POS_PRINTER._6_P2C:
break;
}
// 이미지 upload 후 sleep 필수
System.Threading.Thread.Sleep(8000);
}
devStatus.Printer.Status = "LOGO BMP DOWN SUCCESS";
//SetTopLogo = true;
//SetBottomLogo = true;
UserLog.WriteLogFile(UserCom.LOG_OP,
UserCom.INFO_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"devStatus.Printer.Status:"+devStatus.Printer.Status);
return true;
}
catch(Exception ex)
{
devStatus.Printer.Status = "LOGO BMP DOWN FAIL";
//SetBottomLogo = false;
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetLogoBmp Exception, devStatus.Printer.Status : " + devStatus.Printer.Status);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetLogoBmp Exception, devStatus.Printer.Status : " + devStatus.Printer.Status);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetLogoBmp Exception, devStatus.Printer.Status : " + devStatus.Printer.Status);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
return false;
}
}
private void SetBitmap_TOSHIBA(string[] sFileName)
{
byte[] bytes;
try
{
int nBitmapCnt = sFileName.Length;
MemoryStream stream = new MemoryStream();
BinaryWriter bw = new BinaryWriter(stream);
for(int nRow = 0;nRow < nBitmapCnt;nRow++)
{
bw.Write((char)0x1F);
bw.Write((char)0x30);
bw.Write((byte)(3 + nRow));
byte[] raw = File.ReadAllBytes(sFileName[nRow]);
bw.Write((char)0x1F);
for(int i = 0;i < raw.Length;i++)
{
bw.Write(raw[i]);
}
}
bw.Flush();
bytes = stream.ToArray();
if (bytes != null && bytes.Length > 0)
{
TransmitCommand(bytes, false);
}
}
catch (Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetBitmap_TOSHIBA() Exception : " + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetBitmap_TOSHIBA() Exception : " + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetBitmap_TOSHIBA() Exception : " + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
/// <summary>
/// 명판 출력할 로고 이미지 Set
/// </summary>
/// <param name="sFileName">명판 출력 파일명</param>
/// <returns></returns>
private void SetBitmap_EPSON(string[] sFileName)
{
byte[] bytes;
try
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetBitmap_EPSON Start");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetBitmap_EPSON Start");
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetBitmap_EPSON Start");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
/* ──────────────────────────────────────────────────────
* [Name] Define NV bit image
* [Format] ASCII FS q n [xL xH yL yH d1...dk]1...[xL xH yL yH d1...dk]n
* Hex 1C 71 n [xL xH yL yH d1...dk]1...[xL xH yL yH d1...dk]n
* Decimal 28 113 n [xL xH yL yH d1...dk]1...[xL xH yL yH d1...dk]n
* [Description] Defines the NV bit image in the NV graphics area.
* • n specifies the number of defined NV bit images.
* • xL, xH specifies (xL + xH × 256) bytes in the horizontal direction for the NV bit image you defined.
* • yL, yH specifies (yL + yH × 256) bytes in the vertical direction for the NV bit image you defined.
* • d specifies the definition data for the NV bit image (column format).
* • k indicates the number of the definition data. k is an explanation parameter; therefore it does not need to be transmitted.
* Defined Region 1 ≤ n ≤ 255
* 0 ≤ xL ≤ 255
* 0 ≤ xH ≤ 3 However, 1 ≤ (xL+xH×256) ≤ 1023
* 0 ≤ yL ≤ 255
* 0 ≤ yH ≤ 1 However, 1 ≤ (yL+yH×256) ≤ 288
* 0 ≤ d ≤ 255
* k = (xL+xH×256) × (yL+yH×256) ×8
* Total defined data area = 2 M bytes (256 K bytes)
* ──────────────────────────────────────────────────────
*/
int nBitmapCnt = sFileName.Length;
MemoryStream stream = new MemoryStream();
BinaryWriter bw = new BinaryWriter(stream);
// 초기화
bw.Write((char)0x1B);
bw.Write((char)0x40);
//// Select pripheral device
//bw.Write((char)0x1B);
//bw.Write((char)0x3D);
//bw.Write((char)0x01);
// Define NV bit image
bw.Write((char)0x1C); // FS
bw.Write((char)0x71); // q
bw.Write((byte)nBitmapCnt);
for (int nRow = 0; nRow < nBitmapCnt; nRow++)
{
// 원본 이미지 Load
Bitmap image = new Bitmap(sFileName[nRow]);
// 1Bit Graysacle로 Convert
Bitmap bmptmp = ConvertGrayscale1or8Bit(image, 1);
byte[] raw = ConvertNVBitmap(bmptmp, true);
//byte[] raw = ConvertNVBitmap(image, true);
bw.Write(raw);
image.Dispose();
bmptmp.Dispose();
}
bw.Flush();
bytes = stream.ToArray();
if (bytes != null && bytes.Length > 0)
{
TransmitCommand(bytes, false);
}
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetBitmap_EPSON End");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetBitmap_EPSON End");
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetBitmap_EPSON End");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
catch(Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetBitmap_EPSON Exception : " + ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetBitmap_EPSON Exception : " + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_ERROR,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"SetBitmap_EPSON Exception : " + ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
private byte[] ConvertNVBitmap(Bitmap bitmap, bool bIncludeSize)
{
int baseIndex = ((bIncludeSize) ? 4 : 0);
int xSize = (bitmap.Width / 8);
if (xSize * 8 != bitmap.Width)
{
xSize++;
}
int ySize = (bitmap.Height / 8);
if (ySize * 8 != bitmap.Height)
{
ySize++;
}
byte[] raw = new byte[xSize * ySize * 8 + ((bIncludeSize) ? 4 : 0)];
try
{
for (int i = 0; i < raw.Length; raw[i++] = 0) ;
if (bIncludeSize)
{
raw[0] = (byte)(xSize & 0x00FF);
raw[1] = (byte)(xSize & 0xFF00);
raw[2] = (byte)(ySize & 0x00FF);
raw[3] = (byte)(ySize & 0xFF00);
}
int k = (raw[0] + raw[1] * 256) * (raw[2] + raw[3] * 256) * 8;
if (k > 2000000)
{
throw new Exception("Incorrect size");
}
if (raw[0] < 0 || raw[0] > 255 || raw[1] < 0 || raw[1] > 3 || (raw[0] + raw[1] * 255) < 1 || (raw[0] + raw[1] * 255) > 1023 ||
raw[2] < 0 || raw[2] > 255 || raw[3] < 0 || raw[3] > 1 || (raw[2] + raw[3] * 255) < 1 || (raw[2] + raw[3] * 255) > 288)
{
throw new Exception("Incorrect size");
}
for (int x = 0; x < bitmap.Width; x++)
{
for (int y = 0; y < bitmap.Height; y++)
{
Color color = bitmap.GetPixel(x, y);
if (RGBGreatEqual(color, 255, 255, 128))
{
continue;
}
int idx = (ySize * x) + y / 8;
byte mask = (byte)(0x80 >> (y % 8));
raw[idx + baseIndex] |= mask;
}
}
}
catch(Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + ex.Message);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
return raw;
}
private static bool RGBGreatEqual(Color c1, int R, int G, int B)
{
return (c1.R >= R && c1.G >= G && c1.B >= B);
}
private Bitmap ConvertGrayscale1or8Bit(System.Drawing.Bitmap b, int bitpixel)
{
if (bitpixel != 1 && bitpixel != 8) throw new System.ArgumentException("1 or 8", "bit");
int w = b.Width, h = b.Height;
IntPtr hbm = b.GetHbitmap();
BITMAPINFO bmi = new BITMAPINFO();
bmi.biSize = 40;
bmi.biWidth = w;
bmi.biHeight = h;
bmi.biPlanes = 1;
bmi.biBitCount = (short)bitpixel;
bmi.biCompression = BI_RGB;
bmi.biSizeImage = (uint)(((w + 7) & 0xFFFFFFF8) * h / 8);
bmi.biXPelsPerMeter = 1000000;
bmi.biYPelsPerMeter = 1000000;
uint ncols = (uint)1 << bitpixel;
bmi.biClrUsed = ncols;
bmi.biClrImportant = ncols;
bmi.cols = new uint[256];
if (bitpixel == 1) { bmi.cols[0] = MAKERGB(0, 0, 0); bmi.cols[1] = MAKERGB(255, 255, 255); }
else { for (int i = 0; i < ncols; i++) bmi.cols[i] = MAKERGB(i, i, i); }
IntPtr bits0;
IntPtr hbm0 = CreateDIBSection(IntPtr.Zero, ref bmi, DIB_RGB_COLORS, out bits0, IntPtr.Zero, 0);
IntPtr sdc = GetDC(IntPtr.Zero);
IntPtr hdc = CreateCompatibleDC(sdc); SelectObject(hdc, hbm);
IntPtr hdc0 = CreateCompatibleDC(sdc); SelectObject(hdc0, hbm0);
BitBlt(hdc0, 0, 0, w, h, hdc, 0, 0, SRCCOPY);
System.Drawing.Bitmap b0 = System.Drawing.Bitmap.FromHbitmap(hbm0);
DeleteDC(hdc);
DeleteDC(hdc0);
ReleaseDC(IntPtr.Zero, sdc);
DeleteObject(hbm);
DeleteObject(hbm0);
return b0;
}
private static uint MAKERGB(int r, int g, int b)
{
return ((uint)(b & 255)) | ((uint)((r & 255) << 8)) | ((uint)((g & 255) << 16));
}
#endregion
#region (RS232통신)
private void WriteData(string sText)
{
byte[] outputBytes = System.Text.Encoding.Default.GetBytes(sText);
TransmitCommand(outputBytes);
}
/// <summary>
/// 텍스트 왼쪽 정렬로 출력 후 Line feed
/// </summary>
/// <param name="sText"></param>
/// <returns></returns>
private void WriteLine(string sText, int nAlign = PosConst.PRINT_ALIGN.LEFT_ALIGN)
{
sText = sText.Trim('\n').Trim('\r');
byte[] outputBytes = System.Text.Encoding.Default.GetBytes(sText);
if (nAlign == PosConst.PRINT_ALIGN.LEFT_ALIGN)
{
TransmitCommand(PosConst.ESCP_COMMAND.LEFT_ALIGN, false);
}
else if (nAlign == PosConst.PRINT_ALIGN.CENTER_ALIGN)
{
TransmitCommand(PosConst.ESCP_COMMAND.CENTER_ALIGN, false);
}
else if (nAlign == PosConst.PRINT_ALIGN.RIGHT_ALIGN)
{
TransmitCommand(PosConst.ESCP_COMMAND.RIGHT_ALIGN, false);
}
TransmitCommand(outputBytes);
TransmitCommand(PosConst.ESCP_COMMAND.LEFT_ALIGN, false);
TransmitCommand(PosConst.ESCP_COMMAND.LINE_FEED);
}
/// <summary>
/// BOLD 옵션으로 텍스트 출력 후 Line feed
/// </summary>
/// <param name="sText"></param>
/// <returns></returns>
private void WriteLineBold(string sText, int nAlign = PosConst.PRINT_ALIGN.LEFT_ALIGN)
{
TransmitCommand(PosConst.ESCP_COMMAND.BOLD_ON);
WriteLine(sText, nAlign);
TransmitCommand(PosConst.ESCP_COMMAND.BOLD_OFF);
}
/// <summary>
/// 텍스트를 가로, 세로 2배 확대로 출력 후 Line feed
/// </summary>
/// <param name="sText"></param>
/// <returns></returns>
private void WriteLineZoom(string sText, int nAlign = PosConst.PRINT_ALIGN.LEFT_ALIGN)
{
TransmitCommand(PosConst.ESCP_COMMAND.ZOOM_ON);
WriteLine(sText, nAlign);
TransmitCommand(PosConst.ESCP_COMMAND.ZOOM_OFF);
}
/// <summary>
/// 텍스트를 가로 2배 확대로 출력 후 Line feed
/// </summary>
/// <param name="sText"></param>
/// <returns></returns>
private void WriteLineWidthX2(string sText, int nAlign = PosConst.PRINT_ALIGN.LEFT_ALIGN)
{
TransmitCommand(PosConst.ESCP_COMMAND.WIDTH_X2_ON);
WriteLine(sText, nAlign);
TransmitCommand(PosConst.ESCP_COMMAND.WIDTH_X2_OFF);
}
/// <summary>
/// 텍스트를 세로 2배 확대로 출력 후 Line feed
/// </summary>
/// <param name="sText"></param>
/// <returns></returns>
private void WriteLineHeightX2(string sText, int nAlign = PosConst.PRINT_ALIGN.LEFT_ALIGN)
{
TransmitCommand(PosConst.ESCP_COMMAND.HEIGHT_X2_ON);
WriteLine(sText, nAlign);
TransmitCommand(PosConst.ESCP_COMMAND.HEIGHT_X2_OFF);
}
/// <summary>
/// Set line spacing
/// </summary>
/// <param name="nLines">nLines < 0 일 경우, Set default line spacing</param>
/// <returns></returns>
private void SetLineSpace(int nLines)
{
if (nLines >= 0)
{
TransmitCommand(buildESCPCommand(PosConst.ESCP_COMMAND.SET_LINE_SPACING, (byte)nLines));
}
else
{
TransmitCommand(PosConst.ESCP_COMMAND.SET_DEFAULT_LINE_SPACING);
}
}
/// <summary>
/// Underline 옵션으로 텍스트 출력 후 Line feed
/// </summary>
/// <param name="sText"></param>
/// <returns></returns>
private void WriteLineUnderline(string sText, int nAlign = PosConst.PRINT_ALIGN.LEFT_ALIGN)
{
TransmitCommand(PosConst.ESCP_COMMAND.UNDERLINE_ON);
WriteLine(sText, nAlign);
TransmitCommand(PosConst.ESCP_COMMAND.UNDERLINE_OFF);
}
#endregion
#region (RS232)
private byte[] buildESCPCommand(byte[] command, byte[] args)
{
byte[] ESCPCommand = new byte[command.Length + args.Length];
Array.Copy(command, 0, ESCPCommand, 0, command.Length);
Array.Copy(args, 0, ESCPCommand, command.Length, args.Length);
return ESCPCommand;
}
private byte[] buildESCPCommand(byte[] command, byte arg)
{
byte[] ESCPCommand = new byte[command.Length + 1];
Array.Copy(command, 0, ESCPCommand, 0, command.Length);
ESCPCommand[command.Length] = arg;
return ESCPCommand;
}
//20180611 프린터 미출력 개선 02Printer.exe start
//기존
#if(PRT_O2PRINTER)
#else
private void TransmitCommand(byte[] aCmd, bool bSleepOn = true)
#endif
//변경
#if(PRT_O2PRINTER)
private void TransmitCommand(byte[] aCmd, bool bSleepOn = true, bool bHeathChk = false)
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
{
try
{
//20180611 프린터 미출력 개선 02Printer.exe start
//기존
#if(PRT_O2PRINTER)
#else
if (m_serialPort.IsOpen == true)
{
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
int iOffset = 0;
// Send 를 위한 buffer 크기를 1024 byte 로 고정(20170608)
int iReadBuf = 1024;
//int iReadBuf = m_serialPort.WriteBufferSize;
while (true)
{
if (iOffset >= aCmd.Length)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "TransmitCommand Finish " + aCmd.Length.ToString() + "," + iOffset.ToString());
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "TransmitCommand Finish " + aCmd.Length.ToString() + "," + iOffset.ToString());
#else
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "TransmitCommand Finish " + aCmd.Length.ToString() + "," + iOffset.ToString());
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
break;
}
if (iReadBuf + iOffset > aCmd.Length)
{
iReadBuf = aCmd.Length - iOffset;
}
//#20180123 프린터 다운 현상 관련 로그 추가 start
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Prineter Write : TransmitCommand() Start");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Prineter Write : TransmitCommand() Start");
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Prineter Write : TransmitCommand() Start");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
//#20180123 프린터 다운 현상 관련 로그 추가 end
// grayber@20180124 프린터 출력관련 오류 수정 start - 프린터 배열 오프셋 설정 오류로 변수 변경
//기존
//m_serialPort.Write(aCmd, iOffset, aCmd.Length);
//수정
//#20180329 프린터 간헐적 미출력 증상 수정 start
//전체 버퍼 한번에 출력 하도록 수정
#if(PRT_ALLWRITE) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Prineter Write data: " + Encoding.Default.GetString(aCmd));
m_serialPort.Write(Encoding.Default.GetString(aCmd));
//m_serialPort.Write(aCmd, iOffset, aCmd.Length);
#else
//20180611 프린터 미출력 개선 02Printer.exe start
//기존
#if(PRT_O2PRINTER)
#else
m_serialPort.Write(aCmd, iOffset, iReadBuf);
#endif
//변경
#if(PRT_O2PRINTER)
// TCP 접속 정보
string sPrtTcpIp = "127.0.0.1";
string sPrtTcpPort = "9110";
// 프린터 PORT 번호
string sPrtPort = CmUtil.MidH(m_cPosStatus.Base.OlePosPrinterSerialPortNumber, 3, m_cPosStatus.Base.OlePosPrinterSerialPortNumber.Length - 3);
//Connect
int iRet = OpenPrtTcpDevice(sPrtTcpIp, int.Parse(sPrtTcpPort));
//#20181114 영수증 프린터 base63로 전송 start
//기존
#region
//출력
// 0001: 출력, 0002: 헬스체크
string sPrtGb = "0001";
string sTimeOut = "00000";
if (bHeathChk == true)
{
sPrtGb = "0002";
sTimeOut = "00500";
}
else if (bHeathChk == false)
{
sPrtGb = "0001";
sTimeOut = "00000";
}
// tcp 헤더
string sCommHeader = sPrtGb + // 0001: 출력, 0002: 헬스체크
string.Format("{0:D2}", Convert.ToInt32(sPrtPort)) + // 01,02,03 포트번호
string.Format("{0:D6}", (int)m_cPosStatus.Base.OlePosPrinterSerialBaudRate) + // 프린터 속도
sTimeOut + // 타임아웃
string.Format("{0:D6}", (int)aCmd.Length); // 출력 데이터 길이
// tcp 종료구분자
string sETX = string.Format("{0}", (char)0x03) +
string.Format("{0}", (char)0x03) +
string.Format("{0}", (char)0x03);
// tcp 헤더 byte로 변환
byte[] sSendbt = null;
sSendbt = Encoding.Default.GetBytes(sCommHeader);
// tcp 종료구분자 byte로 변환
byte[] byEtx = null;
byEtx = Encoding.Default.GetBytes(sETX);
// 전체 tcp 전송 데이터 byte 배열 생성
byte[] sSendData = new byte[sSendbt.Length + aCmd.Length + byEtx.Length];
// sSendData 배열에 tcp 헤더 데이터 복사
Array.Copy(sSendbt, 0, sSendData, 0, sSendbt.Length);
// sSendData 배열에 영수증 출력 데이터 복사
Array.Copy(aCmd, 0, sSendData, sSendbt.Length, aCmd.Length);
// sSendData 배열에 tcp 종료구분자 복사
Array.Copy(byEtx, 0, sSendData, sSendbt.Length + aCmd.Length, byEtx.Length);
// 응답 배열 초기화
bytRecvBuff = null;
// 전체 한번에 전송하기 위에 전송 길이 재설정
iOffset += aCmd.Length;
// byte[], int, ref byte[], int
int iPrtSendSocket = m_cPrtSocket.Prt_ByPassSendReceiveData(sSendData, lRecvLen, ref bytRecvBuff, lTimeout);
//string sTemp0 = Encoding.Default.GetString(aCmd);
#endregion
//변경
#region
/*
//출력
// 0101: 출력, 0102: 헬스체크
string sPrtGb = "0101";
string sTimeOut = "00000";
if (bHeathChk == true)
{
sPrtGb = "0102";
sTimeOut = "00500";
}
else if (bHeathChk == false)
{
sPrtGb = "0101";
sTimeOut = "00000";
}
string sSendDataBase64 = Convert.ToBase64String(aCmd);
byte[] btSendDataBase64 = Encoding.Default.GetBytes(sSendDataBase64);
// tcp 헤더
string sCommHeader = sPrtGb + // 0001: 출력, 0002: 헬스체크
string.Format("{0:D2}", Convert.ToInt32(sPrtPort)) + // 01,02,03 포트번호
string.Format("{0:D6}", (int)m_cPosStatus.Base.OlePosPrinterSerialBaudRate) + // 프린터 속도
sTimeOut + // 타임아웃
string.Format("{0:D6}", (int)btSendDataBase64.Length); // 출력 데이터 길이
// tcp 종료구분자
string sETX = string.Format("{0}", (char)0x03) +
string.Format("{0}", (char)0x03) +
string.Format("{0}", (char)0x03);
// tcp 헤더 byte로 변환
byte[] sSendbt = null;
sSendbt = Encoding.Default.GetBytes(sCommHeader);
// tcp 종료구분자 byte로 변환
byte[] byEtx = null;
byEtx = Encoding.Default.GetBytes(sETX);
// 전체 tcp 전송 데이터 byte 배열 생성
byte[] sSendData = new byte[sSendbt.Length + btSendDataBase64.Length + byEtx.Length];
// sSendData 배열에 tcp 헤더 데이터 복사
Array.Copy(sSendbt, 0, sSendData, 0, sSendbt.Length);
// sSendData 배열에 영수증 출력 데이터 복사
Array.Copy(btSendDataBase64, 0, sSendData, sSendbt.Length, btSendDataBase64.Length);
// sSendData 배열에 tcp 종료구분자 복사
Array.Copy(byEtx, 0, sSendData, sSendbt.Length + btSendDataBase64.Length, byEtx.Length);
// 응답 배열 초기화
bytRecvBuff = null;
// 전체 한번에 전송하기 위에 전송 길이 재설정
iOffset += aCmd.Length;
// byte[], int, ref byte[], int
int iPrtSendSocket = m_cPrtSocket.Prt_ByPassSendReceiveData(sSendData, lRecvLen, ref bytRecvBuff, lTimeout);
//string sTemp0 = Encoding.Default.GetString(aCmd);
//string sTemp1 = Encoding.Default.GetString(btSendDataBase64);
//byte[] sBtTemp1 = Convert.FromBase64String(sTemp1);
//string sTemp2 = Encoding.Default.GetString(sBtTemp1);
*/
#endregion
//#20181114 영수증 프린터 base63로 전송 end
//System.Threading.Thread.Sleep(2000);
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
// grayber@20180124 프린터 출력관련 오류 수정 end
//#20180329 프린터 간헐적 미출력 증상 수정 start
//프린터 ErrorReceived
#if(PRT_RECVERR) //프린터 포트 동작 변경시
//m_serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);
m_serialPort.ErrorReceived += new SerialErrorReceivedEventHandler(serialPort_ErrorReceived);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
//#20180123 프린터 다운 현상 관련 로그 추가 start
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Prineter Write : TransmitCommand() End");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Prineter Write : TransmitCommand() End");
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Prineter Write : TransmitCommand() End");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
//#20180123 프린터 다운 현상 관련 로그 추가 end
//#20180329 프린터 간헐적 미출력 증상 수정 start
//20180611 프린터 미출력 개선 02Printer.exe start
//기존
#if(PRT_O2PRINTER)
#else
//전체 버퍼 한번에 출력 하도록 수정
#if(PRT_ALLWRITE) //프린터 포트 동작 변경시
iOffset += aCmd.Length;
#else
iOffset += iReadBuf;
#endif
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
//#20180329 프린터 간헐적 미출력 증상 수정 end
System.Threading.Thread.Sleep(10);
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, aCmd.Length.ToString() + "," + iOffset.ToString());
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, aCmd.Length.ToString() + "," + iOffset.ToString());
#else
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, aCmd.Length.ToString() + "," + iOffset.ToString());
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
//m_serialPort.Write(Encoding.Default.GetString(aCmd, 0, aCmd.Length));
if (bSleepOn == true) System.Threading.Thread.Sleep(30);
//20180611 프린터 미출력 개선 02Printer.exe start
//기존
#if(PRT_O2PRINTER)
#else
}
else
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Serial Port Is Not Opened");
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Serial Port Is Not Opened");
#else
UserLog.WriteLogFile(UserCom.LOG_IOS, UserCom.WARNING_LEVEL, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, "Serial Port Is Not Opened");
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
}
catch(Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
devStatus.Printer.Status);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + devStatus.Printer.Status);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
devStatus.Printer.Status);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
this.CloseDevice();
}
//#20180329 프린터 간헐적 미출력 증상 수정 start
//출력 할때 마다 open, close 하는 부분 한번만 하도록 수정
#if(PRT_ERROR) //프린터 포트 동작 변경시
finally
{
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Prineter Write : TransmitCommand() finally");
}
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
#endregion
#region Open함수
/// <summary>
/// 돈통 Open 함수
/// </summary>
public void OpenCashDrawer()
{
try
{
if (m_cPosStatus.Base.OlePosCashDrawerType == PosConst.POS_DEVICE_LIST.CASHDRAWER._1_PRINTER)
{
this.AddToPrinterBuffer(Encoding.UTF8.GetBytes(CMD_OPEN_CASHDRAWER));
//if (devStatus.Printer.Open == false)
//{
// this.OpenDevice(PosConst.OPOS_DEVICE.POSPRINTER, PosConst.OPOS_LDN.POSPRINTER);
//}
//switch (m_cPosStatus.Base.OlePosPrinterModel)
//{
// case PosConst.POS_DEVICE_LIST.POS_PRINTER._1_EPSON:
// case PosConst.POS_DEVICE_LIST.POS_PRINTER._6_P2C:
// default:
// TransmitCommand(PosConst.ESCP_COMMAND.OPEN_CASHDRAWER);
// break;
// case PosConst.POS_DEVICE_LIST.POS_PRINTER._2_TOSHIBA:
// TransmitCommand(PosConst.ESCP_COMMAND.OPEN_CASHDRAWER_FOR_TOSHIBA);
// break;
//}
//if(devStatus.Printer.Open == true)
//{
// this.CloseDevice();
//}
}
}
catch(Exception ex)
{
//#20180329 프린터 간헐적 미출력 증상 수정 start
//로그 생성 위치 변경 UserCom.LOG_IOS, LOG_ERROR -> UserCom.LOG_OP
//기존
/*
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
devStatus.Printer.Status);
*/
//변경
#if(PRT_ERROR) //프린터 포트 동작 변경시
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"Exception :" + devStatus.Printer.Status);
#else
UserLog.WriteLogFile(UserCom.LOG_IOS,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
devStatus.Printer.Status);
#endif
//#20180329 프린터 간헐적 미출력 증상 수정 end
}
}
//20180611 프린터 미출력 개선 02Printer.exe start
//변경
#if(PRT_O2PRINTER)
#region Printer OPEN / CLOSE
public int OpenPrtTcpDevice(string sIp, int iPort)
{
int iRet = UserCom.NG;
try
{
// PING 테스트로 프린터 가능여부 확인(2017.05.30)
if (CmUtil.PingTest(sIp) == false)
{
if (CmUtil.PingTest(sIp) == false)
{
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"PrtTcp PingTest Fail");
return iRet;
}
}
m_cPrtSocket = new TcpSocket(sIp, iPort, lTimeout);
if (m_cPrtSocket == null)
{
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"TcpSocket null");
return -9;
}
// 접속 3회 시도
for (int nLoop = 0; nLoop < 1; nLoop++)
{
try
{
iRet = m_cPrtSocket.Connect(-1);
}
catch (Exception ex)
{
iRet = UserCom.NG;
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"PrtTcp Exception Error=" + ex.Message);
m_cPrtSocket.Close();
continue;
}
// 접속 실패
if (iRet != UserCom.OK)
{
iRet = UserCom.NG;
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
"PrtTcp(Ethernet) Connect Error");
m_cPrtSocket.Close();
continue;
}
break;
}
return iRet;
}
catch (Exception ex)
{
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
return -99;
}
}
public void ClosePrtTcpDevice()
{
try
{
if (m_cPrtSocket != null)
{
m_cPrtSocket.Close();
m_cPrtSocket = null;
}
}
catch (Exception ex)
{
UserLog.WriteLogFile(UserCom.LOG_OP,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.Message);
}
}
#endregion
#endif
//20180611 프린터 미출력 개선 02Printer.exe end
#endregion
}
}