Author Topic: Print to USB printer.  (Read 3453 times)

0 Members and 1 Guest are viewing this topic.

Offline kanga85

  • Newbie
  • Posts: 1
    • View Profile
Print to USB printer.
« on: February 20, 2020, 02:38:08 am »
I have previously, in all my QB64 programs, printed to a printer attached to the printer port with the command:
 Open "O", #1, LPT1.
I have now moved to a USB printer, which the computer recognizes as USB001.   However if I use:
 Open, "O", #1, USB001, nothing gets sent to the printer.
What code should I use?
Thanks for any help.
Kanga85

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Print to USB printer.
« Reply #1 on: February 20, 2020, 05:23:43 am »
If you are using Windows, you can use a Windows API call and/or powershell to set the USB printer as your default printer, or use the Windows API routine to print. LPRINT works with QB64, but printer esc sequences, to control printing, are not available in QB64. You can slave to wordpad and write the print routine as an .rtf file, to get around that. Using _PRINTIMAGE and sending to the printer is another trick. I have no clue how Mac or Linux systems would be treated.

Here are a few posts to read on the "How to's" for this topic...

https://www.qb64.org/forum/index.php?action=search2

If that link doesn't work, just go to https://www.qb64.org/forum/index.php and type "USB PRINTER" in the search query.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Print to USB printer.
« Reply #2 on: February 20, 2020, 07:29:36 am »
You can slave to wordpad and write the print routine as an .rtf file, to get around that.

I did something like that with my grain harvest database application. When they took the DOS out of Windows, I sent printed output to an html format and saved like a webpage and then open the webpage and printed it. It was an extra step, but got around the problem. It still does it that way as I've been too lazy to go back and change it.

Offline Bert22306

  • Forum Regular
  • Posts: 206
    • View Profile
Re: Print to USB printer.
« Reply #3 on: February 20, 2020, 03:48:15 pm »
Much like OldMoses, but more generic and standard, I simply do this:

OPEN "c:\temp\[NameOfFile].txt" FOR OUTPUT AS #1

It's a two-step process, but it allows you to print from whatever word processor, text editor, whatever, or you can send it as an attachment to an email, and you can filter out stuff you don't need printed, at the last minute, before going to the printer.

I always go to my temp directory (which I clean out periodically), but of course, you can send that text file wherever you want.

Oh, I forgot to specify what the PRINT commands look like. Where you write PRINT, to show the output on the screen, you write PRINT #1, to write to the text file, as this shows:

PRINT "IPv4 address in binary: "; BinByte$(1); " "; BinByte$(2); " "; BinByte$(3); " "; BinByte$(4)
PRINT #1, "IPv4 address in binary: "; BinByte$(1); " "; BinByte$(2); " "; BinByte$(3); " "; BinByte$(4)

If you want the text file to be exactly the same as what you see on the screen, it's as simple as copy and paste, adding that "#1," after PRINT.


 
« Last Edit: February 20, 2020, 04:02:31 pm by Bert22306 »