LinePrinter Tutorial > Part 1 of 6

Part 1: Create the project in Visual Studio .NET

  1. In VS 2008, select File > New > Project.
  2. In the New Project dialog box, select Visual C# and select Smart Device.
  3. From the Visual Studio installed templates list, select Smart Device Project, and then click OK.
  4. In the Add New Smart Device Project dialog box:
  1. In the Target Platform list, select Windows Mobile 6 Professional SDK.
  2. In the .NET Compact Framework Version list, select .NET Compact Framework Version 3.5.
  3. In the Templates list, select Console Application.
  1. Click OK. The project is created.
  2. In the Solution Explorer list, right-click References and select Add Reference.
  3. In the Add Reference list, select Honeywell.Mobility.Print.LinePrinter and click OK.
  4. Copy LinePrtDLL.dll to the project directory on the computer. Versions of this .dll are in the Runtime directory of the Printing Resource Kit installation on your PC. Be sure to copy the .dll from the folder for your computer.
  5. Copy ITC_CONFIG.XML to the project directory on the computer.  A copy may be found in Printing Resource Kit\Examples\C#\example3_CF2.0.
  6. Add the code in red below to the project. For brevity, comments are not included in the following code.
using System;
using System.Data;
using Honeywell.Mobility.Print;

namespace SmartDeviceProject1
{
    class Class1
    {    
       static LinePrinter lp = null;
        static void Main(string[] args)
        {
            lp = new LinePrinter("ITC_CONFIG.XML","PR2Bt_40COL");
            lp.Open();
            lp.Write("Hello World");
            lp.NewLine();
            lp.Close();
        }
    }
}

The line using Honeywell.Mobility.Print gives access to the LinePrinter class.

LinePrinter lp = null declares a variable as a line printer object.

lp = new LinePrinter (... creates and initializes the LinePrinter and takes two string arguments: the name of and path to the printer configuration file, and a printer reference within the configuration file that is the target of the printing.

To use a different printer than the PR2, modify the LinePrinter constructor call to list the correct printer from the configuration file in the second parameter ("PR2Bt_40COL" in the example).

lp.Open() opens the communications link between the two devices.

lp.Write("Hello World") sends a string to the print buffer. Because of LinePrinter and hardware buffering, printing will not start until the application calls a NewLine method.

lp.NewLine() transfers the text follwed by a line feed code to the printer. After this line the printer should start printing the string.

lp.Close() closes the connection to the printer and releases handles. For NPCP printing, Close will not return until all pending text has been printed. For other printing methods, Close will return within a couple of seconds of being called.  The printer may still continue to print for up to a couple minutes until its buffer is empty.

Next » Tutorial Part 2

Back » LinePrinter Tutorial