﻿B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=12.8
@EndOfDesignText@
Sub Class_Globals
	Private Astream As AsyncStreams
	Private Connected As Boolean = False
	Dim CallBack As Object
	Dim ConnectedError As String
	Dim EventName As String
	Dim printerObj As JavaObject
	Dim printerExeption As JavaObject
	Dim errorValue As Int = 0
	Dim errorString As String = ""
	
End Sub

Public Sub Initialize(vCallback As Object, vEventName As String)
	printerObj.InitializeContext
	printerExeption.InitializeContext
	printerObj.InitializeNewInstance("vpos.apipackage.PosApiHelper", Null)
	'printerExeption.InitializeNewInstance
	

	Dim retvalue As Int
	Connected = False
	
	EventName = vEventName
	CallBack = vCallback
	Connected = False
	ConnectedError = ""
	
	
End Sub


'Gray: the grad Density. 1-high Density, 2-medium,3-low
'Fontheight: font height. 16 Or 24
'Fontwidth: font width. 16 Or 24
'Fontzoom: bolt font, 0x00 Or 0x33
Public Sub PrintInit(gray As Int , fontHeight As Int, fontWidth As Int, fontZoom As Int)
	Dim retvalue As Int = printerObj.RunMethod("PrintInit",Null)
	If retvalue = 0 Then Connected = True
	PrintSetGray(gray)
	PrintSetFont(fontHeight, fontWidth, fontZoom)
	errors(retvalue)
	If retvalue = 0 Then
		Return True
	Else
		Return False
	End If
End Sub



Public Sub PrintString(data As String) As Boolean
	Dim retValue As Int = printerObj.RunMethod("PrintStr", Array(data))
	errors(retValue)
	If retValue = 0 Then
		Return True
	Else
		Return False
	End If
End Sub

Public Sub PrintStart As Boolean
	Dim retValue As Int = printerObj.RunMethod("PrintStart", Null)
	errors(retValue)
	If retValue = 0 Then
		Return True
	Else
		Return False
	End If
End Sub

Public Sub PrintCheckStatus(data As String) As Boolean
	Dim retValue As Int = printerObj.RunMethod("PrintCheckStatus", Null)
	errors(retValue)
	If retValue = 0 Then
		Return True
	Else
		Return False
	End If
End Sub

Public Sub PrintSetVoltage(data As Int) As Boolean
	Dim retValue As Int = printerObj.RunMethod("PrintSetVoltage", Array(data))
	errors(retValue)
	If retValue = 0 Then
		Return True
	Else
		Return False
	End If
End Sub

'nLevel：
'Density level, value 1~5
'1:Lowest 3：medium 5：Highest
Public Sub PrintSetGray(data As Int)
	Dim retValue As Int = printerObj.RunMethod("PrintSetGray", Array(data))
	errors(retValue)
	If retValue = 0 Then
		Return True
	Else
		Return False
	End If
End Sub

Public Sub PrintSetFont(fontHeight As Int, fontWidth As Int, zoom As Int)
	Dim bytedata(3) As Byte
	bytedata(0) = fontHeight
	bytedata(1) = fontWidth
	bytedata(2) = zoom

	Dim retValue As Int = printerObj.RunMethod("PrintSetFont", Array(bytedata(0),bytedata(1),bytedata(2)))
	errors(retValue)
	If retValue = 0 Then
		Return True
	Else
		Return False
	End If
End Sub


Private Sub errors(errornum As Int)
	
	If errornum = 0 Then errorString = "successfully"
	
	'IccOpen
	If errornum = (-2403)  Then errorString = "Channel Error"
	If errornum = (-2405)  Then errorString = "The card Is pulled out Or Not"
	If errornum = (-2404)  Then errorString = "Protocol error"
	If errornum = (-2500)  Then errorString = "Voltage mode error of IC card reset"
	If errornum = (-2503)  Then errorString = "Communication failure."
	'IccCommand
	If errornum = -2503 Then errorString = "Communication timeout"
	If errornum = -2405 Then errorString = "The cards are put out in the transaction"
	If errornum = -2401 Then errorString = "Parity error"
	If errornum = -2403 Then errorString = "Select Channel error"
	If errornum = -2400 Then errorString = "Sending data too long（LC)"
	If errornum = -2404 Then errorString = "The Protocol error（is Not T = 0 Or T = 1)"
	If errornum = -2406 Then errorString = "No reset card"
	
	'Print
	If errornum = -4001 Then errorString = "PRINT BUSY"
	If errornum = -4002 Then errorString = "PRINT NOPAPER"
	If errornum = -4003 Then errorString = "PRINT DATAERR"
	If errornum = -4004 Then errorString = "PRINT FAULT"
	If errornum = -4005 Then errorString = "PRINT TOOHEAT"
	If errornum = -4006 Then errorString = "PRINT UNFINISHED"
	If errornum = -4007 Then errorString = "PRINT NOFONTLIB"
	If errornum = -4008 Then errorString = "PRINT BUFFOVERFLOW"
	If errornum = -4009 Then errorString = "PRINT SETFONTERR"
	If errornum = -4010 Then errorString = "PRINT GETFONTERR"
	
	'BMP
	If errornum = -4003 Then errorString = "PRN_DATAERR"
	If errornum = -4004 Then errorString = "PRN_FAULT"
	If errornum = -4008 Then errorString = "PRN_BUFFOVERFLOW"
	
	
	'PrintStart
	If errornum = -1001 Or errornum = 1001 Then errorString = "send fail"
	If errornum = -1002 Or errornum = 1002 Then errorString = "receive timeout"
	If errornum = -1 Then errorString = "Short of paper"
	If errornum = -2 Then errorString = "The temperature Is too high"
	If errornum = -3 Then errorString = "The voltage Is too low"
	If errornum = 8/9 Then errorString = "Instruction reply disorder"
	If errornum = -1023 Then errorString = "status error"
	If errornum = -1021 Then errorString = "Short of paper"
	If errornum = -1000 Or errornum = -1016 Or errornum = -1001 Or errornum = -1002 Or errornum = -1003 Or errornum = -1004 Or errornum = -1019 Or errornum = -1017 Or errornum = -1018 Or errornum = -1020 Then errorString = "print timeout"
	If errornum = -1007 Or errornum = -1008 Or errornum = -1009 Or errornum = -1010 Or errornum = -1011 Or errornum = -1012 Then errorString = "Print times exceeds limit"
	If errornum = -1022 Then errorString = "heat error"
	If errornum = -1015 Or errornum = -1014 Then errorString = "Short of paper"

	
	errorValue = errornum
	
End Sub
