Printing to USB or wireless printers

307 views
Skip to first unread message

flicker177

unread,
Jul 4, 2020, 2:59:50 PM7/4/20
to Harbour Users
Hello folks,

I’m continuing to work on my Cli**er sail race scoring program ported to Harbour. In general its working very well.

I ran into an issue with printing. I believe I understand what is going on. Using the standard SET PRINTER, SET PRINTER ON, commands Harbour acts just like Cli**er under DOS. It will only print to hardware LPT ports. I could not find a clean way to print to USB or wireless printers.

I have a workaround sending the print output to a file and then using an external program called “PrintFilePrinter” which monitors the folder I use for the print file and when it sees a file of type .PRN it sends it to the default Windows printer and then deletes the file. This works fine but it seems ugly and messy.

Does anyone know of a better way, perhaps using a Harbour function that can accomplish this in a clean way? After a lot of searching I didn't find anything of much help.

Thanks in advance,
--Bill


Auge & Ohr

unread,
Jul 4, 2020, 4:25:10 PM7/4/20
to Harbour Users
hi,

you can re-direct USB Printer as Network Printer and access it.

configure your USB-Printer
share it as Netweork-Printer
access Netwerk-Printer to LPT1

greetings by OHR
Jimmy

Klas Engwall

unread,
Jul 4, 2020, 5:00:20 PM7/4/20
to harbou...@googlegroups.com
Hi Bill,
Jimmy's suggestion works very well, although if the computer has a
physical LPT1 port I would use a higher LPT number for the redirection
in order not to end up with circular redirection between the physical
LPT1 and the virtual LPT1.

Another way is to use Harbour's win_PrintFileRaw() function from the
hbwin contrib. The docs at Pete's site
(https://github.com/Petewg/harbour-core/wiki/HBWIN) say:

---------------
win_PrintFileRaw(<cPrinterName>, <cFileName>) ➜ nBytesWritten
sends contents of file cFileName to printer cPrinterName. Returns number
of bytes printed or negative value on error.
---------------

It works with any printer that is installed in Windows, using the
printer name from Control Panel, provided that the printer understands
raw text and escape codes.

You have to call the function yourself after creating the file and then
delete the file when done.

Regards,
Klas

Shaji Thomas

unread,
Jul 5, 2020, 4:57:03 AM7/5/20
to Harbour Users
Hi bill,
I recommend the  win_PrintFileRaw () method over port re-direction. 
win_PrintFileRaw() is built-in and you do' not have to work on it but in the other case (in my experience)
there is always a chance for a call from customer side.

regards..
Shaji Thomas

Betty Hollinshead

unread,
Jul 5, 2020, 6:21:58 AM7/5/20
to Harbour Users
*
Harbour 3.0/Fedora32
A command line call to CUPS will send a file to a printer.
In the example below with no parameters, the file goes to the default CUPS printer.
Note that the default printer can be ANY sort of  connection.
*
PROCEDURE MAIN
    LOCAL cCommand := "lp your.pdf"
    run (cCommand)
RETURN


Thanks in advance,
--Bill


flicker177

unread,
Jul 5, 2020, 4:07:12 PM7/5/20
to Harbour Users


On Sunday, July 5, 2020 at 4:57:03 AM UTC-4, Shaji Thomas wrote:
Hi bill,
I recommend the  win_PrintFileRaw () method over port re-direction. 
win_PrintFileRaw() is built-in and you do' not have to work on it but in the other case (in my experience)
there is always a chance for a call from customer side.

Hi Shaji,

Yes! This is exactly what I was looking for but somehow hadn't managed to find. My program could already create the raw print file so it was very simple to use
win_PrintFileRaw(win_printerGetDefault(),SPOOLFIL) to send the raw input to the windows default printer and then just delete the print file after a successful print. Works perfectly. Thanks so much to you and everyone for the help!
Regards,
--Bill

FX Suryadi

unread,
Jul 12, 2020, 2:32:32 AM7/12/20
to harbou...@googlegroups.com
I am using USB dot printer.
Here is my prosedur
- setup printer in Windows and SHARE it
- use command -> NET USE LPT1:  \\computername\sharename
------- NET USE /? for help in command prompt
- In program, use SET DEVICE TO PRINT
I used it for reroute printer to output file, so I don't need a real printer until program ready for testing
Hope this help you

Suryadi

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/42b03c49-f417-4c4c-83ec-720ad0d9599bo%40googlegroups.com.


--
GBU,
Suryadi
Servite Domino in Laetitia
Reply all
Reply to author
Forward
0 new messages