Imports System.Runtime.InteropServices
Imports Microsoft.WindowsCE.Forms

Public Class Form1
    '1. Printable Data Handling APIs
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub ClearSpool()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub CompressedBmpSaveSpool(ByVal bmpFilePath As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub ControlCommand(ByVal Cmds As Byte(), ByVal iLength As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub DataMatrixSaveSpool(ByVal width As Integer, ByVal height As Integer, ByVal moduler As Integer, ByVal barcodeData As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub GS1DatabarSaveSpool(ByVal type As Integer, ByVal n As Integer, ByVal barcodeData As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub LoadLogoSaveSpool(ByVal n)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub MaxicodeSaveSpool(ByVal mode As Integer, ByVal barcodeData As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub MicroPDF417SaveSpool(ByVal width As Integer, ByVal column As Integer, ByVal row As Integer, ByVal ratio As Integer, ByVal barcodeData As String, ByVal HRI As Boolean)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub NormalBmpSaveSpool(ByVal bmpFilePath As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub OneDimensionBarcodeSaveSpool(ByVal ucBarcodeType As Byte, _
               ByVal ucBarWidth As Integer, ByVal ucBarHeight As Integer, ByVal HRI_On As Boolean, ByVal barcodeData As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_DotFeed(ByVal dots As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_DrawBox(ByVal iXPos As Integer, ByVal iYPos As Integer, ByVal width As Integer, ByVal height As Integer, ByVal thickness As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_DrawEllipse(ByVal iXPos As Integer, ByVal iYPos As Integer, ByVal A_length As Integer, ByVal B_length As Integer, ByVal thickness As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_DrawLine(ByVal iXPos As Integer, ByVal iYPos As Integer, ByVal iX2Pos As Integer, ByVal iY2Pos As Integer, ByVal thickness As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_LineFeed(ByVal lines As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_Newline()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_Print()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_Print_StandardMode()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub PDF417SaveSpool(ByVal width As Integer, ByVal column As Integer, ByVal level As Integer, ByVal ratio As Integer, ByVal barcodeData As String, ByVal HRI As Boolean)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub PrintData()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub PrintDotFeed(ByVal dots As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub PrintLineFeed(ByVal lines As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Function PrintSpool(ByVal bDelete_Spool As Boolean) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")> _
    Shared Function PrintSpoolForTTF(ByVal sData As String, ByVal iXFontSize As Byte, ByVal iYFontSize As Byte) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub QRCodeSaveSpool(ByVal version As Integer, ByVal level As Char, ByVal moduler As Integer, ByVal barcodeData As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub TextSaveSpool(ByVal textData As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub TruncatedPDF417SaveSpool(ByVal width As Integer, ByVal column As Integer, ByVal level As Integer, ByVal ratio As Integer, ByVal barcodeData As String, ByVal HRI As Boolean)
    End Sub

    '2. Printer Mode & Setting APIs
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub GetPrinterModelName()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub GetFirmwareVersion()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub GetPrinterStatus(ByVal iTimeoutMsec As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub InitLineSpace()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub InitPageMode(ByVal iXPos As Integer, ByVal iYPos As Integer, ByVal width As Integer, ByVal height As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub InitPrinterStatus()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_ClearCurrentData()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_SetArea(ByVal iXPos As Integer, ByVal iYPos As Integer, ByVal width As Integer, ByVal height As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_SetDirection(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_SetPosition(ByVal iXPos As Integer, ByVal iYPos As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub Page_SetStandardMode()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetAbsPosition(ByVal distance As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetCharCodeTable(ByVal n As Integer, ByVal MCU As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetCharSpace(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetFontForTTF(ByVal ttfFile As String)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetFontSize(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetLineSpace(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetPageMode()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetTextAlignment(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetTextStyle(ByVal underline As Integer, ByVal emphasize As Boolean, ByVal width As Integer, ByVal height As Integer, ByVal reverse As Boolean)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub SetUpsideDown(ByVal setting As Boolean)
    End Sub

    '3. Misc Device Handling APIs
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub CancelMSRMode()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Function ClosePrinterConnection() As Boolean
    End Function
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub CancelSCRMode()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Function ConnectSerialPrinter(ByVal sSetPort As String, ByVal iBaudRate As Integer, ByVal iTimeoutMsec As Integer, ByVal bProtocol As Boolean) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")> _
    Shared Function ConnectWirelessPrinter(ByVal sIP_ADDR As String, ByVal iPortNum As Integer, ByVal iTimeoutMsec As Integer, ByVal bProtcol As Boolean) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub CutPaper(ByVal mode As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub EnterMSRMode(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub EnterSCRMode()
    End Sub
    <DllImport("WoosimPrinter.dll")> _
    Shared Sub FeedToMark()
    End Sub
    <DllImport("WoosimPrinter.DLL")> _
    Shared Sub SetPositionFromMark(ByVal distance As Integer)
    End Sub


    '***************************************************************************
    '           CONST DEFINE
    '***************************************************************************

    ' Return Message 
    Private Const SUCCESS As Integer = 1
    Private Const ALREADY_OPENED As Integer = -1
    Private Const NO_RESPONSE_FROM_PRINTER As Integer = -5
    Private Const TIMEOUT As Integer = -7
    Private Const NOT_OPEN_THE_PORT As Integer = -11

    'Serial & Bluetooth
    Private Const UNABLE_TO_OPEN_THE_PORT As Integer = -2
    Private Const UNABLE_TO_CONFIGURE_THE_SERIAL_PORT As Integer = -3
    Private Const UNABLE_TO_SET_THE_TIMEPIT_PARAMETERS As Integer = -4

    'Wireless
    Private Const SOCKET_ERROR As Integer = -2
    Private Const CONNECT_FAIL As Integer = -3

    'barcode type
    Public Const UPCA As Int32 = 65
    Public Const UPCE As Int32 = 66
    Public Const EAN13 As Int32 = 67
    Public Const EAN8 As Int32 = 68
    Public Const CODE39 As Int32 = 69
    Public Const ITF As Int32 = 70
    Public Const CODABAR As Int32 = 71
    Public Const CODE93 As Int32 = 72
    Public Const CODE128 As Int32 = 73

    'print width
    Private Const _1INCH As Integer = 192
    Private Const _2INCH As Integer = 384
    Private Const _3INCH As Integer = 576
    Private Const _4INCH As Integer = 832

    'MCU
    Private Const MCU_RX As Integer = 2
    Private Const MCU_ARM As Integer = 1
    Private Const MCU_M16C As Integer = 0

    Private Shared m_MsgWnd As MsgWnd = Nothing

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox1.SelectedIndex = 0
        ComboBox2.SelectedIndex = 0
        ComboBox3.SelectedIndex = 3
        ComboBox4.SelectedIndex = 1
        TextBox1.Hide()
        TextBox2.Hide()
        Label3.Text = ""
        TextBox1.Text = "192.168.0.101"
        TextBox2.Text = "1470"

        m_MsgWnd = New MsgWnd()

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.SelectedIndex = 0 Then
            TextBox1.Hide()
            TextBox2.Hide()
            ComboBox2.Show()
            ComboBox3.Show()
            Label1.Text = "Port"
            Label2.Text = "Baud"
        ElseIf ComboBox1.SelectedIndex = 1 Then
            TextBox1.Show()
            TextBox2.Show()
            ComboBox2.Hide()
            ComboBox3.Hide()
            Label1.Text = "IP"
            Label2.Text = "Port"
        End If
    End Sub

    Private Sub Form1_Deactivate(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate
        'ClosePrinterConnection()
        Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim intReturnValue As Integer = 0
        Dim SetPort As String = ""
        Dim BaudRate As Integer
        Dim DefaultTimeout As Integer = 1000

        Dim ipAddr As String = ""
        Dim ipPort As Integer = 0

        If ComboBox1.SelectedIndex = 0 Then 'serial

            Select Case (ComboBox2.SelectedIndex)
                Case 0 : SetPort = "COM1:"
                Case 1 : SetPort = "COM2:"
                Case 2 : SetPort = "COM3:"
                Case 3 : SetPort = "COM7:"
                Case 4 : SetPort = "COM8:"
                Case 5 : SetPort = "COM9:"
            End Select

            Select Case (ComboBox3.SelectedIndex)
                Case 0 : BaudRate = 9600
                Case 1 : BaudRate = 19200
                Case 2 : BaudRate = 38400
                Case 3 : BaudRate = 57600
                Case 4 : BaudRate = 115200
            End Select

            intReturnValue = ConnectSerialPrinter(SetPort, BaudRate, DefaultTimeout, False)

            Select Case (intReturnValue)
                Case SUCCESS : Label3.Text = "SUCCESS"
                Case ALREADY_OPENED : Label3.Text = "ALREADY_OPENED"
                Case NO_RESPONSE_FROM_PRINTER : Label3.Text = "NO_RESPONSE_FROM_PRINTER" 'protocol
                Case UNABLE_TO_OPEN_THE_PORT : Label3.Text = "UNABLE_TO_OPEN_THE_PORT"
                Case UNABLE_TO_CONFIGURE_THE_SERIAL_PORT : Label3.Text = "UNABLE_TO_CONFIGURE_THE_SERIAL_PORT"
                Case UNABLE_TO_SET_THE_TIMEPIT_PARAMETERS : Label3.Text = "UNABLE_TO_SET_THE_TIMEPIT_PARAMETERS"
                Case TIMEOUT : Label3.Text = "TIMEOUT"
            End Select

        ElseIf ComboBox1.SelectedIndex = 1 Then
            ipAddr = TextBox1.Text.ToString()
            ipPort = Convert.ToDecimal(TextBox2.Text.ToString())
            intReturnValue = ConnectWirelessPrinter(ipAddr, ipPort, DefaultTimeout, False)

            Select Case (intReturnValue)
                Case SUCCESS : Label3.Text = "SUCCESS"
                Case ALREADY_OPENED : Label3.Text = "ALREADY_OPENED"
                Case NO_RESPONSE_FROM_PRINTER : Label3.Text = "NO_RESPONSE_FROM_PRINTER" 'protocol
                Case SOCKET_ERROR : Label3.Text = "SOCKET_ERROR"
                Case CONNECT_FAIL : Label3.Text = "CONNECT_FAIL"
                Case TIMEOUT : Label3.Text = "TIMEOUT"
            End Select
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Label3.Text = "CONNECTION CLOSED"
        ClosePrinterConnection()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        InitPageMode(0, 0, _2INCH, _3INCH)

        'Draw Black & long box
        Page_DrawBox(_2INCH - 80, 30, 30, 150, 20)
        Page_DrawBox(_2INCH - 80, 200, 30, _3INCH - 200 - 30, 1)

        'Contained text "TEXT"
        Page_DrawBox(214, 224, 50, 258, 1)

        'Boxes in Box
        Page_DrawBox(60, 234, 104, 44, 1)
        Page_DrawBox(60, 312, 28, 150, 1)
        Page_DrawBox(98, 312, 28, 150, 1)
        Page_DrawBox(136, 312, 28, 150, 1)
        Page_DrawBox(50, 224, 124, 258, 3)

        'Draw vertical lines
        Page_DrawBox(205, 30, 0, 140, 1)
        Page_DrawBox(235, 30, 0, 140, 1)
        Page_DrawBox(265, 30, 0, 140, 1)

        'Draw horizontal lines
        Page_DrawBox(185, 55, 100, 0, 1)
        Page_DrawBox(185, 95, 100, 0, 1)
        Page_DrawBox(185, 135, 100, 0, 1)

        'Draw outline-Box
        Page_DrawBox(30, 0, _2INCH - 60, _3INCH, 1)

        Page_SetDirection(3) ' Clockwise rotation
        Page_SetPosition(214, 30) 'Y_pos, X_pos
        SetTextStyle(0, False, 1, 1, False)
        TextSaveSpool("Text")
        Page_SetPosition(270, 70)
        QRCodeSaveSpool(0, "H", 2, "www.woosim.com/english")

        SetTextStyle(0, True, 1, 0, False)
        Page_SetPosition(126, 256) 'Y_pos, X_pos
        TextSaveSpool("TEXT")

        Page_Print_StandardMode()

        Page_SetDirection(0)
        InitPageMode(0, 0, _2INCH, _2INCH)

        Page_DrawBox(0, 30, _2INCH, 0, 5)
        Page_DrawBox(30, 0, 0, _2INCH, 5)
        Page_DrawLine(30, 30, 170, 160, 3)
        Page_DrawLine(170, 160, 130, 190, 3)
        Page_DrawLine(130, 190, 210, 250, 3)
        Page_DrawLine(210, 250, 190, 270, 3)
        Page_DrawLine(190, 270, 270, 340, 3)
        Page_DrawLine(270, 340, 210, 370, 3)
        Page_Newline()
        Page_Print()

        Page_ClearCurrentData()
        Page_DrawBox(0, _1INCH, _2INCH, 0, 5)
        Page_DrawBox(_1INCH, 0, 0, _2INCH, 5)
        Page_DrawBox(_1INCH / 2, _1INCH, _1INCH, 0, 0)
        Page_DrawEllipse(_1INCH, _1INCH, _1INCH / 2, _1INCH, 3)
        Page_Print_StandardMode()

        PrintSpool(True)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        InitPrinterStatus()

        ' TODO: Add your control notification handler code here
        TextSaveSpool("   매 출 전 표" + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA))

        'Company
        TextSaveSpool("상점명             Woosim Coffee" + Chr(&HA))
        TextSaveSpool("사업자등록번호      119-81-36382" + Chr(&HA))
        'Reg Number
        TextSaveSpool("대표자                  이 일 복" + Chr(&HA))
        'Address
        TextSaveSpool("서울특별시 금천구 가산동 448번지" + Chr(&HA) + "대륭테크노타운 3차, 501호" + Chr(&HA))
        'Tel
        TextSaveSpool("문의                02-2107-3709" + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA) + Chr(&HA))
        TextSaveSpool("    우심 비자 카드" + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA))
        'Card number
        TextSaveSpool("카드번호     9445 4103 9533 2096" + Chr(&HA))
        TextSaveSpool("유효 기간                2012/10" + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA))
        TextSaveSpool("거 래 일 자           2011/04/11" + Chr(&HA))
        TextSaveSpool("거 래 종 류       [신용거래승인]" + Chr(&HA))
        TextSaveSpool("단 말 번 호            123456789" + Chr(&HA))
        TextSaveSpool("승 인 번 호            987654321" + Chr(&HA))
        TextSaveSpool("결 제 금 액             50,000원" + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA))
        TextSaveSpool("서명: " + Chr(&HA) + Chr(&HA) + Chr(&HA) + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA) + Chr(&HA))

        PrintSpool(True)
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        InitPrinterStatus()
        TextSaveSpool("UPCA" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(UPCA, 2, 100, True, "012100000642")
        PrintData()

        TextSaveSpool("UPCE" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(UPCE, 2, 100, True, "065100004328")
        PrintData()

        TextSaveSpool("EAN13" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(EAN13, 2, 100, True, "123456478901")
        PrintData()

        TextSaveSpool("EAN8" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(EAN8, 2, 100, True, "12345678")
        PrintData()

        TextSaveSpool("CODE39" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(CODE39, 2, 100, True, "12345678901")
        PrintData()

        TextSaveSpool("ITF" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(ITF, 2, 100, True, "123456")
        PrintData()

        TextSaveSpool("CODABAR" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(CODABAR, 2, 100, True, "123456")
        PrintData()

        TextSaveSpool("CODE93" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(CODE93, 2, 100, True, "12345678901")
        PrintData()

        TextSaveSpool("CODE128" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(CODE128, 2, 100, True, "12345678901")
        PrintData()

        PrintSpool(True)
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        InitPrinterStatus()

        TextSaveSpool("PDF417")
        PrintData()
        PDF417SaveSpool(192, 2, 2, 2, "0123456789", False)
        PrintData()

        TextSaveSpool("DataMatrix")
        PrintData()
        DataMatrixSaveSpool(36, 36, 2, "0123456789")
        PrintLineFeed(1)

        TextSaveSpool("QR Code")
        PrintData()
        QRCodeSaveSpool(0, "H", 3, "0123456789")
        PrintDotFeed(30)

        TextSaveSpool("Micro PDF417")
        PrintData()
        MicroPDF417SaveSpool(200, 1, 0, 2, "01234567", False)
        PrintDotFeed(30)

        TextSaveSpool("Truncated PDF417")
        PrintData()
        TruncatedPDF417SaveSpool(192, 2, 2, 2, "0123456789", False)
        PrintData()

        TextSaveSpool("Maxicode")
        PrintData()
        MaxicodeSaveSpool(4, "0123456789")
        PrintData()

        PrintSpool(True)
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

        InitPrinterStatus()

        'Normal BMP file print
        TextSaveSpool("Print Bmp file ./woosim.bmp")
        PrintData()
        NormalBmpSaveSpool("./woosim.bmp")
        PrintLineFeed(2)

        'BMP file print using Compressed algorithm
        TextSaveSpool("Print Bmp file using compressed algorithm")
        PrintData()
        CompressedBmpSaveSpool("./woosim.bmp")
        PrintLineFeed(2)

        'Print pre-download image.
        TextSaveSpool("Print pre-downloaded image file #0")
        PrintData()
        LoadLogoSaveSpool(0)
        PrintData()

        PrintSpool(True)

    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        GetPrinterModelName()
        GetFirmwareVersion()
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        GetPrinterStatus(1000)
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        InitPageMode(0, 0, _2INCH, 700)
        SetTextStyle(0, True, 1, 1, False)
        TextSaveSpool("Woosim Cafe" + Chr(&HA))

        SetTextStyle(0, False, 0, 0, False)
        TextSaveSpool("Coffee, tea and bread" + Chr(&HA))
        Page_DotFeed(15)
        SetFontSize(1)
        Page_SetPosition(277, 105)
        TextSaveSpool("2015-01-27" + Chr(&HA))
        SetFontSize(0)

        Page_SetPosition(290, 5)
        QRCodeSaveSpool(0, "H", 2, "www.woosim.com/english")

        Page_DrawBox(0, 130, _2INCH, 0, 2)
        Page_DotFeed(5)
        TextSaveSpool(" #      Item      Num    Charge" + Chr(&HA))
        TextSaveSpool(" 1      Latte      1     $ 3.35")
        Page_Newline()
        TextSaveSpool(" 2  House Coffee   2     $ 3.98")
        Page_Newline()
        TextSaveSpool(" 3       Tea	       1     $ 1.95")
        Page_DotFeed(10)
        Page_DrawBox(0, 270, _2INCH, 0, 2)
        Page_Newline()

        Page_DrawBox(0, 310, 115, 0, 2)
        Page_DrawBox(260, 310, 124, 0, 2)
        Page_DotFeed(15)
        Page_SetPosition(123, 300)
        TextSaveSpool("Credit Card" + Chr(&HA))

        TextSaveSpool("Number:         ")
        SetFontSize(1)
        TextSaveSpool("6688-9988-6644-3311")
        Page_Newline()
        SetFontSize(0)
        TextSaveSpool("Payment:                $ 9.50 ")
        Page_Newline()

        Page_DrawBox(0, 400, 120, 0, 2)
        Page_DrawBox(250, 400, 134, 0, 2)
        Page_DotFeed(15)
        Page_SetPosition(145, 390)
        TextSaveSpool("Payment" + Chr(&HA))

        TextSaveSpool("Price:                  $ 9.28")
        Page_Newline()
        TextSaveSpool("Tax:                    $ 0.22")
        Page_Newline()

        Page_DrawBox(0, 490, _2INCH, 0, 2)
        Page_DotFeed(15)
        TextSaveSpool("Total:                  $ 9.50")
        Page_Newline()
        TextSaveSpool("Credit Card:            $ 9.50")
        Page_Newline()

        Page_SetPosition(40, 580)
        OneDimensionBarcodeSaveSpool(CODE128, 2, 50, True, "20150127123456789")
        Page_LineFeed(2)

        Page_Print_StandardMode()
        PrintSpool(True)
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        Dim modeSelect As Integer = 0
        'MSR sample is based 12Track magnetic card.
        Select Case (ComboBox2.SelectedIndex)
            Case 0 : modeSelect = 0 'Read 1T. If 23T card, read 2T.
            Case 1 : modeSelect = 1 'Read 2T. If 23T card, read 3T.
            Case 2 : modeSelect = 4 'Read 3T. It only use for 123T.
            Case 3 : modeSelect = 2 'Read 12T. If 23T card, read 23T.
            Case 4 : modeSelect = 3 'Read 123T. It only use for 123T.
        End Select

        EnterMSRMode(modeSelect)
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        CancelMSRMode()
    End Sub
End Class



Public Class MsgWnd
    Inherits MessageWindow
    <DllImport("coredll.dll")> _
    Private Shared Function RegisterWindowMessage( _
         ByVal lpString As String) As UInteger
    End Function

    Private WM_RECEIVE_MSG As Integer = RegisterWindowMessage("WOOSIM_PRT_OK")
    Private DATA As Integer = &H44 '			                                     
    Private STATUS_ANSWER As Integer = &H53 '                                        


    Public Sub New()
    End Sub



    Protected Overrides Sub WndProc(ByRef msg As Message)

        If msg.Msg = WM_RECEIVE_MSG Then
            Dim chk As Short
            Dim length As Long

            chk = msg.WParam.ToInt32() >> 16 ' x86
            length = msg.WParam.ToInt32() And &HFFFF 'x86

            If chk = DATA Then
                MessageBox.Show("DATA")

                Dim sScanData As String
                Dim Revstr As String = Nothing
                If (True) Then
                    sScanData = Marshal.PtrToStringUni(msg.LParam)
                    Dim CardData() As Byte = System.Text.Encoding.Unicode.GetBytes(sScanData)

                    Dim i As Integer
                    For i = 0 To length - 1
                        Revstr += Chr(CardData(i))
                    Next

                End If
                MessageBox.Show(Revstr)

            Else
                If chk = STATUS_ANSWER Then
                    MessageBox.Show("STATUS_ANSWER")

                    Dim lParamByte(length) As Byte

                    Marshal.Copy(msg.LParam, lParamByte, 0, length)

                    MessageBox.Show(Hex(lParamByte(0)))
                End If
            End If
        End If
        MyBase.WndProc(msg)
    End Sub
End Class


