Author Topic: Sending ESC/P sequences to a USB-connected printer  (Read 5963 times)

0 Members and 1 Guest are viewing this topic.

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
Sending ESC/P sequences to a USB-connected printer
« on: April 11, 2019, 07:22:51 am »
Hi,

Have just installed QB64 -- which will allow me to run my legacy Basic code on my 64 bit machines. Happy days! :-)

I have read through the other thread on this business of sending ESC sequences direct to a printer and noted the suggestions.

My requirement is different: I need to directly drive a Brother QL-500 label printer connected to the PC's USB port using a plethora of Brother's specified "ESC/P" type sequences to create a variety of labels.

I have been programming with various incarnations of Basic, on and off, since 1975 (then on a PDP-11) and I'm quite familiar with sending ESC sequences to devices over serial ports. However, I have yet to do so via a USB connection under Windows (currently Win 7 but need to be compatible with Win 10).

What is the recommended method of opening a USB port for two way communications? (I need to query the printer for such things as the label type currently loaded in its memory, its current status, etc).

What is the recommended Basic statement for sending lines of ESC sequences to such a printer? I would imagine LPRINT?
« Last Edit: April 11, 2019, 07:28:07 am by GTC »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Sending ESC/P sequences to a USB-connected printer
« Reply #1 on: April 11, 2019, 01:12:33 pm »
Is your printer also wifi? If so, it's super simple over wifi... Let's see if I can remember all that code needed. Oh yeah,

LPRINT CHR$(12)

So kidding aside about the all that code part, it's just that simple to send it by wifi. I have a brother printer, hooked up to my Windows 10, and a wireless router. If I ran that 1-line of code above in the QB64 IDE, it would turn on my Brother printer and eject a blank page.

As far as opening a USB port, sorry, I have not tried that before. I started programming in 1981, so I also used esc codes to do print to forms, back in the good ol' days.

Hopefully, someone else has some USB answers, or maybe you can find something in the QB64 Wiki: http://www.qb64.org/wiki/Main_Page

Pete
« Last Edit: April 11, 2019, 04:47:00 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
Re: Sending ESC/P sequences to a USB-connected printer
« Reply #2 on: April 11, 2019, 02:52:52 pm »
Is your printer also wifi?

No, it's cable only, and that is what I have been asked to support.

Quote
Hopefully, someone else has some USB answers, or maybe you can find something in the QB64 Wiki: http://www.qb64.org/wiki/Main_Page

I have already done a search of the Wiki on "USB" but found nothing applicable to my question (apart from mention that "LPRINT will only print to the default USB or LPT printer set up in Windows" and "Printer escape codes starting with CHR$(27) will not work with LPRINT and may produce text printing errors." -- which essentially kills LPRINT for my purpose.)
« Last Edit: April 11, 2019, 03:05:37 pm by GTC »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Sending ESC/P sequences to a USB-connected printer
« Reply #3 on: April 11, 2019, 03:57:38 pm »
Can solve your problem statement _PRINTIMAGE? First create image and then print it.

Offline Jack002

  • Forum Regular
  • Posts: 123
  • Boss, l wanna talk about arrays
    • View Profile
Re: Sending ESC/P sequences to a USB-connected printer
« Reply #4 on: April 11, 2019, 04:24:52 pm »
GTC, I went looking for you, and I don't see anything so far. Like you said, LPRINT will not work. I read the wiki on it. Found a great page with lots of info, but it was all on printers that connect with a parallel port or a serial. None on USB.

I know esc codes were how we all controlled printers at one time. I had a commodore 64 with a commodore printer and I made some crazy things with it, a  with esc codes as I recall.

Good luck. If I see anything out there, I'll post it.
QB64 is the best!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Sending ESC/P sequences to a USB-connected printer
« Reply #5 on: April 11, 2019, 04:27:16 pm »
Another alternative is to make your labels, form text, etc., as an rtf file and slave print it with a SHELL command to Wordpad. We had a discussion on this awhile back. If you think that may work, look here: https://www.qb64.org/forum/index.php?topic=979.msg101802#msg101802

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

Offline Jack002

  • Forum Regular
  • Posts: 123
  • Boss, l wanna talk about arrays
    • View Profile
Re: Sending ESC/P sequences to a USB-connected printer
« Reply #6 on: April 11, 2019, 04:44:38 pm »
I found this DLL file that claims to print to any printer from any programming language
http://3d2f.com/programs/55-664-raw-data-printer-component-download.shtml
A huge boast I'd think. I suppose QB64 can take dll files? I never tried.
QB64 is the best!

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
Re: Sending ESC/P sequences to a USB-connected printer
« Reply #7 on: April 11, 2019, 04:45:13 pm »
Another alternative is to make your labels, form text, etc., as an rtf file and slave print it with a SHELL command to Wordpad. We had a discussion on this awhile back. If you think that may work, look here: https://www.qb64.org/forum/index.php?topic=979.msg101802#msg101802

Pete

Yes, I've seen that post (I referred to that in my initial post above).

That approach does not work with this printer. I have to send particular (proprietary) escape sequences to it which have no association with RTF.

My first issue is how to conduct two-way communication with USB ports from within QB64. Serial ports (under DOS) were easy because Basic supports that natively. Hopefully, there are programmers on here with USB comms experience.

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
Re: Sending ESC/P sequences to a USB-connected printer
« Reply #8 on: April 11, 2019, 04:52:19 pm »
I found this DLL file that claims to print to any printer from any programming language
http://3d2f.com/programs/55-664-raw-data-printer-component-download.shtml
A huge boast I'd think. I suppose QB64 can take dll files? I never tried.

Thanks. Good find Jack002.

"It enables you to print raw data and send native printer commands (escape codes) directly to the printer, bypassing any printer drivers."

This sounds like a great way to generate the dreaded BSOD, but heck I'll try anything.

"Raw Data Printer can be used from any programming language that support ActiveX components"

I gather that QB64 has some support for DLLs:

http://www.qb64.org/wiki/DLL_Libraries

I'll need to research that further.

Edit: reading the product's site I note:

Quote
Q. On what platforms can Raw Data Printer be used?
A. Raw Data Printer component can be used on all 32-bit Windows platforms (Windows 95/98/NT/ME/2000/2003/XP).

I'll email the author and ask if it now also supports 64-bit platforms. I hope it does as it hits most of the bases for me.
« Last Edit: April 11, 2019, 05:18:26 pm by GTC »

Offline MWheatley

  • Newbie
  • Posts: 64
    • View Profile
Re: Sending ESC/P sequences to a USB-connected printer
« Reply #9 on: April 12, 2019, 01:44:43 pm »
I hope I'm not speaking out of turn, here.

I use QB64, but I also run native QuickBasic 4.5 programs under vDosPlus, and they communicate fine with a USB-connected laser printer.

I'd offer to hook up an Epson printer, but I've just checked and it doesn't support USB.

Malcolm

Offline Jack002

  • Forum Regular
  • Posts: 123
  • Boss, l wanna talk about arrays
    • View Profile
Re: Sending ESC/P sequences to a USB-connected printer
« Reply #10 on: April 12, 2019, 03:31:26 pm »
Malcolm, I assume you have tried the QB 4.5 code in QB64 and it doesn't work?
Is vDosPlus one of those DOS apps like DOSBOX that lets you run DOS apps on a new computer?

GTC, I don't know how practical it would be for you, but you might want to look at this option?
QB64 is the best!

Offline MWheatley

  • Newbie
  • Posts: 64
    • View Profile
Re: Sending ESC/P sequences to a USB-connected printer
« Reply #11 on: April 12, 2019, 04:14:29 pm »
Malcolm, I assume you have tried the QB 4.5 code in QB64 and it doesn't work?
Is vDosPlus one of those DOS apps like DOSBOX that lets you run DOS apps on a new computer?

GTC, I don't know how practical it would be for you, but you might want to look at this option?

Again, I hope I'm not speaking out of turn.

I'm reasonably prominent in WordPerfect for DOS circles, and in that world, many people have moved over to running WordPerfect under vDOS, a business-friendly variant of DOSBOX that aims to do more than just gaming.  So it prints, etc etc, unlike DOSBOX.

Its weakness is that it doesn't handle DOS programs that rely on certain interrupt codes.  QB45 uses these codes.  VDosPlus is a fork of vDOS that does handle these interrupt codes, and so I use it as the nearest thing I can find to DOS, in 64-bit machines.  (Although, in point of fact, a lot of my day-to-day work is still done on a 32-bit machine.)

I have a bunch of QB45 programs that are important to my work.  (I'm mid-60s, but not retired.)  Being somewhat paranoid about what Microsoft might do next, I tend to keep my options open.  I run Ubuntu Linux as well (which is superb), and as a matter of policy keep these QB45 programs going on both QB64 and QB45-under-vDosPlus.

I have long since stopped keeping them going under Liberty Basic, which is what I was doing prior to QB64.

I'm not an especially active coder, but I add to these programs at the rate of one or two a year, as the need arises.  Some of them go back to Commodore PET days.

So there's a long answer to your question, but hopefully you can see where I'm coming from. 

Malcolm

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
Re: Sending ESC/P sequences to a USB-connected printer
« Reply #12 on: April 14, 2019, 07:35:49 pm »

I'll need to research that further.

Edit: reading the product's site I note:

I'll email the author and ask if it now also supports 64-bit platforms. I hope it does as it hits most of the bases for me.

VBGold's Software web page says:

"Response to your inquiries within just a few hours!" ... wrong, no response for days

"And now you can even talk to us live (click on the Live Help image)!" ... wrong, always offline.


Last ditch effort will be a phone call on Monday.
« Last Edit: April 14, 2019, 07:48:16 pm by GTC »

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
Re: Sending ESC/P sequences to a USB-connected printer
« Reply #13 on: April 14, 2019, 07:38:26 pm »

I use QB64, but I also run native QuickBasic 4.5 programs under vDosPlus, and they communicate fine with a USB-connected laser printer.

I'd offer to hook up an Epson printer, but I've just checked and it doesn't support USB.

Malcolm

Thanks, but the reason I'm using QB64 is that the app needs to run natively under 64-bit Windows. I avoid DOS these days on new stuff.

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
Re: Sending ESC/P sequences to a USB-connected printer
« Reply #14 on: April 24, 2019, 07:04:36 am »
Well, after following Brother's Command Reference Manual for the QL-5xx series and (as witnessed via a USB port sniffer utility) after sending the correct ESC/P codes and seeing the printer respond with the expected response message, but having the printer mechanism sit there silently while I scratched my head and wondered, I took up the issue with Brother Support only to be told that, despite the manual, the QL-500 through QL-570 printers do not support ESC/P mode.

So, the printer responds to the ESC/P command to return its status but it doesn't support ESC/P mode. Japanese logic. Go figure.