Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages
Started by Borut
Fri, 28 Jul 2006 13:56
printing on serial port
Author: Borut
Date: Fri, 28 Jul 2006 13:56
Date: Fri, 28 Jul 2006 13:56
64 lines
2876 bytes
2876 bytes
I have a problem with printing on dotmatrix printer (POS printer with 40
characters in line). It works fine with printer on paralel port (LPT1) and
with small number of lines but when I try to print 12 lines or more (on
serial), it stops printing. I use Generic / Text only printer and this
procedure:
bool xPrint(char* szPrinterName, char *szBuffer)
{
HANDLE hPrinter; // Printer handle
int iLen = strlen(szBuffer);// Length of the data to be sent
DWORD dwWritten; // How much was written to the printer
// Open printer and get a handle to it (which is saved in hPrinter)
if(OpenPrinter(szPrinterName, &hPrinter, NULL))
{
// Doc info
DOC_INFO_1 Info;
memset(&Info, 0, sizeof(Info));
Info.pDocName = "My PrintJob"; // Name of the Doc (which is shown in
the PrintManager)
Info.pOutputFile = NULL; // We're not going to write to a file so we
set it to NULL
Info.pDatatype = "RAW"; // Data are sent in RAW format (RAW and EMF
are supported by both
// Win9x and Win NT). Win NT also supports TEXT.
// Start doc
if(!StartDocPrinter(hPrinter, 1, (LPBYTE)&Info))
return false;
// Tell the printer we're starting on a new page
StartPagePrinter(hPrinter); // Write data to the printer
if(!WritePrinter(hPrinter, szBuffer, iLen, &dwWritten))
{
// An error happened while sending data to the printer.
// Use LastError to figure out what went wrong.
}
// Tell the printer we're done writing this page
EndPagePrinter(hPrinter);
// End the document
if(!EndDocPrinter(hPrinter))
return false;
// Close the printer
ClosePrinter(hPrinter);
return true;
}
else
{
return false;
}
}
what do you think is wrong?
Thx in advance
Borut
Slovenia
--
Bokosoft d.o.o.
www.bokosoft.si
info@bokosoft.si
tel: 01/546 37 20
fax: 01/546 37 21
Re: printing on serial port
Author: Bob Gonder
Date: Fri, 28 Jul 2006 18:23
Date: Fri, 28 Jul 2006 18:23
67 lines
3125 bytes
3125 bytes
Borut wrote:
>I have a problem with printing on dotmatrix printer (POS printer with 40
>characters in line). It works fine with printer on paralel port (LPT1) and
>with small number of lines but when I try to print 12 lines or more (on
>serial), it stops printing. I use Generic / Text only printer and this
>procedure:
Does the POS have a page size of 12 lines?
You might try breaking up the printing into one Write per line instead
of one big Write.
You might also try using CreateFile() and WriteFile().
They work pretty well with serial printers.
>what do you think is wrong?
Looks about right.
You might want to check every return value (you don't check
StartPagePrinter).
You should also close out everything you opened when you return error.
>bool xPrint(char* szPrinterName, char *szBuffer)
>{
> HANDLE hPrinter; // Printer handle
> int iLen = strlen(szBuffer);// Length of the data to be sent
> DWORD dwWritten; // How much was written to the printer
>
> if(OpenPrinter(szPrinterName, &hPrinter, NULL))
> {
> DOC_INFO_1 Info;
> Info.pDocName = "My PrintJob"; // Name of the Doc (which is shown in
> Info.pOutputFile = NULL; // We're not going to write to a file so we
I have this set to szPrinterName.
> Info.pDatatype = "RAW"; // Data are sent in RAW format (RAW and EMF
> if(!StartDocPrinter(hPrinter, 1, (LPBYTE)&Info))
> return false;
Need to close Printer before you return
> StartPagePrinter(hPrinter); // Write data to the printer
test return value and close Doc and Printer before returning false.
> if(!WritePrinter(hPrinter, szBuffer, iLen, &dwWritten))
> {
> // An error happened while sending data to the printer.
> // Use LastError to figure out what went wrong.
You need to close out the Page, Doc and Printer, then return false;
> }
> EndPagePrinter(hPrinter);
> if(!EndDocPrinter(hPrinter))
> return false;
It's a bit late to be returning false.
> ClosePrinter(hPrinter);
> return true;
> }
> else
> {
> return false;
> }
>}
Re: printing on serial port
Author: Mike Collins
Date: Mon, 31 Jul 2006 09:08
Date: Mon, 31 Jul 2006 09:08
13 lines
1521 bytes
1521 bytes
Is the printer recognised by Windows as a valid printer? I've done exactly the same thing on a PoS system that we developed but i used the VCL TPrinter object and wrote directly onto it's canvas - worked perfectly, no problems. Might be a consideration? Mike C "Borut" <borut@bokosoft.si> wrote in message news:44ca1798@newsgroups.borland.com... >I have a problem with printing on dotmatrix printer (POS printer with 40 > characters in line). It works fine with printer on paralel port (LPT1) and > with small number of lines but when I try to print 12 lines or more (on
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads