Sample ZBI Programs

ZBI code demonstrating ZPL usage

ZBI code demonstrating extraction (extract and searchto commands)

ZBI code demonstrating ARRAYS

ZBI code demonstrating numeric expressions

ZBI code demonstrating integer functions

Advanced Exercises

ZBI utilizing E-mail functionality

ZBI utilizing TCP port functionality

ZBI code demonstrating UDP functionality

ZBI code demonstrating Socket functionality

 

Sample ZBI code showing ZPL usage

Commands: Close, REM, OPEN, PRINT, INPUT, GOTO, IF, ELSE, ENDIF, !, END, SLEEP

This program will enable a user to make three choices,  to print a configuration label, to print text or to calibrate the printer.  The corresponding ZPL commands will be sent to the printer depending upon what choice the user makes. 

5 REM PORTS SHOULD BE CLOSED, BY ROUTINE, BEFORE OPENING
10 CLOSE # 1
20 CLOSE # 2
25 REM OPENING PORT
40 OPEN # 1 : NAME "ZPL"
45 REM THE FOLLOWING WILL BE DISPLAYED ON THE TERMINAL
50 PRINT "YOU HAVE THREE CHOICES"
51 PRINT "PRESS 1 TO PRINT CONFIG LABEL" !prints to the console
52 PRINT "PRESS 2 TO PRINT TEXT "
53 PRINT "PRESS 3 TO CALIBRATE"
54 PRINT "OR PRESS 7 TO EXIT"
58 REM THE FOLLOWING ARE THE POSSIBLE INPUTS
60 INPUT A !PRINTER IS EXPECTING AN INPUT
61 IF A = 1 THEN
62 GOTO 120
63 ELSE
65 IF A = 2 THEN
66 GOTO 130
67 ELSE
70 IF A = 3 THEN
71 GOTO 140
72 ELSE
75 IF A = 7 THEN
76 GOTO 300
80 END IF
81 GOTO 51
85 REM IF THERE IS AN IF STATEMENT ALWAYS HAVE AN ENDIF STATEMENT
95 REM THE FOLLOWING WILL PRINT A CONFIGURATION LABEL TO THE PRINTER
120 PRINT # 1 : "~WC" !~WC TELLS THE PRINTER TO PRINT CONFIGURATION LABEL
125 GOTO 50
130 PRINT "THIS TASK WILL SEND SAMPLE TEXT TO THE PRINTER"
131 PRINT "INPUT YOUR SAMPLE TEXT"
132 INPUT Y$
133 REM THE FOLLOWING STATEMENT WILL PRINT THE Y$ STRING VALUE THAT WAS INPUT
135 PRINT # 1 : "^XA^FO20,20^A0N50,50^FD" ; Y$ ; "^XZ"
136 GOTO 50
139 REM THE FOLLOWING COMMAND WILL TELL THE PRINTER TO CALIBRATE
140 PRINT # 1 : "~JG" !~JG ZPL COMMAND BEING SENT TO THE PRINTER
141 GOTO 50
300 PRINT "BEFORE CLOSING THE PRINTER WILL NOW PAUSE FOR 10 SECONDS"
301 SLEEP 10 ! THE SLEEP COMMAND PAUSES THE PRINTER
310 END


 

Sample ZBI code  using extract and searchto commands

Commands: REM, CLOSE, OPEN, EXTRACT, SEARCHTO, LET, PRINT, END

This example will search streaming data,  search for the word "START" and print what values are between the letters T and W.   To see this program work run the program and send data (file) containing the following text somewhere in the data (file). 

"START T testing W"    The word "testing" will be printed on the printer using the ^FD ZPL command.

10 REM ALWAYS CLOSE PORTS BEFORE OPENING (ROUTINE)
20 CLOSE # 1
30 CLOSE # 2
60 OPEN # 1 : NAME "ZPL"
69 REM SPECIFYING VALUE FOR STRING BELOW
70 LET B$ = "START"
79 REM USING SEARCHTO$ COMMAND TO SEARCH STREAMING DATA FOR B$ OR THE WORD "START"
80 LET Z$ = SEARCHTO$ ( 0 , B$ )
89 REM SPECIFYING VALUES FOR THE STRINGS F$ AND G$ ("T" AND "W ")
90 LET F$ = "T "
100 LET G$ = " W"
108 REM USING THE EXTRACT$ COMMAND TO SEARCH STREAMING DATA FOR F$ AND G$
109 REM X$ WILL BE THE DATA BETWEEN F$ AND G$ 
110 LET X$ = EXTRACT$ ( 0 , F$ , G$ )
250 PRINT # 1 : "^XA^F025,25^A050,50^FD" & X$ &"^FS^XZ"
1000 END



Sample ZBI code using ARRAYS

Commands: REM, CLOSE, OPEN, DECLARE, FOR, NEXT, PRINT,  INPUT, END

This program will allow the user to input 5 different names and corresponding numbers.  The printer will then print out these names/numbers. 

5 REM PORTS SHOULD BE CLOSED, BY ROUTINE, PRIOR TO OPENING
10 CLOSE #1
20 CLOSE #2
40 OPEN #1: NAME "ZPL"
45 REM WHEN USING ARRAYS, THE ARRAY HAS TO BE DECLARED BEFORE USING.
49 REM THIS ARRAY "NAME$" IS BEING DEFINED WITH 5 SPOTS FOR DATA
50 DECLARE STRING NAME$ (5)
57 REM THE FOLLOWING ALLOWS ONE TO INPUT 5 DIFFERENT VALUES AND THE VALUES
58 REM ARE PLACED INTO THE ARRAY IN ORDER (1-5)
59 PRINT "INPUT YOUR FIRST 5 NAMES"
60 FOR INDEX = 1 TO 5 STEP 1
70 INPUT NAME$(INDEX)
80 NEXT INDEX
89 REM THE FOLLOWING DECLARES AN ARRAY (NUMBERS$) AND ALLOWS 5 SPOTS FOR DATA
90 DECLARE STRING NUMBERS$ (5)
99 PRINT "INPUT YOUR FIRST 5 NUMBERS"
100 FOR INDEX = 1 TO 5 STEP 1
110 INPUT NUMBERS$(INDEX)
120 NEXT INDEX
128 REM THE FOLLOWING PRINTS OUT THE VALUES THAT HAVE BEEN STORED IN THE ARRAYS
130 PRINT #1 : "^XA^FO60,60^A0N50,50^FD"&NAME$(1)&"^FS";
140 PRINT #1 : "^FO60,120^A0N50,50^FD"&NUMBERS$(1)&"^FS^XZ"
150 PRINT #1 : "^XA^FO60,60^A0N50,50^FD"&NAME$(2)&"^FS";
160 PRINT #1 : "^FO60,120^A0N50,50^FD"&NUMBERS$(2)&"^FS^XZ"
170 PRINT #1 : "^XA^FO60,60^A0N50,50^FD"&NAME$(3)&"^FS";
180 PRINT #1 : "^FO60,120^A0N50,50^FD"&NUMBERS$(3)&"^FS^XZ"
190 PRINT #1 : "^XA^FO60,60^A0N50,50^FD"&NAME$(4)&"^FS";
200 PRINT #1 : "^FO60,120^A0N50,50^FD"&NUMBERS$(4)&"^FS^XZ"
210 PRINT #1 : "^XA^FO60,60^A0N50,50^FD"&NAME$(5)&"^FS";
220 PRINT #1 : "^FO60,120^A0N50,50^FD"&NUMBERS$(5)&"^FS^XZ"
300 END


 

Sample ZBI code showing integer functions

Integer functions: LEN, MIN, ORD

String function: CHR$(M)

Commands: REM, CLOSE, PRINT, INPUT , LET , END, !

This sample program will ask for various inputs and use the integer functions of ZBI to derive resulting length of strings, smallest number, and ascii equivalents.  This program also shows how the " character can be printed using the CHR$(M) string command. 

10 REM THIS PROGRAM WILL SHOW VARIOUS INTEGER FUNCTIONS
11 CLOSE # 1
12 CLOSE # 2
20 PRINT "ENTER YOUR LAST NAME"
25 INPUT A$ ! PRINTER IS EXPECTING A STRING INPUT
30 LET X = LEN ( A$ ) !THIS IS WHERE THE LENGTH IS DETERMINED
35 PRINT "YOUR LAST NAME (" ; A$ ; ") CONTAINS " ; X ; " CHARACTERS"
36 PRINT
40 PRINT "ENTER 2 DIFFERENT NUMBERS EACH FOLLOWED BY THE ENTER KEY"
45 INPUT A
46 INPUT B
55 LET Y = MIN ( A , B ) !THIS IS WHERE THE SMALLEST NUMBER IS DETERMINED
60 PRINT "THE SMALLEST NUMBER THAT YOU ENTERED WAS " ; Y
61 PRINT
65 PRINT "ENTER ANY ASCII CHARACTER FROM YOUR KEYBOARD"
66 INPUT B$
70 LET U = ORD ( B$ ) ! THIS IS WHERE THE ASCII EQUIVELANT IS DETERMINED
71 LET R = 34
75 PRINT "THE ASCII EQUIVELANT OF " , CHR$ ( R ) , B$ , CHR$ ( 290 ) , "IS" , U !THIS LINE SHOWS TWO DIFFERENT WAYS TO PRINT THE " CHARACTER USING THE CHR$ FUNCTION
76 REM IN LINE 75 I AM USING "," UNLIKE THE ";" THAT WAS USED IN LINE 35
78 REM WHEN SEPERATING WITH THE "," CHARACTER A SPACE WILL BE INCLUDED
79 REM IF USING THE ";" NO SPACE WILL BE INCLUDED AS IN LINE 34
80 END


Sample ZBI code showing Numeric expressions

Commands: Close, GOSUB, IF, REM, PRINT, LET, IF, ELSE, END, RETURN,  GOTO, ON ERROR

Numeric expressions: +, -, *, /, ^

Example showing Numeric Expressions, also showing use of ON ERROR command and GOSUB and RETURN commands. 


10 REM This program will demonstrate the use of Numeric expressions
11 CLOSE # 1
12 CLOSE # 2
20 REM SIMPLE PROGRAM SHOWING HOW TO USE NUMERIC EXPRESSIONS
28 PRINT
30 PRINT "The first example will be addition, subtraction, mulitiplication , division and exponentiation"
31 PRINT " Input your first number"
32 INPUT A 
33 PRINT " Input your second number"
35 INPUT B
38 LET X = A + B !simple math (addition)
39 LET Y = A - B !simple math (subtraction)
40 PRINT "If you add" , A , "plus" , B , "you get" , X
43 PRINT "If you subtract" , A , "minus" , B , "you get" , Y
50 LET Z = A * B !simple math (multiplication)
70 PRINT
71 PRINT "IF YOU MULTIPLY" , A , "AND" , B , "YOUR RESULT IS" , Z
75 LET J = A / B !simple math (division)
76 ON ERROR GOTO 100 !This statement allows the program to continue
78 PRINT "IF YOU DIVIDE" , A , "BY" , B , "YOU GET" , J
79 IF J = 0 THEN
80 GOSUB 400
82 GOTO 200
100 PRINT "THERE HAS BEEN A DIVIDE BY ZERO ERROR"
121 PRINT "THE SECOND NUMBER YOU ENTERED WAS A ZERO"
122 PRINT "THE ERROR WAS CAUSED BY TRYING TO DIVIDE" , A , "BY" , B
200 PRINT
201 PRINT " EXPONENTIATION USES THE ^ SYMBOL, X^2 WOULD BE X SQUARED"
202 LET G = A ^ B !exponentiation
205 PRINT A , "^" , B , "RESULTS IN" , G
300 END
400 PRINT
401 PRINT "YOUR RESULT WHEN YOU DIVIDED" , A , "BY" , B , "WAS ZERO"
405 PRINT "REMEMBER WHEN USING DIVISION THE NUMBER WILL ALWAYS BE ROUNDED DOWN"
407 RETURN


Sample ZBI code demonstrating  E-Mail functionality

ZBI example utilizing E-mail server

 

First step   SMTP server has to be identified on Printserver

 

10 CLOSE #1 
20 CLOSE #2 
30 OPEN #1: NAME "EML" ! PORT SET FOR EML FOR EMAIL SERVER 
31 OPEN #2: NAME "ZPL" 
32 PRINT "ENTER YOUR FIRST NAME" 
35 INPUT A$ 
36 PRINT "ENTER YOUR LAST NAME" 
37 INPUT B$ 
40 PRINT "ENTER YOUR EMPLOYEE NUMBER" 
42 INPUT C$ 
45 PRINT "Hello ";A$; " We are now ready to proceed" 
400 PRINT #1 : "JDOE@ZEBRA.COM";CHR$(4); !SENDING MESSAGE TO JDOE 
405 PRINT #1 : "FROM: PRINTER #1" ! MAIL FROM: DATA ("PRINTER #1")
410 PRINT #1 : "TO: MAIN LOG SERVER (EMAIL)" ! MAIL TO: DATA ("MAIN LOG SERVER")
500 PRINT #1 : "SUBJECT: EMPLOYEE "; B$ ;" ( ";C$;" ) LOGGED IN"! SUBJECT : DATA 
505 PRINT #1 : "" 
510 PRINT #1 : "EMPLOYEE "; B$; " LOGGED IN" ! MAIL MESSAGE 
550 PRINT #1 : CHR$(4) ! IMPORTANT TO END WITH EOT 
600 CLOSE #1 
700 CLOSE #2 

In this program an e-mail message will be sent to JDOE  that indicates that an employee has logged in

 


Sample ZBI code demonstrating TCP functions

ZBI Example using TCP port  

In this example, the  user is entering data.  This data is distributed between  two separate labels,  the first label will print locally on the ZPL printer.  The second label will be using TCP/IP and sent to a Mobile printer using CPCL to print a “pick list” 

10 CLOSE #1
20 CLOSE #2
30 OPEN #1: NAME "TCP"
31 OPEN #2: NAME "ZPL"
32 PRINT "ENTER THE PRODUCT NAME"
35 INPUT A$
36 PRINT "ENTER QUANTITY"
37 INPUT B
40 PRINT "ENTER THE LOCATION AISLE/SHELF # EXAMPLE 3/4 "
42 INPUT C$
45 PRINT #2 : "^XA^FO100,100^A0N,50,50^FD";A$;"^FS"; !SENDING ZPL LOCALLY
46 PRINT #2 : "^FO100,200^A0N,50,50^FD";B;"^XZ"
400 PRINT #1 : "10.3.50.79 6101";CHR$(4); !OPENING TCP PORT 
405 PRINT #1 : "! 0 200 200 400 1" !CPCL STARTS
410 PRINT #1 : "JOURNAL"
415 PRINT #1 : "PAGE-WIDTH 400"
420 PRINT #1 : "T 4 0 100 20 AISLE/SHELF"
500 PRINT #1 : "T 4 0 100 100 ";C$
501 PRINT #1 : "T 4 0 100 150 QUANTITY"
505 PRINT #1 : "T 4 0 100 200 ";B
510 PRINT #1 : "T 4 0 100 250 DESCRIPTION"
520 PRINT #1 : "T 4 0 100 300 ";A$
530 PRINT #1 : "PRINT" !CPCL ENDS WITH PRINT
550 PRINT #1 : CHR$(4); 
600 CLOSE #1
700 CLOSE #2

User enters product name, quantity , aisle/shelf location and price.   Local label prints description (product name) quantity and price, while the remote printer IP address 10.3.50.79 using TCP port 6101 (mobile printer using CPCL) prints the product description, quantity and the product location (aisle/shelf).  


 

ZBI example utilizing UDP port

In this example ZPL is being sent to an Syslog server utilizing UDP port 514.  The data that the accounting/syslog server requires is space delimitted for easy input into MS access database.

In this example  Item,Quantity,Price   PRINTER# are being sent from the printer.  Log generates automatically the Month, Date, Time and IP address. 

 

Microsoft Access Database information below

 
Month Date Time IP_Address Product_Number Quantity Price FD# Q# Printer_Number
Jun 30 1:59:45 PM 10.3.9.195 4 45 1.99

PRINTER5
Jun 30 2:00:01 PM 10.3.9.195 3 23 8.69

PRINTER5
Jun 30 2:00:14 PM 10.3.9.195 40 3 1.99

PRINTER5
Jun 30 2:00:24 PM 10.3.9.195 5 65 5.99

PRINTER5
Jun 30 2:00:44 PM 10.3.9.195 6 13 9.99

PRINTER5

 

Text file from server below

Jun 30 13:59:45 10.3.9.195 4 45 1.99    PRINTER5
Jun 30 14:00:01 10.3.9.195 3 23 8.69    PRINTER5
Jun 30 14:00:14 10.3.9.195 40 3 1.99    PRINTER5
Jun 30 14:00:24 10.3.9.195 5 65 5.99    PRINTER5

10 CLOSE #1
20 CLOSE #2
30 OPEN #1: NAME "ZPL"
40 OPEN #2: NAME "UDP"
45 LET C$ = "PRINTER5"
50 PRINT "ENTER PRODUCT NUMBER 1-45"
55 INPUT A
60 PRINT "ENTER QUANTITY"
65 INPUT B
70 PRINT "ENTER $ AMOUNT EXAMPLE 6.99"
75 INPUT A$
80 PRINT #2 : "10.3.50.79 514";CHR$(4);
90 PRINT #2 : A ;" ";B;" ";A$;" ";" ";" ";C$;
91 REM The extra spaces in above line are for
92 REM columns in ACCESS database where no data is sent or needed from the printer
95 PRINT #2: CHR$(4);
100 CLOSE #1
105 CLOSE #2


ZBI Code demonstrating Sockets

10 Close #1
20 Open #1:name "ZPL"
30 Let TCPserver = serversocket("TCP")               
40 Let TheTCPort = Accept(TCPserver)                  
50 On Error GoTo 90                                   
60 Let A$ = searchto$(TheTCPort,"My Data")
61 LET B$ = EXTRACT$ (TheTCPort," "," ")         
70 On Error Goto 90                                    
80 Print #1:"^XA^FO50,50^A0N50,50^FD";B$;"^FS^XZ";    
85 let theTCPort = serverclose(TCPserver)             
87 END                                     
90 sleep 2 
100 GoTo 40

   

Line 10 As a general rule always close ports before opening them to make sure that the port is open only for this program.
Line 20 Opening up “ZPL” port as “#1”  
Line 30 Defining socket (using TCP protocol) calling it TCPserver
Line 40 Opening up tcp port for listening
Line 50 If the port is not being used go to line 90
Line 60 If the port is open ; Searching the data from the printserver (TCPort) for the string “My Data”
Line 61 As soon as it receives the string “My data” it will extract the data between the first space and the second space” and call this B$Line 80 Sends ZPL to the printer with the data it received in line 61
Line 85 closes the TCPport (stops listening)
Line 87 Ends the program
Line 90 Program pauses for 2 seconds
Line 100 After pausing for 2 seconds goes back to line 40 (opening the port for listening)

 

In this example a sample text file with the following information in it is sent to the printer through a printserver using the FTP PUT command. 

"Test My Data TEST end"

The word TEST will be printed

When running the program with trace and debug turned on this is what will display. Note the Communication failure prior to the ftp connection being made.