FieldSoftware
Home

-----------------------------

.NetCF: C#-VB.Net
 Software Developers


PrinterCE.NetCF SDK
   General Info
   Download & Install
   Purchase & Pricing
   Upgrade from PrinterCE

Getting Started with:
 
C#   -   VB.Net

  Code Examples

Documentation
  PrinterCE for .Net CF
  AsciiCE for .Net CF
  BarcodeCE for .Net CF

eVC (C/C++/MFC), eVB:
  PrinterCE SDK

-----------------------------

Software Developers
  PrinterCE SDK
  PrinterCE.NetCF SDK
  PocketHTMLprint SDK

Special Topics
  Supported Printers
  Bluetooth Printing
  Network Printing

Printing Utilities
  PrintPocketCE
  PIEprint
  PocketPixPrint
  PocketShot
 
PocketClipPrint

Arcade Games
  SockOut
  MazeCraze

Contact Info

AsciiCE for .NetCF - Developer's Guide
Namespace : FieldSoftware.PrinterCE_NetCF
DLLs : PrinterCE_NetCF.dll, PrCE_NetCF.dll
Class Name: AsciiCE

The AsciiCE for .NetCF class is included with PrinterCE.NetCF SDK and provides for sending and receiving ASCII text strings and blocks of data or control functions between printers and Windows CE / Pocket PC devices. When used with certain printers that also feature magnetic card readers or smart card readers, AsciiCE provides methods to read the data from those readers.

AsciiCE provides basic high-speed text output to ASCII printers, direct printer control and reading data sent from the printer, but loses the sophisticated graphics, TrueType font, object drawing and barcode printing capabilities of PrinterCE. AsciiCE and PrinterCE can be used simultaneously to a limited degree.

The PrinterCE.NetCF module contains the following print classes:

bullet PrinterCE for .NetCF: The primary class for printing text, images, drawing objects (lines, rectangles, etc) and much more.
bullet AsciiCE for .NetCF: A separate class that allows for printing pure ASCII text to any ASCII printer.
bullet BarcodeCE for .NetCF: An optional class derived from PrinterCE that adds over a dozen barcode types to PrinterCE.


Simple C# code for
using the AsciiCE class to print out "Hello World":

AsciiCE asciice = null;
try
{
 
//No License Key for evaluation
 
asciice = new AsciiCE("YOURLICENSEKEY"); 
//Create instance of AsciiCE class
 
asciice.SelectPort(AsciiCE.ASCIIPORT.INFRARED);   //Print with Infrared port
  asciice.Text("Hello World");                     
//Print Hello World
  asciice.CrLf();                                  
//Move to next line
  asciice.ClosePort();                              //Finish printing and close printing port
}
catch (PrinterCEException exc)
{
  if (asciice!=null)
  {
   
asciice.ShutDown(); //Done - free PrinterCE resources
   
asciice=null;
  }
  MessageBox.Show("AsciiCE Exception","Exception");
}
finally  //Make sure we call ShutDown()
{
  if (asciice!=null)
  {
   
asciice.ShutDown(); //Done - free PrinterCE resources
   
asciice=null;
  }
}

   

AsciiCE for NetCF Constructors

Create an instance of AsciiCE using one of the following 4 overloaded versions:

Syntax: (4 overloaded versions):
  public AsciiCE();
  public
AsciiCE(string initstr);

  public
AsciiCE(EXCEPTION_LEVEL exclevel);
  public
AsciiCE(EXCEPTION_LEVEL exclevel,string initstr);

Parameters

string - Developer's License Key used to unlock AsciiCE. Default is for AsciiCE to run in evaluation mode. After evaluation time limit has expired on a device, AsciiCE will be locked and will not function.
EXCEPTION_LEVEL -
Sets level of errors that will cause an exception, using EXCEPTION_LEVEL enumeration:

EXCEPTION_LEVEL Enumeration

Description

NONE

AsciiCE will not throw an exception - use StatusCheck to determine if an error has occurred.

ABORT_JOB

AsciiCE throws an exception if the print job is aborted, either by serious error or user cancel.

ALL  (default)

AsciiCE throws an exception for any error found.

Example:
AsciiCE asc1 = new AsciiCE(AsciiCE.EXCEPTION_LEVEL.ABORT_JOB);

Remarks

When an error occurs within AsciiCE, the severity of the error is determined and AsciiCE "remembers" this as appropriate.For example, if a printer error occurs, the entire printing job must be aborted, so all calls to AsciiCEwill remember that it is aborting and this will be handled gracefully.

This design allows the app that uses PrinterCE to have a relaxed approach to error handling, even to the point of ignoring errors completely (although it would be kind to the user to do StatusCheck calls and display error dialog boxes as needed). Alternatively, errors can be handled by Exceptions using the appropriate EXCEPTION_LEVEL value.

 

AsciiCE for NetCF Methods & Properties

About

READ-ONLY property returns string describing this version of PrinterCE.NetCF (which includes AsciiCE).This is identical to PrinterCE's About method here.

Char

Method: Sends single character (8-bit value) to the printer.  

Syntax: void Char(char ch);

ClosePort

Method: Closes printer connection used by AsciiCE. This should be called at the end of each AsciiCE print job. See ShutDown() method for freeing all AsciiCE resources.

Syntax: void ClosePort();

CrLf

Method: Sends CR (carriage return Ascii 13) and LF (linefeed Ascii 10) commands to the printer. Some Ascii printers are set up to automatically insert a LF with any CR... in this case, just use Char() operation to send a LF command (ie. Ascii.Char(13))  

Syntax: void CrLf();

FormFeed

Method: Sends a FF (formfeed Ascii 12) to the printer to print everything sent for this page and eject the page. If FormFeed is not called at the end of a print job, the printed page will often be left half printed in the printer.  

Syntax: void FormFeed();

GetVersion

READ-ONLY Property - Returns an integer value representing the version of PrinterCE/AsciiCE... This is identical to PrinterCE's GetVersion here.

Peek

Syntax: int bytestoread = AsciiCE1.Peek();

Method: Returns number of data bytes that have been received from the printer. See Read() and ReadChar().

PrDialogBox

Method: Controls action of the "Printing in progress" dialog box (which allows the user to cancel the print operation). This is identical to PrinterCE's PrDialogBox here.

PrDialogBoxText

Method: Allows changing the text displayed or language used by the "Printing in progress" dialog box. This is identical to PrinterCE's PrDialogBoxText here.

ReadChar

Reads a single character from the printer port into "newch" - returns true if successful. See SelectPort() to enable data reading. See also Read().

Syntax: bool success = AsciiCE1.ReadChar(ref char newch);

Read

Reads a block of data from the printer port into a byte array. This can be useful for special-purpose printers, such as combination printer & magnetic card reader or smart card reader devices (see here for printer selections). See SelectPort() to enable data reading. See ReadString() for easier way to read a text string from printer.

Note: Generally, the application will use AsciiCE2's Write, Text methods to send commands to the printer that enables the data-gathering portion of that device to collect and send the data to be read. 

Syntax: (2 overloaded versions):
byte [] Read(int MaxBytes,bool NormalRead,int nTimeToWait,
   ref
READ_RESULT result);
byte [] Read(int MaxBytes,byte LastByte,bool NormalRead,
   int
nTimeToWait,ref READ_RESULT result);

Parameters

MaxBytes - Maximum number of bytes to read.
LastByte - Read data stream until this byte value is found, then return all data read. Defaults to read until max number of bytes are read.
NormalRead - true to read all data. If false, the read ignores zero value bytes - all other data is read into buffer
TimeToWait - Maximum number of microseconds to wait for data from the printer. If 0, don't time out.
ResultFlags - Results of read from READ_RESULT enumeration:

READ_RESULT Enumeration  Description
ERROR  Error trying to read (such as loss of infrared connection)
SUCCESS  Read was successful
FULLBUFFER  Returning because "MaxBytes" bytes were read
TIMEOUT  Returning because "TimeToWait" microseconds expired
USERCANCEL  User cancelled

Returns:

Byte array - length of array can be determined using Length array member.

ReadString

Similar to Read() but returns a string of text from the printer port rather than byte array.

Syntax: (2 overloaded versions):
string ReadString(int MaxBytes,bool NormalRead,int nTimeToWait,
   ref
READ_RESULT result);
string ReadString(int MaxBytes,char LastChar,bool NormalRead,
   int
nTimeToWait,ref READ_RESULT result);

Parameters

MaxBytes - Maximum number of bytes to read.
LastChar - Read data stream until this char value (8-bit) is found, then return all data read. Defaults to read until max number of bytes are read.
NormalRead - true to read all data. If false, the read ignores zero value bytes - all other data is read into buffer
TimeToWait - Maximum number of microseconds to wait for data from the printer. If 0, don't time out.
ResultFlags - Results of read from READ_RESULT enumeration (see Read())

RepeatChar

Method: Sends one or more copies of a character byte value to the printer.  

Syntax: void RepeatChar(char ch,int repeatcnt);

Parameters

ch - character to be sent to printer (8-bit value)
repeatcnt - count of number of copies of "ch" to send to printer.

SelectPort

Method: Used to open "port" - communication link to printer. Returns true if successful.

Syntax: (4 overloaded versions): 
bool SelectPort(ASCIIPORT Port);
bool SelectPort(ASCIIPORT Port,int ReadBufferSize);
bool
SelectPort(ASCIIPORT Port,PORT_SPEED BaudRate,
  SERIAL_HANDSHAKE Handshake);
bool SelectPort(ASCIIPORT Port,PORT_SPEED BaudRate,
  SERIAL_HANDSHAKE Handshake,int ReadBufferSize);

 

This method extends the SelectPort() method in two ways: it allows the creation of a "read" operation to permit reading data from the printer port. It also offers one additional "port type" - PRINTERCE_SHARE- to allow shared use of the printer port by PrinterCE and AsciiCE2 -> with cautions and alerts sounded!! See AsciiCE discussion here.

Parameters

Port - Port type: 

ASCIIPORT Enumeration

Description

INFRARED

Infrared port

COMPAQ_BT

HP/Compaq Bluetooth iPAQ or sleeve

IPAQ_BT

HP/Compaq Bluetooth iPAQ or sleeve

SOCKETCOM_BT

Socket Bluetooth card support

WIDCOMM_BT Device using WIDCOMM Bluetooth stack

COM1

Com1: serial port

COM2

Com2: serial port

COM3

Com3: serial port

COM4

Com4: serial port

COM5

Com5: serial port

COM6

Com6: serial port

COM7

Com7: serial port

COM8

Com8: serial port

COM9 Com9: serial port
COM0 Com0: serial port

TOFILE

Print to file "\OUTPUT.PRN"

LPT

LPT: parallel port

BTQUIKPRINT

Special for HP iPAQ, WIDCOMM Bluetooth devices that pop up "Bluetooth Browser" to find/select BT printer at print time: using this flag bypasses the BT browser and uses most recent selected BT printer. To let user discover and select BT printer, use COMPAQ_BT, IPAQ_BT, WIDCOMM_BT

PRINTERCE_SHARE

Share PrinterCE port with AsciiCE. PrinterCE must already be connected to the printer by a successful call to PrinterCE's SelectPrinter() or SetupPrinter(). BaudRate and Handshake values are ignored and the PrinterCE values are used. See "Intermixing PrinterCE and AsciiCE2" for more info.

BaudRate Only impacts COM connections : 

PORT_SPEED Enumeration

DONT_CARE

S_4800

S_9600

S_19200

S_38400

S_57600

S_115200

Handshake Only impacts COM connections: 

SERIAL_HANDSHAKE Enumeration

Description

DONT_CARE

Don't change handshake mode

SOFTWARE

Use Xon/Xoff

HARDWARE

 

NO_HANDSHAKE

 

ReadBufferSize An integer value for number of bytes to be set aside for "read" buffer that AsciiCE will use to read and store data read in from the printer port. If ReadBufferSize is zero or omitted, then no read-buffer is established and no reading will occur. Otherwise, AsciiCE creates a separate read thread and buffer to store data read in from the printer port. See Read and Peek methods for more info.

SetReportLevel

Method: Sets error level of errors returned by AsciiCE. This is identical to PrinterCE's SetReportLevel method here.

StatusCheck

This READ-ONLY property returns the current status of AsciiCE. This is identical to PrinterCE's StatusCheck method here.

Text

Method: Send text string to printer

Syntax: void Text(string TextString)

Write

Method: Send block (byte array) of data to printer..  

Syntax: 
int Write(byte [] buffer);
int Write(byte [] buffer,int NumberOfBytesToWrite);

Parameters

buffer - Byte array of data to be sent to printer
NumberBytesToWrite - count of bytes to send from "buffer"
. Defaults to length of buffer array.

Returns: Count of bytes successfully sent to printer  

NOTE: If using both PrinterCE and AsciiCE (SelectPort -> PRINTERCE_SHARE mode) simultaneously, any calls to AsciiCE's Write or Text result in flushing all PrinterCE printing operations before processing the AsciiCE command. If the call to Write is strictly a printer control command, you can pass NumberBytesToWrite as a negative value (for example, NumberBytesToWrite = -22 if sending a 22 byte printer control block). A negative value for NumberBytesToWrite is passed immediately without causing PrinterCE operations to be printed first. See "Intermixing PrinterCE and AsciiCE" for more info.