ESC/POS Customer Display source code

Technical assistance & information for projects
Post Reply
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

ESC/POS Customer Display source code

Post by Neo » Sat Nov 28, 2009 6:14 am

Programme your own POS system - Part 2

This code was also written by me as a part of the POS system. I have tested this with 20x2 vacuum fluorescent display (VFD) models 5220 and 7220.
main-2.jpg
main-2.jpg (10.11 KiB) Viewed 33507 times

Code: Select all

'/******************************************************************************************************
'*
'* Project       : POS
'* File          : ESC_D.c
'* Description   : ESC POS commands for ESC/POS standard customer display
'* Author        : Neo
'* Copyright     : ROBOT.LK Labs (https://robot.lk)
'*
'*
'* Version   Date        Author                  Change/Reason
'* -------   ----------  --------------------    -------------------------------------------------------
'*   1.0     10/02/2005  Neo                     Created
'*******************************************************************************************************/
Option Explicit

'ESC/POS constants standard commanding to receipt printer
Private Const LF As Byte = &HA
Private Const ESC As Byte = &H1B
Private Const GS As Byte = &H1D

'ESC/POS constants standard commanding to customer display
Private Const NLL As Byte = &H0
Private Const MD1 As Byte = &H1
Private Const MD2 As Byte = &H2
Private Const MD3 As Byte = &H3
Private Const MD4 As Byte = &H4
Private Const MD5 As Byte = &H5
Private Const MD6 As Byte = &H6
Private Const MD7 As Byte = &H7
Private Const MD8 As Byte = &H8
Private Const BS As Byte = &H8
Private Const HT As Byte = &H9
'Private Const LF As Byte = &HA
Private Const HOM As Byte = &HB
Private Const CLR As Byte = &HC
Private Const CR As Byte = &HD
Private Const SLE1 As Byte = &HE
Private Const rs As Byte = &HF
Private Const SLE2 As Byte = &HF
Private Const DLE As Byte = &H10
Private Const DC1 As Byte = &H11
Private Const DC2 As Byte = &H12
Private Const DC3 As Byte = &H13
Private Const DC4 As Byte = &H14
Private Const CAN As Byte = &H18
'Private Const ESC As Byte = &H1B
Private Const SF1 As Byte = &H1E
Private Const US As Byte = &H1F, SF2 As Byte = &H1F

'Customer display scrolling control variables
Private loc1 As Byte
Private loc2 As Byte
Private wMsg As String
Private nMsg As String

'Class variables

Private IORP As IO
Private IODR As IO
Private IOCD As IO

'common use for printing funtions
Private tmp As String, ret As Integer
Private font As Byte, Height As Byte, Width As Byte, Emp As Byte, Colour As Byte

Private ADOCon As Connection
Private rec_no As String

Private DRStatus As Byte '0-no drawer 1 - stand alone   2-with printer
Private CDStatus As Byte '0-no display 1 - stand alone   2-with drawer   3-with printer

Public Sub initVar()
DRStatus = 0
CDStatus = 0
wMsg = stt.gwMsg
nMsg = stt.gnMsg
If wMsg = "0" Then wMsg = "Welcome to Digital Research Technologies (Pvt) Ltd., The technology at your fingertips   *  "
End Sub

Public Sub initRP(rp As IO, newCon As DBCon)
Set IORP = rp
IORP.WriteString (Chr(ESC) & "@") 'ESC @ - initialise code
lineFeed
Set ADOCon = newCon.con
End Sub

Public Sub initDR(dr As IO)
Set IODR = dr
End Sub

Public Sub initCD(cd As IO)
Set IOCD = cd
End Sub

Public Property Let gdrStatus(cdrStatus As Byte)
DRStatus = cdrStatus
End Property

Public Property Let gcdStatus(ccdStatus As Byte)
CDStatus = ccdStatus
'0-no display 1 - stand alone   2-with drawer   3-with printer
If CDStatus = 2 Then
    Set IOCD = IODR
ElseIf CDStatus = 3 Then
    Set IOCD = IORP
End If
End Property

'***********   ESC/POS standard commanding to customer display  ************
Public Sub startScr()
'Dim tmp As String, ret As Integer
loc1 = 1
loc2 = 1
tmp = clearDisplay
If CDStatus = 3 Then
    tmp = tmp & selectDevice(1)
End If
tmp = tmp & scrollHor & moveXY(20, 1)
ret = IOCD.WriteData(tmp, Len(tmp))
End Sub

Public Sub stopScr()
'Dim tmp As String, ret As Integer
tmp = scrollOvr
'tmp = tmp & setWindow(1, 1, 1, 1, 20, 2)
ret = IOCD.WriteData(tmp, Len(tmp))
If CDStatus = 3 Then
    tmp = tmp & selectDevice(0)
End If
End Sub

'Public Sub printScr()          'Tested on 5220
'Dim tmpW As String
'Dim tmpN As String
'tmpW = moveXY(20, 1)
'tmpW = tmpW & Mid(wMsg, loc1, 1)
'ret = IOCD.WriteData(tmpW, Len(tmpW))
'
'If nMsg <> "0" Then
'    tmpN = moveXY(20, 2)
'    tmpN = tmpN & Mid(nMsg, loc2, 1)
'    loc2 = loc2 + 1
'    If loc2 > Len(nMsg) Then loc2 = 1
'    IOCD.Wait (8)
'    ret = IOCD.WriteData(tmpN, Len(tmpN))
'End If
'
'loc1 = loc1 + 1
'If loc1 > Len(wMsg) Then loc1 = 1
'End Sub

Public Sub printScr()           'Tested on 7220
Dim tmpW As String
Dim tmpN As String

If nMsg = "0" Then
    tmpW = Mid(wMsg, loc1, 1)
Else
    tmpW = Mid(wMsg, loc1, 1) & moveDown
End If

ret = IOCD.WriteData(tmpW, Len(tmpW))

If nMsg <> "0" Then
    tmpN = tmpN & Mid(nMsg, loc2, 1) & moveUp
    loc2 = loc2 + 1
    If loc2 > Len(nMsg) Then loc2 = 1
    IOCD.Wait (8)
    ret = IOCD.WriteData(tmpN, Len(tmpN))
End If

loc1 = loc1 + 1
If loc1 > Len(wMsg) Then loc1 = 1
End Sub

Public Sub printXy(x As Byte, y As Byte, str As String)
'Dim tmp As String, ret As Integer
tmp = clearDisplay
If CDStatus = 3 Then
    tmp = tmp & selectDevice(1)
End If
tmp = tmp & moveXY(x, y) & str
If CDStatus = 3 Then
    tmp = tmp & selectDevice(0)
End If
ret = IOCD.WriteData(tmp, Len(tmp))
End Sub

Public Sub printXy2(x1 As Byte, y1 As Byte, str1 As String, x2 As Byte, y2 As Byte, str2 As String)
'Dim tmp As String, ret As Integer
tmp = clearDisplay
If CDStatus = 3 Then
    tmp = tmp & selectDevice(1)
End If
tmp = tmp & moveXY(x1, y1)
tmp = tmp & str1
tmp = tmp & moveXY(x2, y2) & str2
If CDStatus = 3 Then
    tmp = tmp & selectDevice(0)
End If
ret = IOCD.WriteData(tmp, Len(tmp))
End Sub

Public Sub printXy3(x1 As Byte, y1 As Byte, str1 As String, x2 As Byte, y2 As Byte, str2 As String, x3 As Byte, y3 As Byte, str3 As String)
'Dim tmp As String, ret As Integer
tmp = clearDisplay
If CDStatus = 3 Then
    tmp = tmp & selectDevice(1)
End If
tmp = tmp & moveXY(x1, y1)
tmp = tmp & str1
tmp = tmp & moveXY(x2, y2)
tmp = tmp & str2
tmp = tmp & moveXY(x3, y3) & str3
If CDStatus = 3 Then
    tmp = tmp & selectDevice(0)
End If
ret = IOCD.WriteData(tmp, Len(tmp))
End Sub

'Public Sub printXy4(x1 As Byte, y1 As Byte, str1 As String, x2 As Byte, y2 As Byte, str2 As String, x3 As Byte, y3 As Byte, str3 As String, x4 As Byte, y4 As Byte, str4 As String)
''Dim tmp As String, ret As Integer
'tmp = clearDisplay
'If CDStatus = 3 Then
'    tmp = tmp & selectDevice(1)
'End If
'tmp = tmp & moveXY(x1, y1)
'tmp = tmp & str1
'tmp = tmp & moveXY(x2, y2)
'tmp = tmp & str2
'tmp = tmp & moveXY(x3, y3)
'tmp = tmp & str3
'tmp = tmp & moveXY(x4, y4) & str4
'If CDStatus = 3 Then
'    tmp = tmp & selectDevice(0)
'End If
'ret = IOCD.WriteData(tmp, Len(tmp))
'End Sub

'Private Function moveRight() As String
'moveRight = Chr(HT) 'HT move cursor right
'End Function
'
'Private Function moveLeft() As String
'moveLeft = Chr(BS) 'BS move cursor left
'End Function
'
Private Function moveUp() As String
moveUp = Chr(US) & Chr(LF) 'US LF move cursor up
End Function

Private Function moveDown() As String
moveDown = Chr(LF) 'LF move cursor down
End Function
'
'Private Function moveRightMost() As String
'moveRightMost = Chr(US) & Chr(CR) 'US CR move cursor rightMost
'End Function
'
'Private Function moveLeftMost() As String
'moveLeftMost = Chr(CR) 'CR move cursor leftMost
'End Function
'
'Private Function moveHome() As String
'moveHome = Chr(HOM) 'HOM move cursor home
'End Function

'Private Function moveBottom() As String
'moveBottom = Chr(US) & "B" 'US B move cursor bottom
'End Function

Private Function moveXY(x As Byte, y As Byte) As String
moveXY = Chr(US) & "$" & Chr(x) & Chr(y) 'US $ x y move cursor x,y
End Function

Private Function clearDisplay() As String
clearDisplay = Chr(CLR) 'CLR clear display
End Function

'Private Function clearLine() As String
'clearLine = Chr(CAN) 'CLR clear display
'End Function

'Private Function bright(br As Byte) As String '&h01 - &h04
'bright = Chr(US) & "X" & Chr(br) 'US X n - brightness control
'End Function

'Private Function blink(speed As Byte) As String '&h00 - &hff (0-255)
'blink = Chr(US) & "E" & Chr(speed) 'US E n - blink
'End Function

Private Function scrollOvr() As String
scrollOvr = Chr(US) & Chr(MD1) 'US MD1 - scroll overwrite
End Function

'Private Function scrollVer() As String
'scrollVer = Chr(US) & Chr(MD2) 'US MD2 - scroll Verticle
'End Function

Private Function scrollHor() As String
scrollHor = Chr(US) & Chr(MD3) 'US MD3 - scroll Horizontal
End Function

'Private Function setTime() As String
'setTime = Chr(ESC) & "T" & Chr(DatePart("h", Time)) & Chr(DatePart("n", Time)) 'ESC T h m set time
'End Function
'
'Private Function runTime() As String
'runTime = Chr(US) & "U" 'US U display time continuously
'End Function
'
'Private Function cursorOn() As String
'cursorOn = Chr(US) & "C1" 'US C 1 - show cursor
'End Function
'
'Private Function cursorOff() As String
'cursorOff = Chr(US) & "C0" 'US C 0 - hide cursor
'End Function

'Private Function setWindow(n As Byte, s As Byte, x1 As Byte, y1 As Byte, x2 As Byte, y2 As Byte) As String
'setWindow = Chr(ESC) & "W" & Chr(n) & Chr(s) & Chr(x1) & Chr(y1) & Chr(x2) & Chr(y2) 'ESCset window
'End Function

''CD 5220/II standard commanding to customer display
'
'private Function scrollOvr()
'IOCD.WriteString (Chr(ESC) & Chr(DC1))  'ESC DC1 - scroll overwrite
'End Function
'
'private Function scrollVer()
'IOCD.WriteString (Chr(ESC) & Chr(DC2))  'ESC DC2 - scroll Verticle
'End Function
'
'private Function scrollHor()
'IOCD.WriteString (Chr(ESC) & Chr(DC3))  'ESC DC3 - scroll Horizontal
'End Function
'
'private Function msgUpper(msg As String)
'msg = Left(msg, 20)
'IOCD.WriteString (Chr(ESC) & "QA" & msg & Chr(CR))  'ESC Q A.......CR msg to upper line
'End Function
'
'private Function msgLower(msg As String)
'msg = Left(msg, 20)
'IOCD.WriteString (Chr(ESC) & "QB" & msg & Chr(CR))  'ESC Q B.......CR msg to lower line
'End Function
'
'private Function msgScroll(msg As String)
'msg = Left(msg, 40)
'IOCD.WriteString (Chr(ESC) & "QD" & msg & Chr(CR))  'ESC Q D.......CR msg to scroll in upper line
'End Function
'
'private Function moveLeft()
'IOCD.WriteString (Chr(BS))  'BS or ESC [ D move cursor left
'End Function
'
'private Function moveRight()
'IOCD.WriteString (Chr(HT))  'HT or ESC [ C move cursor right
'End Function
'
'Private Function moveUp()
'IOCD.WriteString (Chr(ESC) & "[A") 'ESC [ A move cursor up
'End Function
'
'Private Function moveDown()
'IOCD.WriteString (Chr(LF)) 'LF or ESC [ B move cursor down
'End Function
'
'private Function moveHome()
'IOCD.WriteString (Chr(HOM)) 'HOM or ESC [ H move cursor home
'End Function
'
'private Function moveLeftMost()
'IOCD.WriteString (Chr(CR))  'CR or ESC [ L move cursor leftMost
'End Function
'
'private Function moveRightMost()
'IOCD.WriteString (Chr(ESC) & "[R") 'ESC [ R move cursor rightMost
'End Function
'
'private Function moveBottom()
'IOCD.WriteString (Chr(ecr) & "[K") 'ECR [K move cursor bottom
'End Function
'
'private Function moveXY(x As Byte, y As Byte)
'IOCD.WriteString (Chr(ESC) & "l" & Chr(x) & Chr(y))  'ECS l x y move cursor x,y
'End Function
'
'private Function setWindows(x1 As Byte, x2 As Byte, y As Byte)
'IOCD.WriteString (Chr(ESC) & "W1" & Chr(x1) & Chr(x2) & Chr(y)) 'ECS W s x1 x2 y set windows in hor scroll s=1
'End Function
'
'private Function cancelWindows(x1 As Byte, x2 As Byte, y As Byte)
'IOCD.WriteString (Chr(ESC) & "W0" & Chr(x1) & Chr(x2) & Chr(y)) 'ECS W s x1 x2 y set windows in hor scroll s=0
'End Function
'
'private Function clearDisplay()
'IOCD.WriteString (Chr(CLR)) 'CLR clear display
'End Function
'
'private Function clearLine()
'IOCD.WriteString (Chr(CAN)) 'CLR clear display
'End Function
'
'private Function bright(br As Byte) '&h01 - &h04
'IOCD.WriteString (Chr(ESC) & "*" & Chr(br)) 'ESC * n - brightness control
'End Function
'
'private Function cursorOn()
'IOCD.WriteString (Chr(ESC) & "_1")  'ESC _ n - show cursor n=1
'End Function
'
'private Function cursorOff()
'IOCD.WriteString (Chr(ESC) & "_0")  'ESC _ n - hide cursor n=0
'End Function
'
'private Function blink(speed As Byte) '&h00 - &hff (0-255)
'IOCD.WriteString (Chr(US) & "E" & Chr(speed)) 'US E n - blink
'End Function
'
'private Function setTime()
'IOCD.WriteString (Chr(ESC) & "T" & Chr(DatePart("h", Time)) & Chr(DatePart("n", Time))) 'ESC T h m set time
'End Function
'
'private Function runTime()
'IOCD.WriteString (Chr(US) & "U") 'US U display time continuously
'End Function
CD5220 Manual:
CD5220_Manual.pdf
(663.39 KiB) Downloaded 3818 times
Please make sure that you post a reply to say thanks if it works okay for you. :)

See also:
ESC/POS printer & cash drawer source code at https://robot.lk/viewtopic.php?f=39&t=874
Point of Sale printer/drwer and Customer Display source code at https://robot.lk/viewtopic.php?f=39&t=876
Barcode printer source code at https://robot.lk/viewtopic.php?f=39&t=877
User avatar
engengcode
Posts: 1
Joined: Thu Dec 10, 2009 2:18 pm

Customer Display Command in VB.NET

Post by engengcode » Fri Dec 11, 2009 7:01 am

can someone give me a code for VB.Net that make my text message in pole/customer display scrolling from right to left.

this is my code for writing text message in pole display, but i dont know how to make it scroll from RIGHT to LEFT

serialport1.portname = "COM1"
serialport1.open
serialport1.write("WELCOME TO OUR STORE")

thank you...
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: ESC/POS Customer Display source code

Post by Neo » Fri Dec 11, 2009 1:11 pm

I can't remember whether scrolling is possible in both directions. You may find it in the manual. If scrolling is not possible to the direction you want, you may have to do it using code. (See print commands)

To do standard scrolling use following procedure.
First call startScr to start scrolling. Then call printScr within a timer.
(that's about scrolling two messages in both lines, you can change it as you want)
You will have to do a simple conversion to VB.Net.
User avatar
tnn
Posts: 2
Joined: Fri Jul 20, 2012 2:59 pm

Re: ESC/POS Customer Display source code

Post by tnn » Fri Jul 20, 2012 3:37 pm

Can you give me a code in Java to programme a Pole/Customer Display with a USB plugin? I have already developed a POS software to present it in the viva.but I don't know how to programme this customer display.Its okay if you can give it in C++. :D I searched it every in Google.There wasn't any in Java code for USB port ones. :(
Looking forward for a favourable relpy. :D :D :D
User avatar
viz
Posts: 1
Joined: Thu Mar 20, 2014 10:55 am

Re: ESC/POS Customer Display source code

Post by viz » Thu Mar 20, 2014 11:04 am

Hello Neo, can you please give me the source code of IO class which you are using for POS display . I read your post but IO class is not there thats why i m getting error. Thanks in advance.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: ESC/POS Customer Display source code

Post by Neo » Wed Mar 26, 2014 11:44 am

As said over PM, those days MSCOMM had an issue and later it was fixed. The IO class was a self-written class based on Windows API (CreateFile, WriteFile, ReadFile, etc...). Later the MSCOMM started to work fine.
Post Reply

Return to “Project Assistance”