-----------------------------
.NetCF: C#-VB.Net
Documentation eVC
(C/C++/MFC), eVB: ----------------------------- Software Developers Special Topics
Printing Utilities |
AsciiCE
for .NetCF
- Developer's Guide
|
PrinterCE for .NetCF: The primary class for printing text, images, drawing objects (lines, rectangles, etc) and much more. | |
AsciiCE for .NetCF: A separate class that allows for printing pure ASCII text to any ASCII printer. | |
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;
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);
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 |
AsciiCE throws an exception for any error found. |
Example:
AsciiCE asc1 = new
AsciiCE(AsciiCE.EXCEPTION_LEVEL.ABORT_JOB);
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.
READ-ONLY property returns string describing this version of PrinterCE.NetCF (which includes AsciiCE).This is identical to PrinterCE's About method here.
Method:
Sends single character (8-bit value) to the printer.
Syntax: void Char(char ch);
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();
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();
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();
READ-ONLY Property - Returns an integer value representing the version of PrinterCE/AsciiCE... This is identical to PrinterCE's GetVersion here.
Syntax: int bytestoread = AsciiCE1.Peek();
Method: Returns number of data bytes that have been received from the printer. See Read() and ReadChar().
Method: Controls action of the "Printing in
progress" dialog box (which allows the user to cancel the print
operation).
Method:
Allows changing the text displayed or language
used by the "Printing in progress" dialog box.
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);
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);
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 |
Byte array - length of array can be determined using Length array member.
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);
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())
Method:
Sends one or more copies of a character byte value to the printer.
Syntax: void RepeatChar(char ch,int repeatcnt);
ch - character to be sent to printer (8-bit value)
repeatcnt - count of number of copies of "ch" to send to
printer.
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.
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 | |
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 |
|
|
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:
Method: Sets error level of errors returned
by AsciiCE.
This READ-ONLY property returns the current status of
AsciiCE.
Method: Send text string to printer
Syntax: void Text(string TextString)
Method:
Send
block (byte array) of data to printer..
Syntax:
int
Write(byte [] buffer);
int Write(byte
[] buffer,int NumberOfBytesToWrite);
buffer
- Byte array of
data to be 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.
NumberBytesToWrite - count of bytes to send from "buffer"
Returns: Count of bytes successfully sent to printer