ZebraPrint ActiveX Control
ZebraPrint ActiveX Control
Copyright © 2002, Zebra Technologies Corporation. All rights reserved.
The ZebraPrint.dll is an ActiveX control providing a simple interface to the Zebra portable printers. It currently supports 4 connection methods: serial (comm port), infrared (IrDA), TCP, and BlueTooth. Currently, BlueTooth support is provided via a simulated serial/modem connection.
After the ZebraPrint ActiveX control is installed, it can be used from within any HTML document using Microsoft’s JScript web scripting language. The control can also be used from within any other programming language that supports ActiveX, such as Visual Basic or Visual C++.
Installation Instructions for Windows CE and Pocket PC
The ZebraPrint ActiveX control for Windows CE and Pocket PC may be provided in 2 forms – either as a Windows CE / Pocket PC CAB file OR as a self-installing Windows executable. Please follow the appropriate instructions below depending on whether you have a .CAB installation file or a .EXE installation file:
To install the CAB file version of the control, follow these steps:
1) Copy the .CAB file to your Windows CE device
2) Using your CE or Pocket PC device’s file explorer tool, locate the CAB file and double-click on it. The ZebraPrint.dll will automatically be installed.
To install the .EXE version of the control, follow these steps:
NOTE: This method requires that ActiveSync 3.0 or higher be installed on your PC.
1) Connect your CE or Pocket PC device to your PC using ActiveSync.
2) Double-click on the ZebraCEPrintSetup-ALL.exe file on your Windows 9x/2000/XP computer. This will launch a Windows setup program that will unpack the ZebraPrint control and will send to your CE or Pocket PC device via Active Sync.
3) The ZebraPrint control will then be automatically installed on your CE or Pocket PC device.
Installation Instructions for the Windows 2000 and Windows XP version
The ZebraPrint ActiveX control for Windows 2000 and Windows XP is provided as a dll. Before this dll can be used, it must be registered. Run the following command to register the ActiveX control:
Regsvr32.exe \path\ZebraPrint.dll
Where \path\ is replaced with the actual path to where you have stored the ActiveX control. For example, if you stored the ActiveX control in c:\ActiveX\Zebra, you would issue the command:
Regsvr.32.exe c:\ActiveX\Zebra\ZebraPrint.dll
You should then receive a message that the ActiveX control was successfully registered.
Programming Interface
To use the ZebraPrint control, you first declare what connection method you are using with your printer. This is done via one of the following methods:
SerialConnection(string port, int baud);
where:
port is the serial port (e.g. “COM1:”, “COM2:”, etc.)
baud is the baud rate (e.g. 9600, 19200, 38400, 115200)
Declares you are connecting to the printer via a serial comm port or via a BlueTooth serial/modem connection.
IrDAConnection();
Declares you are connecting to the printer via the infrared (IrDA) port.
TcpConnection(string host, int port);
where:
host is the ip address or hostname of the printer
port is the TCP port number the printer is listening on
Declares you are connecting to the printer via TCP/IP.
NOTE: If you do not specify a connection type, ZebraPrint defaults to a serial connection on “COM1:” at 19200 baud.
After the connection is declared, you can use the following additional methods:
int Print(string data);
where:
data is the data to be sent to the printer
Print() will do an implicit Open() and Close() of the printer port, so it can be called immediately after declaring the printer connection. It will also do error checking and will prompt for retry attempts (via dialog boxes) when an error condition is encountered. Because it handles the Open() and Close() of the printer automatically and does error handling, it is recommended that Print() be used to send data to the printer. This function returns 1 on success and 0 if the Print() command failed. Call ZebraPrint’s GetLastError() function to get the error code.
NOTE: if you prefer this command does not do error checking or perform a status check before the print is performed, use the EnableStatusCheck(), SetStatusQueryTimeout(), and ShowPrompts() to modify the default behavior of this command. These commands are described below.
If you require a lower level of interaction and/or control with the printer, the following methods are also supplied:
int Open();
Opens a connection to the printer. This function returns 1 on success and 0 if the Open() command failed. On failure, the error code encountered can be retrieved via a call to ZebraPrint’s GetLastError() (see below).
Close();
Closes the connection to the printer.
long Send(string data);
where:
data is the null terminated string of data to be sent to the printer
Sends the data to the printer. Returns the number of bytes successfully sent. If the return value is less than the number of bytes in data, call GetLastError() to determine the error condition. This function requires the printer connection was previously opened via a call to Open().
string Recv(long lTimeout)
where:
lTimeout is the maximum time (in milliseconds) to block waiting for a response from the printer
This command will receive data from the printer. If the timeout period is exceeded, an empty string “” is returned. This command will block a maximum of lTimeout milliseconds. If data is received before the the timeout is exceeded, the command will return as soon as the input buffer has been exhausted for 100ms.
The maximum number of bytes returned by a single call to Recv() is 999 bytes. If 999 bytes of data is received from a single call to Recv(), another call should be made with a timeout of 0 to check for any remaining data.
long GetPrinterStatus()
This command will query the printer for its current status and will return it as a bit field. A response of 0xFFFF0000 indicates no response from the printer. The following mask values indicate different status attributes of the printer:
LOWBATTERY_MASK 0x0008 /* printer status, low-battery bit */
HEADUP_MASK 0x0004 /* printer status, head-up bit */
PAPEROUT_MASK 0x0002 /* printer status, paper-out bit */
BUSY_MASK 0x0001 /* printer status, busy bit */
EnableStatusCheck(int iCheck)
where:
iCheck specifies whether to enable (1) or disable (0) the status checking
If status checking is enabled, the ZebraPrint ActiveX control will first verify the printer is available and in a “ready” state before it attempts to send data to the printer via the Print() command. Disabling status checking will allow printing of data without first querying the printer’s status.
SetStatusQueryTimeout(int iTimeout)
where:
iTimeout specifies how long (in seconds) to wait for a response from the printer
If status checking is enabled, this command will specify how long to wait until reporting an error that there is no response from the printer. The default timeout is 10 seconds. The minimum allowed value is a timeout of 1 second.
ShowPrompts(int iPrompts)
where:
iPrompts is either a 1 or 0 to specify whether or not error messages and “retry” prompts should be displayed.
This function can be called to alter the default behavior of the Print() command. By default, when the Print() command encounters a printing problem, it will display a message window describing the problem and will allow the user to retry the print command. Passing a value of 0 to this function will disable this behavior.
EnablePrintVerify(int iVerify)
where:
iVerify is a flag to specificy whether a confirmation “reprint” prompt will be displayed after each Print()
This option is useful if you want to give the user a chance to reprint something when the printer encounters an error while it was printing (such as running out of paper). Pass a 1 to enable this feature. By default this feature is off.
SerialCloseWait(int iWait)
where:
iWait is the time in milliseconds to wait
This command will alter the default behavior of the Print() command when used with a serial port. It specifies the number of milliseconds to wait before closing the serial port after a Print(). This is useful if you have configured the printer to use the PRESENT-AT command in a printer config.sys file. You should ensure the wait time chosen exceeds the time delay specified with the PRESENT-AT command. For information on PRESENT-AT, please refer to the CPL programmer’s guide. NOTE: This command only affects serial printing – it does not apply to IR or TCP printing.
SetFlowCtl(int iFlowMask)
where:
iFlowMask specifies the flow control settings mask
This command enables/disables serial hardware and software flow control. To choose the flow control settings, build a mask of values where 0x01 specifies hardware flow control and 0x02 specifies software flow control. For example, to enable both hardware and software flow control, you would use a mask value of 0x03 (i.e. 0x1 + 0x02). The default mask is 0x0 (i.e. no flow control).
Version();
Displays the version number of the ZebraPrint.dll
long GetLastError();
Returns the numeric error code of the last error encountered by the ActiveX dll.
ShowLastError();
This method displays a window with the last error code encountered, along with a text description.
Usage Examples
1) Serial Printing within HTML
The following example illustrates using the ZebraPrint ActiveX control to print to a serial printer via an HTML document:
ZebraPrint Serial Sample
var zp = new ActiveXObject("ZebraPrint.ZebraPrintCtl");
zp.SerialConnection("COM1:", 19200);
This is a test of serial printing.
zp.Print("! 0 200 200 581 1\r\nLABEL\r\nCONTRAST 0\r\nTONE 0\r\nSPEED 3\r\nPAGE-WIDTH 240\r\nBAR-SENSE\r\nTEXT90 4 3 36 288 $22.88\r\nTEXT90 5 2 163 273 SWEATSHIRT\r\nVBARCODE UPCA 2 1 45 139 576 04364503284\r\nTEXT90 7 0 191 511 043645032841\r\nTEXT90 5 0 4 524 COMPARE AT\r\nTEXT90 4 0 30 508 $ 30.00\r\nTEXT90 5 0 115 575 ZD-180-KL\r\nTEXT90 5 2 119 269 ALL COTTON\r\nTEXT90 7 0 114 389 01/17/98\r\nTEXT90 0 0 208 173 EA00-732-00560\r\nTEXT90 5 0 82 519 ELSEWHERE\r\nBOX 189 358 217 527 1\r\nFORM\r\nPRINT\r\n");
2) IrDA Printing within HTML
The following example illustrates using the ZebraPrint ActiveX control to print to an IrDA printer via an HTML document:
ZebraPrint Infrared (IrDA) Sample
var zp = new ActiveXObject("ZebraPrint.ZebraPrintCtl");
zp.IrDAConnection();
This is a test of IrDA printing.
zp.Print("! 0 200 200 581 1\r\nLABEL\r\nCONTRAST 0\r\nTONE 0\r\nSPEED 3\r\nPAGE-WIDTH 240\r\nBAR-SENSE\r\nTEXT90 4 3 36 288 $22.88\r\nTEXT90 5 2 163 273 SWEATSHIRT\r\nVBARCODE UPCA 2 1 45 139 576 04364503284\r\nTEXT90 7 0 191 511 043645032841\r\nTEXT90 5 0 4 524 COMPARE AT\r\nTEXT90 4 0 30 508 $ 30.00\r\nTEXT90 5 0 115 575 ZD-180-KL\r\nTEXT90 5 2 119 269 ALL COTTON\r\nTEXT90 7 0 114 389 01/17/98\r\nTEXT90 0 0 208 173 EA00-732-00560\r\nTEXT90 5 0 82 519 ELSEWHERE\r\nBOX 189 358 217 527 1\r\nFORM\r\nPRINT\r\n");
3) Auto-detection / Installation of ActiveX control
Using JScript, it is possible to detect if the ZebraPrint ActiveX control is not currently installed. The following example illustrates recognizing this condition and also illustrates the possibility of automatically installing the control via a web URL.
ActiveX Sample
var zp = new ActiveXObject("ZebraCEPrint.ZebraCEPrintCtl");
if (zp == null)
document.write("Failed to load the ZebraPrint activeX control. Click here to install the ZebraPrint ActiveX control");
else
zp.Print("! 0 200 200 581 1\r\nLABEL\r\nCONTRAST 0\r\nTONE 0\r\nSPEED 3\r\nPAGE-WIDTH 240\r\nBAR-SENSE\r\nTEXT90 4 3 36 288 $22.88\r\nTEXT90 5 2 163 273 SWEATSHIRT\r\nVBARCODE UPCA 2 1 45 139 576 04364503284\r\nTEXT90 7 0 191 511 043645032841\r\nTEXT90 5 0 4 524 COMPARE AT\r\nTEXT90 4 0 30 508 $ 30.00\r\nTEXT90 5 0 115 575 ZD-180-KL\r\nTEXT90 5 2 119 269 ALL COTTON\r\nTEXT90 7 0 114 389 01/17/98\r\nTEXT90 0 0 208 173 EA00-732-00560\r\nTEXT90 5 0 82 519 ELSEWHERE\r\nBOX 189 358 217 527 1\r\nFORM\r\nPRINT\r\n");
4) Using the ActiveX control within Visual Basic
The ActiveX control can be used within Visual Basic as illustrated by the code below. However, if you would like to enable automatic syntax checking of the ZebraPrint methods within Visual Basic, you will first need to import a reference to the ActiveX object. This can be done as follows: Open you Visual Basic project and choose “Project->References…” on the main menu. Click on “Browse…” and locate the ZebraPrint.tlb file that was supplied with this document. If you are prompted with warning message, “The selected library is not marked as usable in your current platform. Would you like this library added?”, answer “YES”. The ZebraPrint library will then be added to your list of valid references. You can then view the ZebraPrint methods via the Object Browser.
Here is the actual VB code demonstrating the use of the ZebraPrint object:
Dim ZP As ZebraPrint.ZebraPrintCtl
Set ZP = CreateObject("ZebraPrint.ZebraPrintCtl")
Dim CRNL As String
CRNL = Chr(13) + Chr(10) ‘ Set a string equal to CR and LF
ZP.SerialConnection "COM1:", 19200
ZP.Print "! 0 200 200 581 1" + CRNL + "LABEL" + CRNL + "CONTRAST 0" + CRNL + "TONE 0" + CRNL + "SPEED 3" + CRNL + "PAGE-WIDTH 240" + CRNL + "BAR-SENSE" + CRNL + "TEXT90 4 3 36 288 $22.88" + CRNL + "TEXT90 5 2 163 273 SWEATSHIRT" + CRNL + "VBARCODE UPCA 2 1 45 139 576 04364503284" + CRNL + "TEXT90 7 0 191 511 043645032841" + CRNL + "TEXT90 5 0 4 524 COMPARE AT" + CRNL + "TEXT90 4 0 30 508 $ 30.00" + CRNL + "TEXT90 5 0 115 575 ZD-180-KL" + CRNL + "TEXT90 5 2 119 269 ALL COTTON" + CRNL + "TEXT90 7 0 114 389 01/17/98" + CRNL + "TEXT90 0 0 208 173 EA00-732-00560" + CRNL + "TEXT90 5 0 82 519 ELSEWHERE" + CRNL + "BOX 189 358 217 527 1" + CRNL + "FORM" + CRNL + "PRINT" + CRNL
5) Using the ActiveX control from Visual C++
Within your Visual C++ project, choose “View->Class Wizard…” to open Class Wizard. Click on “Add Class…” and choose “From a type library…”. Using the file browser, select the file ZebraPrint.tlb. You will then be prompt for the default file names to use for this new class. Accept the defaults of ZebraPrint.cpp and ZebraPrint.h. This will create a new class called IZebraPrintCtl within your project. This new class is derived from the class COleDispatchDriver. To actually make use of the class, follow the example provided below:
IZebraPrintCtl zp;
if (zp.CreateDispatch(_T("ZebraPrint.ZebraPrintCtl")))
{
zp.Version();
zp.SerialConnection(_T("COM1:"), 19200);
zp.Print(_T("! 0 200 200 581 1\r\nLABEL\r\nCONTRAST 0\r\nTONE 0\r\nSPEED 3\r\nPAGE-WIDTH 240\r\nBAR-SENSE\r\nTEXT90 4 3 36 288 $22.88\r\nTEXT90 5 2 163 273 SWEATSHIRT\r\nVBARCODE UPCA 2 1 45 139 576 04364503284\r\nTEXT90 7 0 191 511 043645032841\r\nTEXT90 5 0 4 524 COMPARE AT\r\nTEXT90 4 0 30 508 $ 30.00\r\nTEXT90 5 0 115 575 ZD-180-KL\r\nTEXT90 5 2 119 269 ALL COTTON\r\nTEXT90 7 0 114 389 01/17/98\r\nTEXT90 0 0 208 173 EA00-732-00560\r\nTEXT90 5 0 82 519 ELSEWHERE\r\nBOX 189 358 217 527 1\r\nFORM\r\nPRINT\r\n"));
}
6) Using the Send() / Recv() commands to query various printer attributes
Using the Send() / Recv() commands, it is possible to using the printer’s “GETVAR” utility command to query various attributes, such as battery voltage. Here is an example of doing this within JScript:
var zp = new ActiveXObject("ZebraPrint.ZebraPrintCtl");
zp.SerialConnection("COM8:", 19200);
zp.Open();
zp.Send("! U1 GETVAR \"power.voltage\"\r\n");
response = zp.Recv(1000); // wait up to 1 second (1000ms) for a response
if (response == "")
alert("Failed to receive a response.");
else
alert(response);
zp.Close();
7) Using the Magnetic Card Reader (MCR)
The ActiveX control can also be used to retrieve data from Zebra printers that are equipped with a Magnetic Card Reader. This involves first sending the appropriate MCR command to the printer and then using the ActiveX control’s Recv() function to retrieve the MCR data. For specifics on the MCR command syntax, please refer to the Zebra printer programming manual.
The following examples illustrate retrieving data from the MCR using JScript, Visual Basic, and Visual C++:
Jscript
ActiveX Sample
var zp = new ActiveXObject("ZebraPrint.ZebraPrintCtl");
zp.SerialConnection();
This is a test
if (zp == null)
document.write("Failed to load ZebraPrint activeX control. Please re-install the ZebraPrint ActiveX control");
else
{
var mcr_data;
zp.Version();
zp.Open();
zp.GetPrinterStatus(); // wait for the printer to be ready
alert("Scan a card after clicking ok and you see the amber LED begin to flash on the printer...");
zp.Send("! U1 MCR 80 T1 T2 ERRORS\r\n");
mcr_data = zp.Recv(10000);
zp.Close();
// Display the MCR data received
alert(mcr_data);
}
Visual Basic
Private Sub Form_OKClick()
Dim CRNL As String
CRNL = Chr(13) + Chr(10)
Dim ZP As ZebraPrint.ZebraPrintCtl
Set ZP = CreateObject("ZebraPrint.ZebraPrintCtl")
ZP.Version
ZP.SerialConnection "COM1:", 19200
ZP.Open
ZP.GetPrinterStatus
MsgBox "Please scan a magnetic card after clicking OK and you see the printer's amber light begin to blink."
ZP.Send "! U1 MCR 80 T1 T2 ERRORS" + CRNL
Dim mcr_data As String
mcr_data = ZP.Recv(10000)
ZP.Close
MsgBox mcr_data
End Sub
Visual C++
IZebraPrintCtl zp;
if (zp.CreateDispatch(_T("ZebraPrint.ZebraPrintCtl"))){
zp.Version();
zp.SerialConnection(_T("COM1:"), 19200);
if (zp.Open()){
if (zp.GetPrinterStatus() == 0xffff0000)
MessageBox(_T("Failed to connect to the printer."));
else {
CString szMCRData;
zp.Send(_T("! U1 MCR 80 T1 T2 ERRORS\r\n"));
szMCRData = zp.Recv(10000);
MessageBox(szMCRData);
}
}
}
Version History
2.1 6-2-2003
Added support for a baud rate of 115200 when using serial communications.
2. 6-2-2003
Corrected buffer copying in Recv() function so allow data to be received on non-unicode platforms.
1.8, 8-13-2002
Added SetFlowCtl to enable/disable serial port flow control.
1.7, 7-31-2002
Added examples illustrating using the MCR.
Corrected a buffer overflow problem if more than 99 bytes were received via a call to Recv()
1.6, 4-22-2002
Added Recv() command to get data back from printer.
1.5, 4-19-2002
Modified the serial i/o behavior to support a BlueTooth serial/modem connection in additional to regular serial (comm) printing.
1.4, 4-16-2002
Added SerialCloseWait() command to improve interaction with PRESENT-AT.
1.3, 4-1-2002
Added EnablePrintVerify() command to turn on automatic prompting of the user for reprints when the Print() command is used.
1.2, 3-29-2002
Altered the default behavior of the Print() command so it now waits 10 seconds for the printer to become available, rather than 5 seconds.
Added SetStatusQueryTimeout() command for altering the default timeout when waiting for the printer to become available.
1.1, 3-25-2002
Initial full release. Added TCP support and extra commands to allow modification of the default behavior of the Print() command.
1.0D beta, 3-20-2002
Initial test release. Supports serial and IrDA.
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- nevada cosmetology infection control course
- internal control for financial reporting
- infection control in outpatient setting
- control technology corporation
- control technology corp
- control technology inc
- control technology inc knoxville tn
- tool inventory control system
- small business inventory control systems
- psychological control tactics
- financial control system
- how to control financial management