// Card123Dlg.cpp : 구현 파일
//

#include "stdafx.h"
#include "Card123.h"
#include "Card123Dlg.h"
#include <stdlib.h>

CWoosimPrinter woosimprinter;

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// 응용 프로그램 정보에 사용되는 CAboutDlg 대화 상자입니다.

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// 대화 상자 데이터입니다.
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 지원입니다.

// 구현입니다.
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CCard123Dlg 대화 상자




CCard123Dlg::CCard123Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCard123Dlg::IDD, pParent)
	, m_strReceivedata(_T(""))
	, m_strStatus(_T(""))
	, m_strMsg(_T(""))
	, m_strCardNo(_T(""))
	, m_strValidDate(_T(""))
	, m_SetIP(_T("174.100.169.243"))
	
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCard123Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, m_strReceivedata);
	DDX_Control(pDX, IDC_BUTTON_HEX, m_btnCtrlHex);
	DDX_Control(pDX, IDC_BUTTON_ASCII, m_btnCtrlAscii);
	DDX_Text(pDX, IDC_STATIC_PORTSTATUS, m_strStatus);
	DDX_Text(pDX, IDC_STATIC_STATUSMSG, m_strMsg);
	DDX_Text(pDX, IDC_STATIC_CARDNO, m_strCardNo);

	DDX_Control(pDX, IDC_COMBO_PORT, m_cboCtrlPort);
	DDX_Control(pDX, IDC_COMBO_BAUD, m_cboCtrlBaud);
	DDX_Control(pDX, IDC_COMBO_PROTOCOL, m_cboCtrlProtocol);
	DDX_Text(pDX, IDC_STATIC_DATA, m_strValidDate);
	DDX_Text(pDX, IDC_EDIT2, m_SetIP);
	DDX_Control(pDX, IDC_CHECK_TCPIP, m_chkCtrlTcpip);
}

BEGIN_MESSAGE_MAP(CCard123Dlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_BUTTON_OPEN, &CCard123Dlg::OnBnClickedButtonOpen)
	ON_BN_CLICKED(IDC_BUTTON_2Track, &CCard123Dlg::OnBnClickedButton2track)
	ON_BN_CLICKED(IDC_BUTTON_3Track, &CCard123Dlg::OnBnClickedButton3track)
	ON_BN_CLICKED(IDC_BUTTON_23Track, &CCard123Dlg::OnBnClickedButton23track)
	ON_BN_CLICKED(IDC_BUTTON_Cancel, &CCard123Dlg::OnBnClickedButtonCancel)
	ON_BN_CLICKED(IDC_BUTTON_HEX, &CCard123Dlg::OnBnClickedButtonHex)
	ON_BN_CLICKED(IDC_BUTTON_ASCII, &CCard123Dlg::OnBnClickedButtonAscii)
	ON_BN_CLICKED(IDC_BUTTON_PRINT, &CCard123Dlg::OnBnClickedButtonPrint)
	ON_BN_CLICKED(IDC_BUTTON_PRINT4, &CCard123Dlg::OnBnClickedButtonPrint4)
	ON_BN_CLICKED(IDC_BUTTON_PRINT2, &CCard123Dlg::OnBnClickedButtonPrint2)
	ON_BN_CLICKED(IDC_BUTTON_PRINT3, &CCard123Dlg::OnBnClickedButtonPrint3)
	ON_BN_CLICKED(IDC_BUTTON_CLOSE, &CCard123Dlg::OnBnClickedButtonClose)
END_MESSAGE_MAP()


// CCard123Dlg 메시지 처리기

BOOL CCard123Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 시스템 메뉴에 "정보..." 메뉴 항목을 추가합니다.

	// IDM_ABOUTBOX는 시스템 명령 범위에 있어야 합니다.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 이 대화 상자의 아이콘을 설정합니다. 응용 프로그램의 주 창이 대화 상자가 아닐 경우에는
	//  프레임워크가 이 작업을 자동으로 수행합니다.
	SetIcon(m_hIcon, TRUE);			// 큰 아이콘을 설정합니다.
	SetIcon(m_hIcon, FALSE);		// 작은 아이콘을 설정합니다.

	
	m_cboCtrlPort.SetCurSel(0);
	m_cboCtrlBaud.SetCurSel(5);
	m_cboCtrlProtocol.SetCurSel(0);

	return TRUE;  // 포커스를 컨트롤에 설정하지 않으면 TRUE를 반환합니다.
}

void CCard123Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 대화 상자에 최소화 단추를 추가할 경우 아이콘을 그리려면
//  아래 코드가 필요합니다. 문서/뷰 모델을 사용하는 MFC 응용 프로그램의 경우에는
//  프레임워크에서 이 작업을 자동으로 수행합니다.

void CCard123Dlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 그리기를 위한 디바이스 컨텍스트

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 클라이언트 사각형에서 아이콘을 가운데에 맞춥니다.
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 아이콘을 그립니다.
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// 사용자가 최소화된 창을 끄는 동안에 커서가 표시되도록 시스템에서
//  이 함수를 호출합니다.
HCURSOR CCard123Dlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CCard123Dlg::OnBnClickedButtonOpen()
{
	UpdateData(TRUE);
	m_strMsg = _T("");
	m_strStatus = _T("");

	woosimprinter.ClosePrinter();

	int BaudRate;
	CString SetPort;

	switch (m_cboCtrlPort.GetCurSel())
	{
		case 0 : SetPort = _T("COM1:");
			break;
		case 1 : SetPort = _T("COM2:");
			break;
		case 2 : SetPort = _T("COM3:");
			break;
		case 3 : SetPort = _T("COM4:");
			break;
		case 4 : SetPort = _T("COM5:");
			break;
		case 5 : SetPort = _T("COM6:"); 
			break;
		case 6 : SetPort = _T("COM7:");
			break;
		case 7 : SetPort = _T("COM8:");
			break;
	}

	switch (m_cboCtrlBaud.GetCurSel())
	{
		case 0 : BaudRate = 2400;
			break;
		case 1 : BaudRate = 4800;
			break;
		case 2 : BaudRate = 9600;
			break;
		case 3 : BaudRate = 19200;
			break;
		case 4 : BaudRate = 38400;
			break;
		case 5 : BaudRate = 57600; 
			break;
		case 6 : BaudRate = 115200; 
			break;
	}


	char* Serial_buff = new char[strlen(CT2A(SetPort))+1];
	strcpy(Serial_buff, CT2A(SetPort));

	char* Wlan_buff = new char[strlen(CT2A(m_SetIP))+1];
	strcpy(Wlan_buff, CT2A(m_SetIP));

	if(m_chkCtrlTcpip.GetCheck())
	{
		switch(m_cboCtrlProtocol.GetCurSel())
		{
			case 0 :
				iRet = woosimprinter.InitWlanPrinter(Wlan_buff,1470, 3000, FALSE);
				break;
			case 1 :
				iRet = woosimprinter.InitWlanPrinter(Wlan_buff,1470, 3000, TRUE);
				break;
		}
		switch (iRet)
		{

			case 1 : 
				m_strStatus = _T("Success");
				break;
			case -1 : 
				m_strStatus = _T("Socket Error");
				break;

			case -2 : 
				m_strStatus = _T("Connect Fail");
				break;
			case -3 : 
				m_strStatus =_T("Already Connected");
				break;
			case -5 : 
				m_strStatus =_T("No response from printer");
				break;	
			default :
				m_strStatus.Format(_T("%d"),iRet);
				break;		
		}
	}
	else
	{
		switch (m_cboCtrlProtocol.GetCurSel())
		{
			case 0 : 
				iRet= woosimprinter.InitPrinter(Serial_buff, BaudRate,FALSE);
				break;
			case 1 :
				iRet= woosimprinter.InitPrinter(Serial_buff, BaudRate,TRUE);
				break;
		}
		switch (iRet)
		{
			case 1 : 
				m_strStatus = _T("Success");
				break;
			case -1 : 
				m_strStatus = _T("Already opened");
				break;
			case -2 : 
				m_strStatus =_T("Unable to open the port");
				break;
			case -3 : 
				m_strStatus = _T("Unable to configure the serial port");
				break;
			case -4 : 
				m_strStatus =_T("Unable to set the timeout parameters");
				break;		
			case -5 : 
				m_strStatus =_T("No response from printer");
			default :
				m_strStatus.Format(_T("%d"),iRet);
				break;		
		}
	}

	delete[] Serial_buff;
	delete[]  Wlan_buff;
	UpdateData(FALSE);
}

void CCard123Dlg::OnBnClickedButton2track()
{
	m_strMsg = _T("");
	m_strCardNo = _T("");
	m_strValidDate = _T("");
	m_strReceivedata = _T("");
	m_btnCtrlHex.EnableWindow(FALSE);
	m_btnCtrlHex.ShowWindow(SW_HIDE);
	m_btnCtrlAscii.EnableWindow(FALSE);
	m_btnCtrlAscii.ShowWindow(SW_HIDE);	
	UpdateData(FALSE);
	woosimprinter.CardRead(FALSE);
}

void CCard123Dlg::OnBnClickedButton3track()
{
	m_strMsg = _T("");
	m_strCardNo = _T("");
	m_strValidDate = _T("");
	m_strReceivedata = _T("");
	m_btnCtrlHex.EnableWindow(FALSE);
	m_btnCtrlHex.ShowWindow(SW_HIDE);
	m_btnCtrlAscii.EnableWindow(FALSE);
	m_btnCtrlAscii.ShowWindow(SW_HIDE);	
	UpdateData(FALSE);
	woosimprinter.CardRead(TRUE);
}

void CCard123Dlg::OnBnClickedButton23track()
{
	m_strMsg = _T("");
	m_strCardNo = _T("");
	m_strValidDate = _T("");
	m_strReceivedata = _T("");
	m_btnCtrlHex.EnableWindow(FALSE);
	m_btnCtrlHex.ShowWindow(SW_HIDE);
	m_btnCtrlAscii.EnableWindow(FALSE);
	m_btnCtrlAscii.ShowWindow(SW_HIDE);	
	UpdateData(FALSE);

	BYTE Card23[]  = {0x1b,0x4d,0x45};
   	woosimprinter.ControlCommand(Card23, 3);
	woosimprinter.PrintSpool();
}

void CCard123Dlg::OnBnClickedButtonCancel()
{
	m_strMsg = _T("");
	m_strCardNo = _T("");
	m_strValidDate = _T("");
	m_strReceivedata = _T("");
	m_btnCtrlHex.EnableWindow(FALSE);
	m_btnCtrlHex.ShowWindow(SW_HIDE);
	m_btnCtrlAscii.EnableWindow(FALSE);
	m_btnCtrlAscii.ShowWindow(SW_HIDE);	
	UpdateData(FALSE);
	woosimprinter.CardCancel();
}

void CCard123Dlg::OnBnClickedButtonHex()
{
	m_btnCtrlHex.EnableWindow(FALSE);
	m_btnCtrlHex.ShowWindow(SW_HIDE);
	m_btnCtrlAscii.EnableWindow(TRUE);
	m_btnCtrlAscii.ShowWindow(SW_SHOW);
	m_strReceivedata = strDataHex;
	UpdateData(FALSE);
}

void CCard123Dlg::OnBnClickedButtonAscii()
{
	m_btnCtrlAscii.EnableWindow(FALSE);
	m_btnCtrlAscii.ShowWindow(SW_HIDE);
	m_btnCtrlHex.EnableWindow(TRUE);
	m_btnCtrlHex.ShowWindow(SW_SHOW);
	m_strReceivedata = strDataAscii;
	UpdateData(FALSE);
}

void CCard123Dlg::OnBnClickedButtonPrint()
{
	m_strMsg = _T("");
	UpdateData(FALSE);
	
	//print init
	BYTE init[]={0x1b,0x40};
	woosimprinter.ControlCommand(init, 2);

	//Title
	woosimprinter.SaveSpool("  SALES  SLIP\r\n", 3, TRUE);
	woosimprinter.SaveSpool("--------------------------------\r\n", 0,FALSE );

	//Company
	woosimprinter.SaveSpool("MERCHANT NAME      Woosim Coffee\r\n", 0, TRUE);

	//Reg Number
	woosimprinter.SaveSpool("MASTER                LEE IL BOK\r\n", 0 ,FALSE);

	//Address
	woosimprinter.SaveSpool("ADDRESS\r\n #501, DaerungTechnotown3th 448,\r\n  Gasan-dong, Geumchun-gu, Seoul\r\n  Korea\r\n", 0,0 );

	//Tel
	woosimprinter.SaveSpool("HELP DESK       (+82-2)2107-3714\r\n", 0 ,FALSE);
	woosimprinter.SaveSpool("--------------------------------\r\n\r\n", 0 ,FALSE);
	woosimprinter.SaveSpool("        WOOSIM  CARD \r\n", 1 ,0);
	woosimprinter.SaveSpool("--------------------------------\r\n", 0 ,0);

	//Card number
	woosimprinter.SaveSpool("CARD NO.     9445 4103 9533 2096\r\n", 0 ,FALSE);

	woosimprinter.SaveSpool("EXPIRY                 2012 / 10\r\n", 0 ,FALSE);
	woosimprinter.SaveSpool("--------------------------------\r\n", 0,0 );

	woosimprinter.SaveSpool("TRANS. YEAR & DATE    2011/04/11\r\n", 0 ,FALSE);
	
	woosimprinter.SaveSpool("TRANS CLASS             [Credit]\r\n", 0 ,FALSE);
	woosimprinter.SaveSpool("TERMINAL ID.           123456789\r\n", 0 ,FALSE);
	woosimprinter.SaveSpool("APPROVAL NO.           987654321\r\n", 0 ,FALSE);
	woosimprinter.SaveSpool("AMOUNT                   500.00$\r\n", 0 ,FALSE);
	
	woosimprinter.SaveSpool("--------------------------------\r\n", 0 ,0);

	woosimprinter.SaveSpool("SIGNATURE: \r\n\r\n\r\n\r\n\r\n", 0,0 );
	woosimprinter.SaveSpool("--------------------------------\r\n", 0 ,0);

	woosimprinter.PrintSpool();
}


void CCard123Dlg::OnBnClickedButtonPrint4()
{
	m_strMsg = _T("");
	UpdateData(FALSE);
	UpdateData();
	CString strTmp;

	//printer init
	BYTE Print_init[]={0x1b,0x40};
	woosimprinter.ControlCommand(Print_init, 2);

	//page mode
	BYTE Pagemode[]={0x1b,0x4c};
	woosimprinter.ControlCommand(Pagemode, 2);

	//page area setting
	//1inch printer width : 192dot = 0xC0
	//2inch printer width : 384dot = 0x180
	//3inch printer width : 576dot = 0x240
	//4inch printer width : 832dot = 0x340


	//page area set
	//3inch printer width : 576dot = 0x240
	//Page Size setting ESC W   384x176x2 bitmap
	// 1dot = 0.0125cm  
	// calculation : X : 0x180 => 384(decimal,2inch width)  
	//	              Y : 0xa7  => 167(decimal) => 167*0.0125 = 2.08cm
	BYTE Pagesize[]={0x1b,0x57, 0x00,0x00, 0x00,0x00, 0x80,0x01,0xa7,0x00};
	woosimprinter.ControlCommand(Pagesize, 10);

	//page area clear
	BYTE can[]={0x18};
	woosimprinter.ControlCommand(can, 1);

	//bitmap 
	woosimprinter.BmpSaveSpool("\\woosim.bmp",0,0);

	//page area print
	BYTE FF[]={0x0c};
	woosimprinter.ControlCommand(FF, 1);

	woosimprinter.PrintSpool();

}

void CCard123Dlg::OnBnClickedButtonPrint2()
{
	m_strMsg = _T("");
	UpdateData(FALSE);
	UpdateData();
	CString strTmp;

	///////////////////////
	// Barcode    
	//
	//barcode type	

	//#define UPCA									65
	//#define UPCE									66
	//#define EAN13									67
	//#define EAN8									68
	//#define CODE39									69
	//#define ITF										70
	//#define CODABAR									71
	//#define CODE93									72
	//#define CODE128									73

	//printer width
	//#define _2INCH									384
	//#define _3INCH									576
	//#define _4INCH									832

	//Printer initialization ESC @
	BYTE Print_init[] = { 0x1b, 0x40 };
	woosimprinter.ControlCommand(Print_init, 2);

	//Barcode Print	
	woosimprinter.BarcodeSaveSpool(UPCA, 2, 100, true, "12345678901", _2INCH, 200, 50);
	woosimprinter.BarcodeSaveSpool(UPCE, 2, 100, true, "02345678901", _2INCH, 200, 50);
	woosimprinter.BarcodeSaveSpool(EAN13, 2, 100, true, "12345678901", _2INCH, 200, 100);
	woosimprinter.BarcodeSaveSpool(EAN8, 2, 100, true, "12345678", _2INCH, 200, 150);
	woosimprinter.BarcodeSaveSpool(CODE39, 2, 100, true, "12345678901", _2INCH, 200, 200);
	woosimprinter.BarcodeSaveSpool(ITF, 2, 100, true, "123456", _2INCH, 200, 250);
	woosimprinter.BarcodeSaveSpool(CODABAR, 2, 100, true, "123456", _2INCH, 200, 0);
	woosimprinter.BarcodeSaveSpool(CODE93, 2, 100, true, "12345678901", _2INCH, 200, 0);
	woosimprinter.BarcodeSaveSpool(CODE128, 2, 100, true, "12345678901", _2INCH, 200, 0);

	woosimprinter.PrintSpool();

	///////////////////////////////////////////////////////////////
	//Barcode command
	//
	/*
	//Printer initialization ESC @
	BYTE Print_init[]={0x1b,0x40};
	woosimprinter.ControlCommand(Print_init, 2);

	//print 
	BYTE FF[]={0x0c};

	//Barcode height GS k
	BYTE GS_h[] = {0x1d, 0x68, 0x44};
	woosimprinter.ControlCommand(GS_h,3);

	//barcode width GS w
	BYTE GS_w[] = {0x1d, 0x77, 0x02};
	woosimprinter.ControlCommand(GS_w,3);

	//HRI  character print  GS H
	BYTE GS_H[] = {0x1d, 0x48, 0x01};

	woosimprinter.SaveSpool("UPC-A\r\n",0);
	BYTE GS_k41[] = {0x1d, 0x6b, 0x41 , 0x0b, 0X30, 0x31 , 0x32 , 0x33 , 0x34 , 0x35 , 0x36 , 0x37 , 0x38 , 0x39, 0x30};
	woosimprinter.ControlCommand(GS_k41,15);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);

	woosimprinter.SaveSpool("UPC-E\r\n",0);	
	BYTE GS_k42[] = {0x1d, 0x6b, 0x42 , 0x0b, 0x30, 0X30, 0x31 , 0x32 , 0x33 , 0x34 , 0x35 , 0x36 , 0x37 , 0x38 , 0x39};
	woosimprinter.ControlCommand(GS_k42,15);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);

	woosimprinter.SaveSpool("EAN13\r\n",0);
	BYTE GS_k43[] = {0x1d, 0x6b, 0x43 , 0x0b, 0x31 , 0x32 , 0x33 , 0x34 , 0x35 , 0x36 , 0x37 , 0x38 , 0x39, 0x30, 0x31};
	woosimprinter.ControlCommand(GS_k43,15);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);

	woosimprinter.SaveSpool("EAN8 Data 7\r\n",0);
	BYTE GS_k44[] = {0x1d, 0x6b, 0x44 , 0x07, 0x31 , 0x32 , 0x33 , 0x34 , 0x35 , 0x36 ,0x37};
	woosimprinter.ControlCommand(GS_k44,11);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);

	woosimprinter.SaveSpool("code39 Even\r\n",0);
	BYTE GS_k45[] = {0x1d, 0x6b, 0x45 , 0x0b, 0x41, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x5a};
	woosimprinter.ControlCommand(GS_k45,15);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);

	woosimprinter.SaveSpool("ITF\r\n",0);
	BYTE GS_k46[] = {0x1d, 0x6b, 0x46 , 0x06, 0x31 , 0x32 , 0x33 , 0x34 , 0x35 , 0x36};
	woosimprinter.ControlCommand(GS_k46,10);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);

	woosimprinter.SaveSpool("codabar\r\n",0);
	BYTE GS_k47[] = {0x1d, 0x6b, 0x47 , 0x0b, 0x41, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x44};
	woosimprinter.ControlCommand(GS_k47,15);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);

	woosimprinter.SaveSpool("code93\r\n",0);
	BYTE GS_k48[] = {0x1d, 0x6b, 0x48 , 0x0b, 0x21, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,0x7d};
	woosimprinter.ControlCommand(GS_k48,15);
	woosimprinter.ControlCommand(GS_H,3);
	woosimprinter.ControlCommand(FF,1);

	woosimprinter.PrintSpool();
	*/
}

void CCard123Dlg::OnBnClickedButtonPrint3()
{
	
	//Printer initialization ESC @
	BYTE Print_init[] ={ 0x1b, 0x40 };
	woosimprinter.ControlCommand(Print_init, 2);

	//Barcode print 
	BYTE FF[] = { 0x0c };

	woosimprinter.SaveSpool("PDF417\r\n", 0, 0);

	//Select 2D barcode type GS Z  n (0 = PDF417 / 1 = DATAMATRIX / 2 = QR-CODE / 3 = Micro PDF417 / 4 = Trunc PDF417)
	BYTE GS_Z[] = { 0x1d, 0x5a, 0x00 };
	woosimprinter.ControlCommand(GS_Z, 3);

	BYTE GS_W[] = { 0x1d, 0x77, 0x03 };
	woosimprinter.ControlCommand(GS_W, 3);


	//Print 2D barcode
	BYTE ESC_Z[] = {0x1b, 0x5a,
					0x01 , 0x00, 0X03, 0x0f, 0x00, 
					0x41,0x42,0x43,0x44,0x45,0x31,0x32,0x33,0x34,0x35,0x61,0x62,0x63,0x64,0x65};
	woosimprinter.ControlCommand(ESC_Z, 22);

	woosimprinter.ControlCommand(FF, 1);

	BYTE LF[] ={ 0x0a };
	woosimprinter.ControlCommand(LF, 1);


	woosimprinter.SaveSpool("Micro PDF417\r\n", 0, 0);
	//Select 2D barcode type GS Z  n (0 = PDF417 / 1 = DATAMATRIX / 2 = QR-CODE / 3 = Micro PDF417 / 4 = Trunc PDF417)
	BYTE GS_Z1[] = { 0x1d, 0x5a, 0x03 };
	woosimprinter.ControlCommand(GS_Z1, 3);

	woosimprinter.ControlCommand(GS_W, 3);

	woosimprinter.ControlCommand(ESC_Z, 22);

	woosimprinter.ControlCommand(LF, 1);

	woosimprinter.SaveSpool("Truncated PDF417\r\n", 0, 0);
	//Select 2D barcode type GS Z  n (0 = PDF417 / 1 = DATAMATRIX / 2 = QR-CODE / 3 = Micro PDF417 / 4 = Trunc PDF417)
	BYTE GS_Z2[] = { 0x1d, 0x5a, 0x04 };
	woosimprinter.ControlCommand(GS_Z2, 3);

	woosimprinter.ControlCommand(GS_W, 3);

	woosimprinter.ControlCommand(ESC_Z, 22);

	woosimprinter.ControlCommand(LF, 1);

	woosimprinter.SaveSpool("DATAMAREIX\r\n", 0, 0);
	//Select 2D barcode type GS Z  n (0 = PDF417 / 1 = DATAMATRIX / 2 = QR-CODE / 3 = Micro PDF417 / 4 = Trunc PDF417)
	BYTE GS_Z3[] = { 0x1d, 0x5a, 0x01 };
	woosimprinter.ControlCommand(GS_Z3, 3);

	//Print 2D barcode
	BYTE ESC_Z1[] = {0x1b, 0x5a,
					 0x00 , 0x00, 0X03, 0x0f, 0x00, 
					 0x41,0x42,0x43,0x44,0x45,0x31,0x32,0x33,0x34,0x35,0x61,0x62,0x63,0x64,0x65};
	woosimprinter.ControlCommand(ESC_Z1, 22);

	woosimprinter.ControlCommand(LF, 1);

	woosimprinter.SaveSpool("QR-CODE\r\n", 0, 0);
	//Select 2D barcode type GS Z  n (0 = PDF417 / 1 = DATAMATRIX / 2 = QR-CODE / 3 = Micro PDF417 / 4 = Trunc PDF417)
	BYTE GS_Z4[] = { 0x1d, 0x5a, 0x02 };
	woosimprinter.ControlCommand(GS_Z4, 3);

	//Print 2D barcode
	BYTE ESC_Z2[] = {0x1b, 0x5a,
					 0x00 , 0x4d, 0X03, 0x0f, 0x00, 
					 0x41,0x42,0x43,0x44,0x45,0x31,0x32,0x33,0x34,0x35,0x61,0x62,0x63,0x64,0x65};
	woosimprinter.ControlCommand(ESC_Z2, 22);

	woosimprinter.ControlCommand(LF, 1);
	woosimprinter.PrintSpool(1);
}

void CCard123Dlg::OnBnClickedButtonClose()
{
	// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
	m_strStatus = _T("Close Printer");
	UpdateData(FALSE);
	woosimprinter.ClosePrinter();
}

LRESULT CCard123Dlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	// TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다.
	if(message == ::RegisterWindowMessage(MSG_RECEIVE_CHECK))
	{
		switch (wParam)
		{

		case STATUS_ANSWER:
			
			m_strMsg = _T("STATUS_ANSWER");
			m_strReceivedata.Format(_T("H%02x"), (BYTE)lParam);
			break;
		case NACK:
			
			m_strMsg = _T("NACK");
			break;
		case EOT:
			
			m_strMsg = _T("EOT");
			break;
		case ETX:
			
			m_strMsg = _T("ETX");
			break;
		case MSR_FAIL:
			
			m_strMsg = _T("MSR_FAIL");
			break;
		case CAN:
			
			m_strMsg = _T("CAN");
			break;

		case DATA:
			
			CString data,temp;
			data = _T("");
			temp = _T("");
			strDataHex =  _T("");
			strDataAscii =  _T("");

			switch (m_cboCtrlProtocol.GetCurSel())
			{
			case 0:
				data      = (LPCSTR)(unsigned char*)lParam;
				m_strCardNo.Format(_T("%s %s %s %s"), data.Mid(4,4),data.Mid(8,4),data.Mid(12,4),data.Mid(16,4)); 
				m_strValidDate.Format(_T("%s Month / %s Year"),data.Mid(23,2),data.Mid(21,2)); 
				m_strMsg = _T("DATA");
				break;
			case 1 :
				data      = (LPCSTR)(unsigned char*)lParam;
				m_strCardNo.Format(_T("%s %s %s %s"), data.Mid(1,4),data.Mid(5,4),data.Mid(9,4),data.Mid(13,4)); 
				m_strValidDate.Format(_T("%s Month / %s Year"),data.Mid(20,2),data.Mid(18,2)); 
				m_strMsg = _T("DATA");
				break;
			}

			//Hex 표현으로 변환 
			strDataHex.Format(_T("Receive %dbyte\r\n"),data.GetLength() ); 
			for(int i=0; i < data.GetLength(); i++)
			{
				if(i%8==0)
				{	
					temp.Format(_T("%s\r\n"),strDataHex); 
					strDataHex = temp ;
				}
				temp.Format(_T("%sH%02x "),strDataHex,data[i]); 
				strDataHex = temp;
			}

			m_strReceivedata = strDataHex;

			//Ascii표현으로 변환 
			strDataAscii.Format(_T("Receive %dbyte"),data.GetLength() ); 
			int i;
			for(i=0; i < data.GetLength(); i++)
			{

				if(i%24==0)
				{	
					temp.Format(_T("%s\r\n"),strDataAscii); 
					strDataAscii = temp ;
				}
				temp.Format(_T("%s%c"),strDataAscii,data[i]); 
				strDataAscii = temp;

			}

			m_btnCtrlAscii.EnableWindow(TRUE);
			m_btnCtrlAscii.ShowWindow(SW_SHOW);
			m_btnCtrlHex.EnableWindow(FALSE);
			m_btnCtrlHex.ShowWindow(SW_HIDE);

			break;
		}
		UpdateData(FALSE);
	}
	return CDialog::DefWindowProc(message, wParam, lParam);
}
