PrinterCE
SDK Special Topics
.Net CF C# or VB.Net: Printing Utilities |
AsciiCE2 Developer's
Guide
|
Constant |
Setting |
Description |
CAPS_STD |
01h |
PrinterCE
Standard capabilities |
CAPS_PLUS |
02h |
PrinterCE SDK |
CAPS_ASCII |
04h |
AsciiCE |
CAPS_BARCODE |
08h |
BarcodeCE |
This
method sends single character byte value to the printer.
MFC Syntax:
AsciiCE2a.Char(long
ch);
C++ Syntax:
AsciiCE2a.Char(long ch);
eVB
Syntax:
AsciiCE2a.Char ch
ch - character to be sent to printer
Closes
printer connection used by AsciiCE. This should be called at the end of
each Ascii print job.
MFC Syntax:
AsciiCE2a.ClosePort();
C++ Syntax:
AsciiCE2a.ClosePort();
eVB
Syntax:
AsciiCE2a.ClosePort
This
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))
MFC Syntax:
AsciiCE2a.CrLf();
C++ Syntax:
AsciiCE2a.CrLf();
eVB
Syntax:
AsciiCE2a.CrLf
This
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.
MFC Syntax:
AsciiCE2a.FormFeed();
C++ Syntax:
AsciiCE2a.FormFeed();
eVB
Syntax:
AsciiCE2a.FormFeed
READ-ONLY Property - Returns an integer value representing
the version of the control
MFC Syntax:
long value =AsciiCE2a.GetGetVersion();
C++ Syntax:
AsciiCE2a.get_GetVersion(long * value);
eVB
Syntax: value = AsciiCE2a.GetVersion
value - Integer representation of version = (Major * 1000) +
Minor.
Example: version 1700 would return value of 1700.
This method registers AsciiCE with the application's RegID
string to verify that the app is licensed to use the printer
functions.This is identical to PrinterCE's Init() method. Once either Init
method has been invoked by either PrinterCE or AsciiCE it is not necessary
to call either one again during this use of the control.
MFC Syntax:
long retval=AsciiCE2a.Init(
C++ Syntax:
AsciiCE2a.Init(BSTR
regidstring,long* retval);
eVB
Syntax:
AsciiCE2a.Init
regidstring
regidstring - the 10 digit registration id provided when the
PrinterCE/AsciiCE license is purchased. This will identify which version
of PrinterCE is licensed and permit all licensed functions to work.
retval - a boolean return value - True if registration was
successful, false otherwise.
If Init() is not called or is not successful, then the
registry is queried to see if the user has registered a single-use
license. If not, then an "evaluation" version (30-day time
limit) allows the user to continue printing.
Returns number of data bytes currently available for reading from the printer port.
MFC Syntax:
long retval=AsciiCE2a.GetPeek();
C++ Syntax:
AsciiCE2a.get_Peek(long*
retval);
eVB Syntax: retval=AsciiCE2a.Peek
retval - number of data bytes available.
This method controls action of the "Printing in
progress" dialog box (which allows the user to cancel the print
operation).
MFC Syntax:
long retval=AsciiCE2a.PrDialogBox(long operation);
C++ Syntax:
AsciiCE2a. PrDialogBox(long
operation,long* retval);
eVB
Syntax: retval=AsciiCE2a. PrDialogBox operation
operation One of the following values:
Constant |
Setting |
Description |
vbDlgBoxDebugOn |
-1 |
Uses "in progress" dialog box to show details
about internal mode of PrinterCE during printing. |
vbDlgBoxDebugOff |
-2 |
Turns off Debug mode. |
vbDlgBoxUp |
0 |
Display "in progress" dialog box |
vbDlgBoxDown |
1 |
Take down dialog box |
vbDlgBoxDisable |
2 |
Prevent dialog box from being used |
vbDlgBoxStatus |
3 |
Get status of printing operation |
vbDlgBoxUserCancel |
4 |
Return True if user cancelled printing operation |
vbDlgBoxAbortError |
5 |
Return True if an error aborted printing operation |
retval - Current status of operation (see table above). If
not user cancel or AbortError, then returns current status of printer
dialog box (vbDlgUp, etc).
By default, the "Printing in progress" dialog box
is displayed with the first call by an application to most PrinterCE or
AsciiCE2 operation
(such as SelectPort). This dialog box will remain
until ClosePort completes the printing job. Calling
PrDialogBox(vbDlgDisable) will prevent AsciiCE2 from displaying
the dialog box (and will not give the user any chance to cancel).
See PrDialogBoxText() for info on changing the text displayed
or language used by this dialog.
This method allows changing the text displayed or language
used by the "Printing in progress" dialog box.
MFC Syntax:
AsciiCE2a.PrDialogBoxText(
C++ Syntax:
AsciiCE2a. PrDialogBoxText(BSTR MainStr,BSTR TitleStr,BSTR
CancelBtnStr);
eVB
Syntax: AsciiCE2a. PrDialogBoxText MainStr,TitleStr,CancelBtnStr
MainStr - String for main text portion of the "Printing
in progress" dialog box.
TitleStr - String for title portion of the "Printing in
progress" dialog box.
CancelBtnStr - String for Cancel Button portion of the "Printing in
progress" dialog box
The text of this dialog box may be changed at any time
if
the dialog box is already displayed, it will be taken down, the new text
added, and then the dialog box will be redisplayed. If the dialog box is
not currently displayed, it will remain down until a call to PrDialogBox()
or until the AsciiCE2 automatically displays it.
Reads a single character from the printer port. If no data is available, then returns -1.
MFC Syntax: short bval=AsciiCE2a.ReadChar();
C++ Syntax: AsciiCE2a.ReadChar(short*
bval);
eVB
Syntax:
bval=AsciiCE2a.ReadChar
bval - Data byte read. If no data available, returns -1.
Reads a block of data from the printer port. This can be useful for special-purpose printers, such as combination printer & magnetic card reader or smart card reader devices (see printer selections). Note that AsciiCE2 supports infrared devices via IrLPT connections and will only read data if the printer can send it using the IrLPT protocol.
Note: Generally, the application will use AsciiCE2's Write, WriteVar or 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.
MFC Syntax: AsciiCE2a.Read(long
MaxBytes, long LastChar, long ModeFlags, long TimeToWait,
long* ResultFlags,long* BytesRead,BYTE* buffer);
C++ Syntax: AsciiCE2a.Read(long
MaxBytes, long LastChar, long ModeFlags, long TimeToWait,
long* ResultFlags,long* BytesRead,BYTE* buffer);
eVB
Syntax:
None (see
ReadVar method).
MaxBytes
- Maximum number of bytes to read.
LastChar - Optional - read data stream until this byte value is found,
then return all data read.
ModeFlags
- Defines following modes:
READMODE_NORMAL = 0 - Reads all data into buffer
READMODE_FLUSHZEROS = 1 - 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 - Returns results of block read:
READRESULT_ERR = 0 - Error trying to read (such as loss of
infrared connection)
READRESULT_OK = 1 - Read was successful
READRESULT_FULLBUFFER = 2 - Returning because
"MaxBytes" bytes were read
READRESULT_TIMEOUT = 3 - Returning because
"TimeToWait" microseconds expired
READRESULT_USERCANCEL = 4 - User cancelled
BytesRead - Returns actual number of bytes read into buffer
buffer - data buffer containing the bytes read
Identical to Read() - except that the data read is returned in a VARIANT array. This is the preferred method for eVB to read.
MFC Syntax: VARIANT*
buffer=AsciiCE2a.ReadVar(long MaxBytes, long LastChar, long
ModeFlags,
long TimeToWait,long* ResultFlags,long* BytesRead);
C++ Syntax: AsciiCE2a.ReadVar(long
MaxBytes, long LastChar, long ModeFlags, long TimeToWait,
long* ResultFlags,long* BytesRead,VARIANT* buffer);
eVB
Syntax:
buffer = AsciiCE2a.ReadVar
MaxBytes, LastChar, ModeFlags, TimeToWait,
ResultFlags,BytesRead
MaxBytes
- Maximum number of bytes to read.
LastChar - Optional - read data stream until this byte value is found,
then return all data read.
ModeFlags
- Defines following modes:
READMODE_NORMAL = 0 - Reads all data into buffer
READMODE_FLUSHZEROS = 1 - 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 - Returns results of block read:
READRESULT_ERR
= 0 - Error trying to read (such as loss of infrared connection)
READRESULT_OK = 1 - Read was successful
READRESULT_FULLBUFFER = 2 - Returning because
"MaxBytes" bytes were read
READRESULT_TIMEOUT = 3 - Returning because
"TimeToWait" microseconds expired
READRESULT_USERCANCEL = 4 - User cancelled
BytesRead - Returns actual number of bytes read into buffer
buffer - data buffer containing the bytes read - stored as VARIANT array
Similar to Read() - but reads a string of text from the printer port.
MFC Syntax: BSTR
string=AsciiCE2a.ReadString(long MaxChars, long LastChar, long
ModeFlags,
long TimeToWait,long* ResultFlags,long* CharsRead);
C++ Syntax: AsciiCE2a.ReadString(long
MaxChars, long LastChar, long ModeFlags, long TimeToWait,
long* ResultFlags,long* CharsRead
,BSTR
string);
eVB
Syntax:
None (see
ReadVar method).
MaxChars
- Maximum number of characters to read.
LastChar - Optional - read data stream until this byte value is found,
then return all data read.
ModeFlags
- Defines following modes:
READMODE_NORMAL = 0 - Reads all data into buffer
READMODE_FLUSHZEROS = 1 - 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 - Returns results of block read:
READRESULT_ERR = 0 - Error trying to read (such as loss of
infrared connection)
READRESULT_OK = 1 - Read was successful
READRESULT_FULLBUFFER = 2 - Returning because
"MaxBytes" bytes were read
READRESULT_TIMEOUT = 3 - Returning because
"TimeToWait" microseconds expired
READRESULT_USERCANCEL = 4 - User cancelled
CharsRead - Returns actual number of characters read into buffer
string - text containing the bytes read
Identical to ReadString() - except that the "ResultFlags" and "CharsRead" values are returned as VARIANTS. This is the preferred method for eVB to read text strings.
MFC Syntax: BSTR*
string=AsciiCE2a.ReadStringVar(long MaxChars, long LastChar,
long ModeFlags, long TimeToWait,VARIANT* ResultFlags,VARIANT* CharsRead);
C++ Syntax: AsciiCE2a.ReadStringVar(long
MaxChars, long LastChar, long ModeFlags,
long TimeToWait,VARIANT* ResultFlags,VARIANT* CharsRead,
BSTR* string);
eVB
Syntax:
buffer = AsciiCE2a.ReadStringVar(MaxChars,
LastChar, ModeFlags, TimeToWait,
ResultFlags,
CharsRead
MaxChars
- Maximum number of characters to read.
LastChar - Optional - read data stream until this byte value is found,
then return all data read.
ModeFlags
- Defines following modes:
READMODE_NORMAL = 0 - Reads all data into buffer
READMODE_FLUSHZEROS = 1 - 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 - Returns results of block read:
READRESULT_ERR
= 0 - Error trying to read (such as loss of infrared connection)
READRESULT_OK = 1 - Read was successful
READRESULT_FULLBUFFER = 2 - Returning because
"MaxBytes" bytes were read
READRESULT_TIMEOUT = 3 - Returning because
"TimeToWait" microseconds expired
READRESULT_USERCANCEL = 4 - User cancelled
CharsRead - Returns actual number of characters read into buffer
string - text containing the bytes read
This
method sends one or more copies of a character byte value to the printer.
MFC Syntax:
AsciiCE2a.RepeatChar(long ch,long repeatcnt);
C++ Syntax:
AsciiCE2a.RepeatChar(long ch,long repeatcnt);
eVB
Syntax:
AsciiCE2a.RepeatChar ch, repeatcnt
ch - character to be sent to printer
repeatcnt - count of number of copies of "ch" to send to
printer.
This
method selects the printer connection for an AsciiCE print job. It must
precede any Acii printing operations.
MFC Syntax:
long retval = AsciiCE2a.SelectPort(long Port,long BaudRate,long HandShake);
C++ Syntax:
AsciiCE2a.SelectPort(long Port,long BaudRate,long HandShake,long*
retval);
eVB Syntax: retval = AsciiCE2a.SelectPort(Port, BaudRate, Handshake)
Port
- Port type:
Constant |
Setting |
Description |
PORT_COM1 |
0 |
Open
COM1 |
PORT_COM2 |
1 |
Open
COM2 |
PORT_COM3 |
4 |
Open COM3 |
PORT_COM4 |
5 |
Open COM4 |
PORT_COM5 |
6 |
Open COM5 |
PORT_COM6 |
7 |
Open COM6 |
PORT_COM7 |
13 |
Open COM7 |
PORT_COM8 |
14 |
Open COM8 |
PORT_COM9 |
17 |
Open COM9 |
PORT_COM0 |
19 |
Open COM0 |
PORT_LPT |
2 |
Open
LPT1 |
PORT_IR |
3 |
Open
IR infrared port |
PORT_TOFILE |
8 |
Send all print data to \Output.prn file |
PORT_SOCKETCOM |
1 |
Socket PNC Bluetooth card support |
PORT_COMPAQ |
15 |
Compaq Bluetooth iPAQ or sleeve |
PORT_IPAQ |
15 |
Bluetooth iPAQ or sleeve |
PORT_WIDCOMM | 16 | Device using WIDCOMM Bluetooth stack |
PORT_BTQUIKPRINT | 18 | Special for WIDCOMM, HP iPAQ 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 PORT_COMPAQ, PORT_IPAQ, PORT_WIDCOMM |
PORT_PRINTERCE |
-1 |
Share PrinterCE port with AsciiCE2. 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
:
Constant |
Setting |
S_4800 |
0 |
S_9600
|
1 |
S_19200
|
2 |
S_38400
|
3 |
S_57600 |
4 |
S_115200 |
5 |
Handshake (plus OR any needed Handshake Bitflags
below):
Constant |
Setting |
Description |
SOFTWARE_HANDSHAKE |
0 |
Use
Xon/Xoff |
HARDWARE_HANDSHAKE |
1 |
|
NO_HANDSHAKE |
2 |
|
Handshake -> Parity: (OR with Handshake):
Constant |
Setting |
Description |
SET_PARITY_NONE |
0x000 |
Default: No parity |
SET_PARITY_EVEN |
0x0800 |
|
SET_PARITY_ODD |
0x0400 |
|
Handshake -> Stopbits: (OR with Handshake):
Constant |
Setting |
Description |
SET_STOPBITS_ONE |
0x000 |
Default: No parity |
SET_STOPBITS_ONEANDHALF |
0x0200 |
|
SET_STOPBITS_TWO |
0x0100 |
|
Handshake -> Bytesize: (OR with Handshake):
Constant |
Setting |
Description |
SET_BYTESIZE_8 |
0x000 |
Default: 8 data bits per byte |
SET_BYTESIZE_7 |
0x0080 |
|
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" - PORT_PRINTERCE - to allow shared use of the printer port by PrinterCE and AsciiCE2 -> with cautions and alerts sounded!! See AsciiCE discussion here.
Port
- Port type:
Constant |
Setting |
Description |
PORT_COM1 |
0 |
Open
COM1 |
PORT_COM2 |
1 |
Open
COM2 |
PORT_COM3 |
4 |
Open COM3 |
PORT_COM4 |
5 |
Open COM4 |
PORT_COM5 |
6 |
Open COM5 |
PORT_COM6 |
7 |
Open COM6 |
PORT_COM7 |
13 |
Open COM7 |
PORT_COM8 |
14 |
Open COM8 |
PORT_COM9 |
17 |
Open COM9 |
PORT_COM0 |
19 |
Open COM0 |
PORT_LPT |
2 |
Open
LPT1 |
PORT_IR |
3 |
Open
IR infrared port |
PORT_TOFILE |
8 |
Send all print data to \Output.prn file |
PORT_SOCKETCOM |
1 |
Socket PNC Bluetooth card support |
PORT_COMPAQ |
15 |
Compaq Bluetooth iPAQ or sleeve |
PORT_IPAQ |
15 |
Bluetooth iPAQ or sleeve |
PORT_WIDCOMM | 16 | Device using WIDCOMM Bluetooth stack |
PORT_BTQUIKPRINT | 18 | Special for WIDCOMM, HP iPAQ 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 PORT_COMPAQ, PORT_IPAQ, PORT_WIDCOMM |
PORT_PRINTERCE |
-1 |
Share PrinterCE port with AsciiCE2. 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
:
Constant |
Setting |
S_4800 |
0 |
S_9600
|
1 |
S_19200
|
2 |
S_38400
|
3 |
S_57600 |
4 |
S_115200 |
5 |
Handshake:
Constant |
Setting |
Description |
SOFTWARE_HANDSHAKE |
0 |
Use
Xon/Xoff |
HARDWARE_HANDSHAKE |
1 |
|
NO_HANDSHAKE |
2 |
|
ReadBufferSize:
This Write-Only property sets error level of errors returned by AsciiCE2.
MFC Syntax:
AsciiCE2a.SetSetErrorLevel(long value);
C++ Syntax:
AsciiCE2a.put_SetErrorLevel(long value);
eVB
Syntax: AsciiCE2a.SetErrorLevel
=value
value - Integer that specifies four available error levels
Constant |
Setting |
Description |
vbErrLevelNone |
0 (default) |
No errors are returned Use StatusCheck to watch
progress |
vbErrLevelAll |
1 |
All errors are returned |
vbErrLevelTask |
2 |
Only errors that force abort of current operation or of
printer job are returned |
vbErrLevelJob |
3 |
Only errors forcing abort of the printer job are returned |
There are two approaches that a VB program can take while
using AsciiCE2
first is to set up "On Error" statements in
each sub or function that calls a PrinterCE method or property and use the
"On Error" handler to determine the course of action when an
error occurs within PrinterCE. The second approach is to use occasional
calls to StatusCheck to determine if an error has occurred.
When an error occurs within AsciiCE2, the severity of the error is determined and PrinterCE "remembers" this as appropriate. So, for example, if a printer error occurs, the entire printing job must be aborted, so all calls to PrinterCE will remember that it is aborting and this will be handled gracefully.
This structure allows the VB program that uses AsciiCE2 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).
C++
and MFC-based applications can use the StatusCheck() method to determine
if some error or user action has caused AsciiCE2 to
stop printing. Since AsciiCE2 stops trying to print once an error or user
cancel has been found, StatusCheck() only needs to be called when the
application may be entering some extended period of activity.
This Write-Only property sets error level of errors returned
by AsciiCE2..
MFC Syntax:
AsciiCE2a.SetSetReportLevel(long value);
C++ Syntax:
AsciiCE2a.put_SetReportLevel(long value);
eVB
Syntax: AsciiCE2a.SetReportLevel
=value
value - Integer that specifies four available error levels
Constant |
Setting |
Description |
vbReportErrors |
0 (default) |
All errors are reported to user by PrEngineCE via MsgBox()
error reports |
vbNoReportErrors |
1 |
No errors are reported by PrEngineCE... it is up to app to
report errors. |
There are two approaches that a VB program can take while
using AsciiCE2
first is to set up "On Error" statements in
each sub or function that calls a PrinterCE method or property and use the
"On Error" handler to determine the course of action when an
error occurs within PrinterCE. The second approach is to use occasional
calls to StatusCheck to determine if an error has occurred.
When an error occurs within AsciiCE2, the severity of the error is determined and PrinterCE "remembers" this as appropriate. So, for example, if a printer error occurs, the entire printing job must be aborted, so all calls to PrinterCE will remember that it is aborting and this will be handled gracefully.
This structure allows the VB program that uses AsciiCE2 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).
C++ and MFC-based applications can use the StatusCheck() method to determine if some error or user action has caused AsciiCE to stop printing. Since AsciiCE stops trying to print once an error or user cancel has been found, StatusCheck() only needs to be called when the application may be entering some extended period of activity.
This READ-ONLY property returns the current status of
AsciiCE2.
MFC Syntax:
long value=AsciiCE2a.GetStatusCheck();
C++ Syntax:
AsciiCE2a.get_StatusCheck(long * value);
eVB
Syntax: value = AsciiCE2a.StatusCheck
value - Integer that specifies four possible status values
Constant |
Setting |
Description |
vbNoError |
0 |
No error to report |
vbUserCancel |
1 |
User cancelled print job |
vbAbortOperation |
2 |
Error aborted the last print operation (but the print job
is still viable). |
vbAbortPrint |
3 |
Error aborted the print job |
This
is the main text printing method.
MFC Syntax:
AsciiCE2a.Text(
C++ Syntax:
AsciiCE2a.Text(BSTR textstring);
eVB
Syntax:
AsciiCE2a.Text textstring
textstring
- Text string to be printed.
Sends
block of data to printer..
MFC Syntax: AsciiCE2a.Write(BYTE*
buffer,long NumberBytesToWrite,long*
BytesWritten);
C++ Syntax: AsciiCE2a.Write(BYTE*
buffer,long NumberBytesToWrite,long*
BytesWritten);
eVB Syntax: None (see WriteVar method).
buffer
- Block of bytes
to be sent to printer
NumberBytesToWrite - count of bytes to send from "buffer"
NOTE: If using both PrinterCE and AsciiCE2 (SelectPortEx -> PORT_PRINTERCE mode) simultaneously, any calls to AsciiCE2's Write, WriteVar, or Text result in flushing all PrinterCE printing operations before processing the AsciiCE2 command. If the call to Write or WriteVar 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 AsciiCE2" for more info.
Sends
block of data to printer. The data is passed in the form of a VARIANT
array - this is eVB's native method of passing arrays of data and so
WriteVar() should be used by eVB applications.
For MFC and C++, the "Write" method is preferred.
MFC Syntax:
AsciiCE2a.WriteVar(VARIANT*
buffer,long NumberBytesToWrite,long*
BytesWritten);
C++ Syntax:
AsciiCE2a.WriteVar(VARIANT*
buffer,long NumberBytesToWrite,long*
BytesWritten);
AsciiCE2a.WriteVar
varbuffer, NumberBytesToWrite, BytesWritten
varbuffer
- Block of bytes to be sent to printer - passed as VARIANT array.
NumberBytesToWrite - count of bytes to send from "buffer"