Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim usb1 As UsbSerial
Dim astreams1 As AsyncStreams
End Sub
#Region EXAMPLE POSPRINTER
Sub aprostampante
If usb1.UsbPresent(1) = usb1.USB_NONE Then ' Ver_2.4
Log("Msgbox - no device")
Msgbox("No USB device or accessory detected!", "Error")
Log("Msgbox - returned")
Return
End If
Log("Checking permission 1")
If (usb1.HasPermission(1)) Then ' Ver_2.4
'Msgbox(usb1.DeviceInfo(1), "Device Information 1") ' Ver_2.4
Log(usb1.DeviceInfo(1))
'Questo è importante
usb1.SetCustomDevice(usb1.DRIVER_SILABS, 0x493, 0x8760)
'usb1.SetParameters(19200, usb1.DATABITS_8,usb1.STOPBITS_1, usb1.PARITY_NONE)
Dim dev As Int
dev = usb1.Open(19200, 1) 'STMicroeletronics
'dev = usb1.Open(4800, 1)
'dev = usb1.Open(115200, 1) ' Ver_2.4
'dev = usb1.Open(9600, 1) ' Ver_2.4
If dev <> usb1.USB_NONE Then
Log("Connected successfully! 1")
astreams1.Initialize(usb1.GetInputStream, usb1.GetOutputStream, "astreams1")
'THIS IS VERY IMPORTANT- PARAMETER
usb1.SetParameters(19200, usb1.DATABITS_8,usb1.STOPBITS_1, usb1.PARITY_NONE)
'START PRINT
stampafattura
Else
Log("Error opening USB port 1")
End If
Else
usb1.RequestPermission(1) ' Ver_2.4
End If
End Sub
Sub stampafattura
'astreams1.Write("By Devil-App".GetBytes("UTF8"))
'astreams1.Write("Welcome To USB Receiver" & Chr(10) & Chr(13))
'astreams1.Write("By Devil-App" & Chr(10) & Chr(13))
'***** START DEMO
Dim SendMsg As String
SendMsg = "HOUSE FOOD & ROOMS" 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = "LOCATION: TAKE AWAY" 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = "TEL: 0302-774477, 0302-773399, 024-4145444" 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = "CASHIER: TAKE AWAY PM" 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
'Print Date and Time
SendMsg = DateTime.Date(DateTime.Now) & " " & DateTime.Time(DateTime.Now) 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
'Qui inserisco il numero di ordine
SendMsg = "ORDER NO:" & ordine_consegna 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = "*******************************" 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
'Here Receipt no:
SendMsg = "RECEIPT NO: XXXXXXXXX" 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
'COLUMN HEADER
Dim d_qta As String = "QTY"
Dim d_desc As String = "ITEM"
Dim d_price As String = "U/PRICE"
Dim d_total As String = "TOTAL"
'QTY++ITEM++++++++U/PRICE+++TOTAL
Dim myString As String=Chr(27) & "D" & Chr(4) & Chr(17) & Chr(27) & Chr(0) & d_qta & Chr(9) & d_desc & Chr(9) & d_price & Chr(9) & d_total
astreams1.Write(myString.GetBytes("UTF8"))
astreams1.Write(Array As Byte(13, 10))'Line feed
'LOOP EXAMPLE
For i = 0 To 3
Dim qta As String = i
Dim ii As Int = Rnd(0, 1000)
Dim descrizione As String = "Descrizione " & i & ii
descrizione = descrizione.SubString2(0,13)
Dim price As String = "30.14"
'0++++Descrizione 0
astreams1.Write(Array As Byte(13, 10))'Line feed
Dim mydetails As String=Chr(27) & "D" & Chr(4) & Chr(19) & Chr(26) & Chr(0) & qta & Chr(9) & descrizione & Chr(9) & price & Chr(9) & price
astreams1.Write(mydetails.GetBytes("UTF8"))
Next
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = "*******************************" 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
'Qui inserisco i paramtri per NHIS e VAT in modo da detrarre il totale
Dim contototale As Double = 121.60
Dim totalenhis As Double = contototale * 0.0244
Dim totalevat As Double = contototale * 0.1275
Dim subtotale As Double = contototale - totalenhis - totalevat
'Fine calcolo
SendMsg = "SUB - TOTAL: " & NumberFormat2(subtotale, 0, 2, 2, True) 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
'NHIS
SendMsg = "NHIS: " & NumberFormat2(totalenhis, 0, 2, 2, True) 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
'VAT
SendMsg = "VAT: " & NumberFormat2(totalevat, 0, 2, 2, True) 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = "*******************************" 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
'TOTAL 2
SendMsg = "AMOUNT DUE: " & NumberFormat2(contototale, 0, 2, 2, True) 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = "*******************************" 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = "PAID: " & NumberFormat2(contototale, 0, 2, 2, True) 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = "*******************************" 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = "VAT NO: 221V44449" 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = "PHONE ORDERS: 11:00AM - 10:00PM" 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = "COME AGAIN" 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = "*******************************" 'Send this line to the EPSON printer
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
SendMsg = Chr(13) & Chr(10)'Line feed
astreams1.Write(SendMsg.GetBytes("UTF8"))
'****** END PRINT
End Sub
Sub Astreams1_NewData (Buffer() As Byte)
' You must check for DeviceInfo or analyze Buffer data to know what is connected to the USB
' The order of the USB could change as you plug them and could change when changing the hub port they are connected to
Log("NewData 1")
Log(BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
End Sub
Sub AStreams1_Error
Log("Error: " & LastException)
astreams1.Close
End Sub
Sub Astreams1_Terminated
Log("Terminated")
astreams1.Close
End Sub
#End Region EXAMPLE POSPRINTER