Imports System.IO
Imports System.Runtime.InteropServices
Imports System.Text

Public Class Form1
    'Device communication API
    <DllImport("WoosimPrinter.dll")>
    Shared Function ConnectSerialPrinter(ByVal portName As String, ByVal baudRate As Integer, ByVal timeoutMsec As Integer, ByVal bProtocol As Boolean) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")>
    Shared Function ConnectUSBPrinter(ByVal timeoutMsec As Integer, ByVal bProtocol As Boolean) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")>
    Shared Function ConnectWirelessPrinter(ByVal IPAddress As String, ByVal port As Integer, ByVal timeoutMsec As Integer, ByVal bProtocol As Boolean) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")>
    Shared Function ClosePrinterConnection() As Boolean
    End Function
    <DllImport("WoosimPrinter.dll")>
    Shared Function PrintSpool(ByVal bDelete As Boolean) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")>
    Shared Sub EnterMSRMode(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub CancelMSRMode()
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub EnterSCRMode()
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub CancelSCRMode()
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub GetPrinterModelName()
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub GetFirmwareVersion()
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub GetPrinterStatus(ByVal timeoutMsec As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub GetPrinterStatusEx(ByVal timeoutMsec As Integer)
    End Sub

    'Printing data buffer handling
    <DllImport("WoosimPrinter.dll")>
    Shared Sub ClearSpool()
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Function GetSpoolSize() As Integer
    End Function
    <DllImport("WoosimPrinter.dll")>
    Shared Function GetSpoolBuffer() As IntPtr
    End Function

    'Append command & data To the printing data buffer
    <DllImport("WoosimPrinter.dll")>
    Shared Function ControlCommand(ByVal data As Byte(), ByVal length As Integer) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")>
    Shared Sub TextSaveSpool(ByVal text As String)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub InitPrinterStatus()
    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 Sub SetCharCodeTable(ByVal n As Integer, ByVal mcu As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub SetFontSize(ByVal n As Integer)
    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 bold As Boolean, ByVal width As Integer, ByVal height As Integer, ByVal reverse As Boolean)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub InitLineSpace()
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub SetLineSpace(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub SetAbsPosition(ByVal distance As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub SetCharSpace(ByVal n As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub SetUpsideDown(ByVal bSet As Boolean)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub SetFontForTTF(ByVal ttfFile As String)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Function PrintSpoolForTTF(ByVal data As String, ByVal fontWidth As Byte, ByVal fontHeight As Byte) As Integer
    End Function
    <DllImport("WoosimPrinter.dll")>
    Shared Sub SetPositionFromMark(ByVal distance As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub FeedToMark()
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub CutPaper(ByVal mode As Integer)
    End Sub
    'Page mode
    <DllImport("WoosimPrinter.dll")>
    Shared Sub SetPageMode()
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub InitPageMode(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub Page_DrawLine(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer, ByVal thickness As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub Page_DrawBox(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal thickness As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub Page_DrawEllipse(ByVal x As Integer, ByVal y As Integer, ByVal radiusW As Integer, ByVal radiusH As Integer, ByVal thickness As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub Page_DotFeed(ByVal dots 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_ClearCurrentData()
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub Page_SetArea(ByVal x As Integer, ByVal y 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 x As Integer, ByVal y As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub Page_Print()
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub Page_SetStandardMode()
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub Page_Print_StandardMode()
    End Sub
    'Image
    <DllImport("WoosimPrinter.dll")>
    Shared Sub NormalBmpSaveSpool(ByVal bmpFilePath As String)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub NormalAdjustBmpSaveSpool(ByVal bmpFilePath As String, ByVal contrast As Integer, ByVal brightness As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub CompressedBmpSaveSpool(ByVal bmpFilePath As String)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub CompressedAdjustBmpSaveSpool(ByVal bmpFilePath As String, ByVal contrast As Integer, ByVal brightness As Integer)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub LoadLogoSaveSpool(ByVal n As Integer)
    End Sub
    'Barcode
    <DllImport("WoosimPrinter.dll")>
    Shared Sub OneDimensionBarcodeSaveSpool(ByVal barcodeType As Integer, ByVal width As Integer, ByVal height As Integer, ByVal bHri As Boolean, ByVal barcodeData As String)
    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 bHri As Boolean)
    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 QRCodeSaveSpool(ByVal version As Integer, ByVal level As Char, ByVal moduler 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 bHri As Boolean)
    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 bHri As Boolean)
    End Sub
    <DllImport("WoosimPrinter.dll")>
    Shared Sub MaxicodeSaveSpool(ByVal mode 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("user32.dll")>
    Private Shared Function RegisterWindowMessage(ByVal message As String) As UInteger
    End Function

    Private UWM_RECEIVE_DATA As Integer = RegisterWindowMessage("WOOSIM_PRT_OK")

    Private Const DATA As Integer = &H44            'Response data from printer (ex. card data , model name, etc)
    Private Const STATUS_ANSWER As Integer = &H53   'Response of printer status request

    'Common return value
    Private Const SUCCESS As Integer = 1
    Private Const ALREADY_OPENED As Integer = -1
    Private Const TIMEOUT As Integer = -7
    Private Const NOT_OPEN_THE_PORT As Integer = -11
    'Serial and Bluetooth connection error return value
    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 network connection error return value
    Private Const SOCKET_ERROR As Integer = -2
    Private Const CONNECT_FAIL As Integer = -3
    'USB connection error return value
    Private Const UNABLE_TO_MAKE_CONNECTION As Integer = -2
    Private Const UNABLE_TO_GET_INFOMATION As Integer = -3
    Private Const NOT_WOOSIM_PRINTER As Integer = -4

    'Paper width with dot unit
    Private Const _1INCH As Integer = 192
    Private Const _2INCH As Integer = 384
    Private Const _3INCH As Integer = 576
    Private Const _4INCH As Integer = 832

    Enum Barcode
        UPCA = 65
        UPCE
        EAN13
        EAN8
        CODE39
        ITF
        CODABAR
        CODE93
        CODE128
    End Enum

    Enum MCU
        M16C
        ARM
        RX
    End Enum

    Private connectionStatus As Integer

    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        comboSerialPort.SelectedIndex = 0   'COM1
        comboBaudrate.SelectedIndex = 3     '57600
        textBoxIP.Text = "192.168.10.1"
        textBoxIpPort.Text = "9100"
        comboMsr.SelectedIndex = 3          'Triple Track

        connectionStatus = 0
    End Sub

    Private Sub Form1Closing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
        If connectionStatus = SUCCESS Then
            ClosePrinterConnection()
        End If
    End Sub

    Private Sub RadioSerial_CheckedChanged(sender As Object, e As EventArgs) Handles RadioSerial.CheckedChanged
        If RadioSerial.Checked Then
            labelSerialPort.Show()
            labelBaudrate.Show()
            comboSerialPort.Show()
            comboBaudrate.Show()

            labelIP.Hide()
            labelIpPort.Hide()
            textBoxIP.Hide()
            textBoxIpPort.Hide()
        End If
    End Sub

    Private Sub RadioUsb_CheckedChanged(sender As Object, e As EventArgs) Handles RadioUsb.CheckedChanged
        If RadioUsb.Checked Then
            labelSerialPort.Hide()
            labelBaudrate.Hide()
            comboSerialPort.Hide()
            comboBaudrate.Hide()

            labelIP.Hide()
            labelIpPort.Hide()
            textBoxIP.Hide()
            textBoxIpPort.Hide()
        End If
    End Sub

    Private Sub RadioTcpip_CheckedChanged(sender As Object, e As EventArgs) Handles RadioTcpip.CheckedChanged
        If RadioTcpip.Checked Then
            labelSerialPort.Hide()
            labelBaudrate.Hide()
            comboSerialPort.Hide()
            comboBaudrate.Hide()

            labelIP.Show()
            labelIpPort.Show()
            textBoxIP.Show()
            textBoxIpPort.Show()
        End If
    End Sub

    Private Sub OpenButton_Click(sender As Object, e As EventArgs) Handles openButton.Click
        If connectionStatus = SUCCESS Then
            Return
        End If

        If RadioSerial.Checked Then
            Dim baudrate As Integer
            Integer.TryParse(comboBaudrate.SelectedItem.ToString(), baudrate)
            connectionStatus = ConnectSerialPrinter(comboSerialPort.SelectedItem.ToString(), baudrate, 1000, False)
        ElseIf RadioUsb.Checked Then
            connectionStatus = ConnectUSBPrinter(1000, False)
        ElseIf RadioTcpip.Checked Then
            Dim port As Integer
            Integer.TryParse(textBoxIpPort.Text.ToString(), port)
            connectionStatus = ConnectWirelessPrinter(textBoxIP.Text.ToString(), port, 5000, False)
        End If

        If connectionStatus = SUCCESS Then
            labelComStatus.Text = "Connection success"
        Else
            labelComStatus.Text = String.Format("Connection is failed with return value {0}", connectionStatus)
        End If
    End Sub

    Private Sub CloseButton_Click(sender As Object, e As EventArgs) Handles closeButton.Click
        If connectionStatus = SUCCESS Then
            ClosePrinterConnection()
            connectionStatus = 0
            labelComStatus.Text = "Connection closed"
        End If
    End Sub

    Protected Overrides Sub WndProc(ByRef msg As Message)
        If msg.Msg = UWM_RECEIVE_DATA Then
            Dim type As Integer = msg.WParam.ToInt32() >> 16
            Dim length As Integer = msg.WParam.ToInt32() And &HFFFF
            Dim strData As String = Nothing
            Dim byteArray(length) As Byte

            Marshal.Copy(msg.LParam, byteArray, 0, length)
            If type = STATUS_ANSWER Then
                strData = String.Format("{0:X}", byteArray(0))
            ElseIf type = DATA Then
                strData = String.Format("Receive {0} bytes" + Chr(&HD) + Chr(&HA) + Chr(&HD) + Chr(&HA), length)
                strData += Encoding.Default.GetString(byteArray)
            End If
            textBoxRcvData.Text = strData
        End If
        MyBase.WndProc(msg)
    End Sub

    Private Sub TextButton_Click(sender As Object, e As EventArgs) Handles textButton.Click
        InitPrinterStatus()
        SetTextAlignment(1)
        TextSaveSpool("SALES  SLIP" + Chr(&HA))
        SetTextAlignment(0)
        TextSaveSpool("--------------------------------" + Chr(&HA))
        TextSaveSpool("MERCHANT NAME      Woosim Coffee" + Chr(&HA))
        TextSaveSpool("MASTER                LEE IL BOK" + Chr(&HA))
        TextSaveSpool("ADDRESS" + Chr(&HA))
        TextSaveSpool("     #60, Sandan-ro 388beon-gil," + Chr(&HA))
        TextSaveSpool("    Galsan-myeon, Hongseong-gun," + Chr(&HA))
        TextSaveSpool("       Chungnam-do, 32200, Korea" + Chr(&HA))
        TextSaveSpool("HELP DESK        +82-41-339-3700" + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA) + Chr(&HA))
        TextSaveSpool("          WOOSIM  CARD          " + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA))
        TextSaveSpool("CARD NO.     4428-8819-0118-****" + Chr(&HA))
        TextSaveSpool("EXPIRY                   2022/10" + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA))
        TextSaveSpool("TRANS. YEAR & DATE    2020/04/15" + Chr(&HA))
        TextSaveSpool("TRANS CLASS             [Credit]" + Chr(&HA))
        TextSaveSpool("TERMINAL ID.           123456789" + Chr(&HA))
        TextSaveSpool("APPROVAL NO.           987654321" + Chr(&HA))
        TextSaveSpool("AMOUNT                   500.00$" + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA))
        TextSaveSpool("SIGNATURE: " + Chr(&HA) + Chr(&HA))
        TextSaveSpool("--------------------------------" + Chr(&HA) + Chr(&HA))
        PrintSpool(True)
    End Sub

    Private Sub Barcode1Button_Click(sender As Object, e As EventArgs) Handles barcode1Button.Click
        InitPrinterStatus()
        TextSaveSpool("UPCA" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.UPCA, 2, 60, True, "012100000642")
        PrintData()
        TextSaveSpool("UPCE" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.UPCE, 2, 60, True, "065100004328")
        PrintData()
        TextSaveSpool("EAN13" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.EAN13, 2, 60, True, "123456478901")
        PrintData()
        TextSaveSpool("EAN8" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.EAN8, 2, 60, True, "12345678")
        PrintData()
        TextSaveSpool("CODE39" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.CODE39, 2, 60, True, "12345678901")
        PrintData()
        TextSaveSpool("ITF" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.ITF, 2, 60, True, "123456")
        PrintData()
        TextSaveSpool("CODABAR" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.CODABAR, 2, 60, True, "123456")
        PrintData()
        TextSaveSpool("CODE93" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.CODE93, 2, 60, True, "12345678901")
        PrintData()
        TextSaveSpool("CODE128" + Chr(&HA))
        OneDimensionBarcodeSaveSpool(Barcode.CODE128, 2, 60, True, "12345678901")
        PrintLineFeed(2)
        PrintSpool(True)
    End Sub

    Private Sub Barcode2Button_Click(sender As Object, e As EventArgs) Handles barcode2Button.Click
        InitPrinterStatus()
        TextSaveSpool("PDF417" + Chr(&HA))
        PDF417SaveSpool(2, 2, 2, 4, "0123456789", False)
        PrintData()
        TextSaveSpool("DataMatrix" + Chr(&HA))
        DataMatrixSaveSpool(36, 36, 2, "0123456789")
        PrintData()
        TextSaveSpool("QR Code" + Chr(&HA))
        QRCodeSaveSpool(0, "H", 3, "0123456789")
        PrintData()
        TextSaveSpool("Micro PDF417" + Chr(&HA))
        MicroPDF417SaveSpool(2, 1, 0, 2, "01234567", False)
        PrintData()
        TextSaveSpool("Truncated PDF417" + Chr(&HA))
        TruncatedPDF417SaveSpool(2, 2, 2, 2, "0123456789", False)
        PrintData()
        TextSaveSpool("Maxicode" + Chr(&HA))
        MaxicodeSaveSpool(4, "0123456789")
        PrintData()
        PrintSpool(True)
    End Sub

    Private Sub TtfButton_Click(sender As Object, e As EventArgs) Handles ttfButton.Click
        SetFontForTTF("WSTTFL.ttf")
        PrintSpoolForTTF("Woosim System Inc.", 30, 30)
        PrintLineFeed(2)
        PrintSpool(True)
    End Sub

    Private Sub PageSampleButton_Click(sender As Object, e As EventArgs) Handles pageSampleButton.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))
        PrintDotFeed(15)
        SetFontSize(1)
        Page_SetPosition(277, 105)
        TextSaveSpool("2020-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)
        PrintDotFeed(5)
        TextSaveSpool(" #      Item      Num    Charge" + Chr(&HA))
        TextSaveSpool(" 1      Latte      1     $ 3.35" + Chr(&HA))
        TextSaveSpool(" 2  House Coffee   2     $ 3.98" + Chr(&HA))
        TextSaveSpool(" 3       Tea       1     $ 1.95")
        PrintDotFeed(10)
        Page_DrawBox(0, 270, _2INCH, 0, 2)

        Page_DrawBox(0, 310, 115, 0, 2)
        Page_DrawBox(260, 310, 124, 0, 2)
        Page_SetPosition(123, 300)
        TextSaveSpool("Credit Card" + Chr(&HA))
        TextSaveSpool("Number:         ")
        SetFontSize(1)
        TextSaveSpool("6688-9988-6644-3311" + Chr(&HA))
        SetFontSize(0)
        TextSaveSpool("Payment:                $ 9.50" + Chr(&HA))

        Page_DrawBox(0, 400, 120, 0, 2)
        Page_DrawBox(250, 400, 134, 0, 2)
        Page_SetPosition(145, 390)
        TextSaveSpool("Payment" + Chr(&HA))
        TextSaveSpool("Price:                  $ 9.28" + Chr(&HA))
        TextSaveSpool("Tax:                    $ 0.22" + Chr(&HA))
        Page_DrawBox(0, 490, _2INCH, 0, 2)
        PrintDotFeed(15)
        TextSaveSpool("Total:                  $ 9.50" + Chr(&HA))
        TextSaveSpool("Credit Card:            $ 9.50" + Chr(&HA))

        Page_SetPosition(40, 580)
        OneDimensionBarcodeSaveSpool(Barcode.CODE128, 2, 50, True, "20150127123456789")
        PrintLineFeed(2)

        Page_Print_StandardMode()
        PrintSpool(True)
    End Sub

    Private Sub ImageButton_Click(sender As Object, e As EventArgs) Handles imageButton.Click
        If (File.Exists("./woosim.bmp") = False) Then
            MessageBox.Show("woosim.bmp file is not found!")
            Return
        End If

        InitPrinterStatus()

        'Normal BMP file print
        TextSaveSpool("Print Bmp file " + Chr(&HA))
        NormalBmpSaveSpool("./woosim.bmp")
        PrintLineFeed(2)

        'BMP file print using Compressed algorithm
        TextSaveSpool("Print Bmp file with compressing" + Chr(&HA))
        InitPageMode(0, 0, _2INCH, 200)
        CompressedBmpSaveSpool("./woosim.bmp")
        Page_Print_StandardMode()

        'Print image downloaded in printer
        TextSaveSpool("Print pre-downloaded image file #0" + Chr(&HA))
        LoadLogoSaveSpool(0)
        PrintLineFeed(2)
        PrintSpool(True)
    End Sub

    Private Sub BoxLineButton_Click(sender As Object, e As EventArgs) Handles boxLineButton.Click
        'Initialization & make page
        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)
        PrintData()
        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 - 20, 3)
        Page_Print_StandardMode()
        PrintLineFeed(2)

        PrintSpool(True)
    End Sub

    Private Sub StatusButton_Click(sender As Object, e As EventArgs) Handles statusButton.Click
        GetPrinterStatus(1000)
    End Sub

    Private Sub DevInfoButton_Click(sender As Object, e As EventArgs) Handles devInfoButton.Click
        GetPrinterModelName()
        GetFirmwareVersion()
    End Sub

    Private Sub SetMsrButton_Click(sender As Object, e As EventArgs) Handles setMsrButton.Click
        EnterMSRMode(comboMsr.SelectedIndex)
    End Sub

    Private Sub CancelMsrButton_Click(sender As Object, e As EventArgs) Handles cancelMsrButton.Click
        CancelMSRMode()
    End Sub
End Class
