25
Getting Started with ZMotif Card Printer Development ZMotif SDK+ C# Contents Overview................................................................................................................................................................................ 2 Target Audience .................................................................................................................................................................... 2 Feedback ............................................................................................................................................................................... 2 Prerequisites ......................................................................................................................................................................... 2 Installing the ZMotif™ SDK+ ................................................................................................................................................. 3 Creating an Application using the ZMotif™ SDK+ ................................................................................................................ 5 Launch Microsoft Visual Studio 2008. ........................................................................................................................... 5 Create a C# Windows Form project. ............................................................................................................................. 5 Design the Form Layout .............................................................................................................................................. 10 Add the Code ............................................................................................................................................................... 19 Running the Application............................................................................................................................................... 22 Deploying the Application ............................................................................................................................................ 24

ZMotifSDK CSharp GettingStarted WH

Embed Size (px)

DESCRIPTION

guia Impresora Zebra

Citation preview

Page 1: ZMotifSDK CSharp GettingStarted WH

Getting Started with ZMotif Card Printer Development – ZMotif SDK+ – C#

Contents

Overview ................................................................................................................................................................................ 2

Target Audience .................................................................................................................................................................... 2

Feedback ............................................................................................................................................................................... 2

Prerequisites ......................................................................................................................................................................... 2

Installing the ZMotif™ SDK+ ................................................................................................................................................. 3

Creating an Application using the ZMotif™ SDK+ ................................................................................................................ 5

Launch Microsoft Visual Studio 2008. ........................................................................................................................... 5

Create a C# Windows Form project. ............................................................................................................................. 5

Design the Form Layout .............................................................................................................................................. 10

Add the Code ............................................................................................................................................................... 19

Running the Application ............................................................................................................................................... 22

Deploying the Application ............................................................................................................................................ 24

Page 2: ZMotifSDK CSharp GettingStarted WH

Overview This document describes the end to end process of designing, packaging, deploying and running a C# application using the Zebra ZMotif™ SDK+. The sample code used in this guide is from the “Getting started with ZMotif Card Printer Development supporting sample code” (SA249) available here on the Zebra Support Portal.

Target Audience The information delivered in this document assumes the reader has reasonable technical competence covering Microsoft Visual Studio, core programming concepts and rationales.

Feedback We value all feedback. Please add your comments/suggestions to the article in the Zebra Support Portal.

Prerequisites The following items are required to create the ZMotif™ SDK+ application: ZMotif™ SDK+ The following components are required and included in the ZMotif™ SDK+ package: ZMotif Printer SDK, ZMotif Graphics SDK, and ZGT (Zebra General Tool). To download ZMotif™ SDK+, navigate to the following site: http://www.zebra.com/cardpartner/zmotif.php. Click the “Click here for the EULA” link located at the top right section of the page. The “Installing the ZMotif™ SDK+” section of this document contains instructions on how to install the SDKs. ZXP Series 8 Printer In order to run the ZMotif™ SDK+ application created in this document, a Zebra ZXP Series 8™ retransfer printer must be accessible from the computer.

Page 3: ZMotifSDK CSharp GettingStarted WH

Installing the ZMotif™ SDK+ The ZMotif™ SDK+ must be installed to your system before the sample application can be developed. The following steps explain how to install the ZMotif™ SDK+.

1. Install the ZMotifPrinterSDK. a. Navigate to the ZMotifPrinterSDK’s directory (ZMotifPrinterSDK_<version>) within the ZMotif™ SDK+’s

installation package.

b. Launch setup.exe located in the ZMotifPrinterSDK’s directory.

c. Complete the ZMotifPrinterSDK installation by advancing through the installation wizard using the installer’s defaults.

Page 4: ZMotifSDK CSharp GettingStarted WH

2. Install the ZMotifGrahpicsSDK. a. Navigate to the ZMotifGraphicsSDK’s directory (ZMotifGraphicsSDK_<version>) within the ZMotif™

SDK+’s installation package.

b. Launch setup.exe located in the ZMotifGraphicsSDK’s directory.

c. Complete the ZMotifGraphicsSDK installation by advancing through the installation wizard using the installer’s defaults.

Page 5: ZMotifSDK CSharp GettingStarted WH

Creating an Application using the ZMotif™ SDK+ The following steps will guide you through the creation of an application that will utilize the ZMotif™ SDK+. The application will feed in a PVC card from the Input Hopper, print text and graphics to the card, than send the card to the Output Hopper.

1. Launch Microsoft Visual Studio 2008. Go to Start -> All Programs -> Microsoft Visual Studio 2008 -> Microsoft Visual Studio 2008.

2. Create a C# Windows Form project.

a. Click on File -> New -> Project.

Page 6: ZMotifSDK CSharp GettingStarted WH

b. You will be prompted with a New Project window. In “Project types” pane, expand Visual C# and select

Windows Forms Application.

c. Enter “ZMotifGettingStarted” in the Name text field and chose a location for your project. Click OK.

Page 7: ZMotifSDK CSharp GettingStarted WH

d. Your project will automatically open in the IDE. The Form Designer is opened by default.

Page 8: ZMotifSDK CSharp GettingStarted WH

e. The ZMotif™ SDK+ only works with 32-bit applications. If you are running on a 64-bit system you must

change the project’s built type to x86.

i. Right-click the ZMotifGettingStarted project in the Solution Explorer and select Properties.

Page 9: ZMotifSDK CSharp GettingStarted WH

ii. The ZMotifGettingStarted project’s properties window will be displayed. Select Build on the left.

iii. Set the Platform target to x86 and Save. Close the properties window to return to the Form

Designer.

Page 10: ZMotifSDK CSharp GettingStarted WH

3. Design the Form Layout

a. Rename the form in the Solution Explorer by right-clicking Form1.cs and selecting Rename.

i. Enter “frmMain.cs” and hit Enter. ii. Click Yes when prompted to rename all references of “Form1”.

Page 11: ZMotifSDK CSharp GettingStarted WH

b. Right-click anywhere on the form in the Form Designer and select Properties. This will bring up the Properties table in the bottom right panel.

Page 12: ZMotifSDK CSharp GettingStarted WH

c. Replace “Form1” with “ZMotif Application” for the value of the Text property. This changes the text on the

title bar of the form.

Page 13: ZMotifSDK CSharp GettingStarted WH

d. For the value of the Size property, replace “300, 300” with “350, 300”.

e. In the Properties window, select the lightning bolt icon to show the Form’s events. Set the Load event to “frmMain_Load”.

Page 14: ZMotifSDK CSharp GettingStarted WH

f. We will use a combo box for selecting a printer.

i. Expand the Toolbox on the left. ii. Expand Common Controls and drag a ComboBox into the top left portion of the form.

iii. Right-click the combo box and select Properties. iv. Set the value of the “(Name)” property to “cboPrinterSelection”.

Page 15: ZMotifSDK CSharp GettingStarted WH

g. We will use a text box to enter text that will appear on the card. i. Drag a TextBox from the Toolbox and place it directly under the combo box on the form.

ii. Right-click the TextBox and select Properties. Set the value of its “(Name)” property to “txtCardTextFront”.

Page 16: ZMotifSDK CSharp GettingStarted WH

h. Now we will add Labels to the ComboBox and TextBox. i. Drag a Label from the Toolbox and place it to the right of the ComboBox.

ii. Right-click the label and select Properties. Set the value of the Text property to “Printer:”.

iii. Drag another Label from the Toolbox and place it to the right of the TextBox.

iv. Right-click the label and select Properties. Set the value of the Text property to “Card Text:”.

Page 17: ZMotifSDK CSharp GettingStarted WH

i. We will use another label to output the status messages. i. Drag another Label from the Toolbox and place it directly under the Card Text Label.

ii. Right-click the label and select Properties. Clear the value of the Text property so that is blank.

iii. Set the value of the “(Name)” property to “lblPrintStatus”.

Page 18: ZMotifSDK CSharp GettingStarted WH

j. The last control we need is a Button to print the card.

i. Drag a Button from the Toolbox and place it in the bottom right portion of the form.

ii. Right-click the Button and select Properties.

iii. Change the value of the Text property to “Print”.

iv. Change the value of the “(Name)” property to “btnPrint”.

v. Click the lightning bolt icon to show the Button’s events.

vi. Set the Button’s click event to “btnPrint_Click”.

Page 19: ZMotifSDK CSharp GettingStarted WH

4. Add the Code

a. Before we write any code, we need to include References to the ZMotif™ SDK+’s assemblies.

i. First, we will add a reference to ZMotifGraphics.dll. In the Solution Explorer, right-click “References” and select “Add Reference…”.

ii. Select the “Browse” tab and navigate to the location where the ZMotifGraphicsSDK was installed. (The default is “C:\Program Files\Zebra Technologies\ZMotifGraphicsSDK\bin”)

iii. In the “bin” directory, select “ZMotifGrahpics.dll” and click OK.

Page 20: ZMotifSDK CSharp GettingStarted WH

iv. Now we will add a reference to ZMotifPrinter.dll. Once again, right-click “References” and select “Add Reference…”.

v. Select the “Browse” tab and navigate to the location where the ZMotifPrinterSDK was installed. (The default is “C:\Program Files\Zebra Technologies\ZMotifPrinterSDK\<version>\bin”)

vi. In the “<version>\bin” directory, select “ZMotifPrinter.dll” and click OK.

vii. Lastly, we will add a reference to Neodynamic.SDK.Barcode.dll. This DLL is required by the

ZMotif™ SDK+’s assemblies.

viii. In the Solution Explorer, right-click “References” and select “Add Reference…”.

ix. Select the “Browse” tab and navigate to the location where the ZGT (Zebra General Tool) was installed. (The default is “C:\Program Files\Zebra Technologies\ZGT”)

x. Select “Neodynamic.SDK.Barcode.dll” and click OK.

xi. There should now be three new assemblies (ZMotifGraphics, ZMOTIFPRINTERLib,

Neodynamic.SDK.Barcode) under References in the Solution Explorer.

Page 21: ZMotifSDK CSharp GettingStarted WH

b. Now we will begin adding the code. Right-click anywhere in the Form Designer and select View Code. This will open frmMain.cs.

c. Replace the existing code in frmMain.cs with the “frmMain.cs” from the “Getting Started with ZMotif Printer Development supporting sample code”. This code has a few main functions: Note: The source code in this whitepaper is extracted from the "Getting started with ZMotif Card Printer Development support sample code" SA249 which is available for download to all registered members of the Zebra ISV Program here. For information on joining the ISV Program, contact a Program Manager in your area. Details here.

i. Populates the printer selection combo box with available printers.

ii. Connects to the printer before printing and disconnects from the printer after printing.

iii. Draws shapes and text to the graphics buffer and begins printing when the Print button is clicked.

Page 22: ZMotifSDK CSharp GettingStarted WH

5. Running the Application

a. Start the application by pressing F5.

b. Select your ZMotif device from the printer selection combo box.

c. Enter “Hello World!” into the Card Text text field.

Page 23: ZMotifSDK CSharp GettingStarted WH

d. Click the Print button. When the print begins, you will see the message “Printing Card”.

e. The resulting card should have shapes and text printed on the front and back, as shown below.

Front:

Back:

Page 24: ZMotifSDK CSharp GettingStarted WH

6. Deploying the Application

a. Set the project’s build mode to Release by choosing Release from the dropdown near the top.

b. If you are running on a 64-bit system, you must once again change the build type to x86, as this set separately for Debug and Release build modes.

i. You may refer back to section 2 step e if you do not remember how to do this. ii. Be sure your build mode is set to Release before changing the build type.

c. Select Build -> Build Solution from the top menu.

d. Open Windows Explorer and navigate to your ZMotifGettingStarted Visual Studio project. Your application is located at “~\ZMotifGettingStarted \bin\Release\ZMotifGettingStarted.exe”.

e. If a custom ZMotif device application will be run on machines that do not have the ZMotif™ SDK+

installed, it needs access to any ZMotif assemblies that it uses in its code. The ZMotifGettingStarted uses “ZMotifGraphics.dll” (ZMotifGraphicsSDK) and “Interop.ZMOTIFPRINTERLib.dll” (ZMotifPrinterSDK).

Page 25: ZMotifSDK CSharp GettingStarted WH

*Specifications subject to change without notice. ©2009 ZIH Corp. EPL, APL, ZBI 2.0, ZBI-Developer, Element Energy Equalizer, E 3, ZebraLink, EPL2, ZebraNet, and all product names and numbers are Zebra trademarks, and Zebra, the Zebra head graphic stripe, ZPL, ZebraNet, and ZPL II are registered trademarks of ZIH Corp. All rights reserved. Unicode is a trademark of Unicode, Inc. CG Triumvirate is a trademark of Agfa Division, Miles In c. IBM is a registered trademark of International Business Machines Corporation. UFST is a trademark of Monotype Imaging Inc. a nd may be registered in certain jurisdictions. All other trademarks are the property of their respective owners.

Corporate Headquarters Asia-Pacific Headquarters EMEA Headquarters Latin America Headquarters +1 800 423 0442 +65 6858 0722 +44 (0)1628 556000 +1 847 955 2283 E-mail: [email protected] E-mail: [email protected] E-mail: [email protected] E-mail: [email protected] Other Locations USA: California, Georgia, Rhode Island, Texas, Wisconsin Europe: France, Germany, Italy, Netherlands, Poland, Spain, Sweden Asia Pacific: Australia, China, Japan, South Korea Latin America: Argentina, Brazil, Florida (USA), Mexico Africa/Middle East: India, Russia, South Africa, United Arab Emirates GSA#: GS-35F-0268N

13919L-001 Rev. 9 (11/08)

Document Control

Version Date Description

1.0 14-Dec-10 Initial Release

All links and information correct at time of writing Created for the Zebra Global ISV Program by Zebra Development Services