🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #3204

Re: printing on serial port

#3204
From: Bob Gonder
Date: Fri, 28 Jul 2006 18:23
67 lines
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;
>   }
>}
Technical Details
Message-ID: <mjkkc2pl2dr3b21ob5nmeip3tp0798mpl5@4ax.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news2.volia.net!news.germany.com!newsfeed.freenet.de!news.albasani.net!reader.uucp.at!feeder02.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail
References: <44ca1798@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,90aeb40ea5a6de4e
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: printing on serial port
Date: Fri, 28 Jul 2006 11:23:24 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <mjkkc2pl2dr3b21ob5nmeip3tp0798mpl5@4ax.com>
References: <44ca1798@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 71.49.221.11
X-Trace: newsgroups.borland.com 1154111004 71.49.221.11 (28 Jul 2006 11:23:24 -0700)
Lines: 70
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news2.volia.net!news.germany.com!newsfeed.freenet.de!news.albasani.net!reader.uucp.at!feeder02.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail