USB Printing

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

franco
Posts: 821
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: USB Printing

Post by franco »

Serge,
You do not change ports net use redirects ports. That is why I release lpt1: at end of bat file. net use lpt1: /delete
I use this in HB30 and Clipper NOT HMG.
In hmg I use normal print set.
Here is a crude example

Code: Select all

Procedure Printsmall
	*------------------------------------------------------------------------------*
	Local i ,lSuccess, pl:= 0, Page := 1, PR := 'Star'           //ALLTRIM(Controls->prn1)
	Parameter DI
        select your print file
	go top
			SELECT PRINTER PR TO LSUCCESS ;  //PREVIEW ;
			ORIENTATION	PRINTER_ORIENT_PORTRAIT ;  
			QUALITY	PRINTER_RES_MEDIUM 
			If lSuccess  <> .T.
				MsgInfo('Print Not Available')
				return
			EndIf
	      pl:=pl+5
         	START PRINTPAGE
	       pl:=pl+5
               @ pl,5   print 'Company'  FONT "Arial" SIZE 8 
	       @ pl+4,5  Print  'Address. SIZE 8
	      pl:=pl+18
	     @ pl+4,5  Print 'Sold To:  customer->name 'FONT "Arial" SIZE 7 
             @ pl+8,5 print '               Address.'  'FONT "Arial" SIZE 7 
             pl:=pl+12
             @ pl+4,2 print 'Item                         Description    '+;  
				'                             Amount'  FONT "Arial" SIZE 7
		@ pl+8,1  Print Line TO pl+8,80 penwidth 0.1		//110	
		pl:=pl+6           //8
                go top
		do while ! eof()
			if eof()
				exit
			endif
			@ pl+4,1 print 'item' FONT "Arial" SIZE 6 bold  //10
			@ pl+4,22 print 'desc' FONT "Arial" SIZE 6 BOLD  //45
			@ pl+4,70 print '     129.00' right  FONT "Arial" SIZE 7 //110
			pl:=pl+4
                        if pl >= controls->invlines*4       // a value in my control file is 55
				END PRINTPAGE
				START PRINTPAGE    //  this stops eject
				PL := -4
			endif
			skip
			loop
		enddo
** next print footertotals no not forget to keep adding 4 for every line
	END PRINTPAGE
	END PRINTDOC
return
	
Remember pos is half width of laser printer other wise a print procedure is the same. I found it takes 4 lines between lines at size 9.
I have three print outs for invoices PRINTBIG, PRINTLITTLE, PRINTFILE.
Franco
Last edited by franco on Thu May 11, 2017 3:57 pm, edited 5 times in total.
All The Best,
Franco
Canada
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: USB Printing

Post by serge_girard »

Thanks All !

I try as soon as possible. Serge
There's nothing you can do that can't be done...
trmpluym
Posts: 303
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands

Re: USB Printing

Post by trmpluym »

Serge,

When there is only one pc you also can use this trick:

net use lpt1: \\127.0.0.1\printershare

127.0.0.1 (localhost) is the current machine where you have to share the USB printer on.

Theo
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: USB Printing

Post by serge_girard »

Thx Theo!

It is indeed one PC.

printershare is the default name, I presume?

Serge
There's nothing you can do that can't be done...
edk
Posts: 912
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: USB Printing

Post by edk »

Serge,
serge_girard wrote: Fri May 05, 2017 7:07 am printershare is the default name, I presume?
No, printershare is the share name of the shared printer.


If the printer supports RAW printing, you can try to send directly to the printer queue a previously created print file:

Code: Select all

cPrnFileName := "_hbtest.prn"
hb_MemoWrit( cPrnFileName, "Hello World!" + Chr( 12 ) )
cPrinter:=GetPrinter()
IF !EMPTY(cPrinter)
     MsgInfo( "win_PrintFileRaw() returned: " + hb_ntos( WIN_PRINTFILERAW( cPrinter, cPrnFileName, "testing raw printing" )))
ENDIF
serge_girard wrote: Wed May 03, 2017 3:22 pm Hello,

Does anybody know how to print directly to a POS USB printer? I now have an old paraller POS printer which prints immdetialy after:

Code: Select all

SET DEVICE  TO PRINTER
SET PRINTER ON
SET CONSOLE OFF
? 'lines'
SET PRINTER OFF
SET PRINTER TO
SET DEVICE  TO SCREEN
SET CONSOLE ON
Thanks, Serge

It is better for me to create a print file instead of printing directly to the PRN device.

Code: Select all

cPrnFileName := "_hbtest.prn"
SET DEVICE  TO PRINTER
SET PRINTER TO &cPrnFileName
SET CONSOLE OFF
? 'lines'
SET PRINTER OFF
SET PRINTER TO
SET DEVICE  TO SCREEN
SET CONSOLE ON
mol wrote: Wed May 03, 2017 6:23 pm Hi Serge.
Do you connect this printer via USB-Centronics adapter?
You can set your printer as shared, then you can map it to lpt

eg.
net use lpt1 \\comp_name\shared_printer_name

After that, you can use your commands as you described
Capturing the LPT1 port is not always a good idea, especially when your computer has a physical LPT1 port. In newer Windows, sometimes you need to disable the physical LPT1 port or change to LPT2 or LPT3.
Besides, there is no need to capture LPT ports by NET USE LPTn.

Simply refer directly to the UNC path of the shared resource:

Code: Select all

cUNCPrinter:= "\\localhost\sharedprinter"
FILECOPY ( cPrnFileName, cUNCPrinter )
where: "sharedprinter" is the share name of the shared printer.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: USB Printing

Post by Pablo César »

Thank you Edward, everything you said, IMHO, is correct. :D
It is better for me to create a print file instead of printing directly to the PRN device.
Is the best practice ! :)
 
As the same used NET USE OS command, you can use NetRedir() in Harbour.

The guaranteed way to print is by graphical mode (when is not matrix printer), IMHO.

PrintFile.exe is a good example to select from text and graphical mode but always printing by the file created at report process instead to print direct to the printer. This practice belongs to the past.
 
@Franco,

Please take in mind when you post your codes embraced/enclosed by Image and Image tags, my friend.

It's very hard to understand without it and certainly everybody will be grateful for that. :mrgreen:

CODE tags - Brief tutorial
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
franco
Posts: 821
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: USB Printing

Post by franco »

Thank you Pablo,
I did not know how to do this.
@Serge, what are going to use the pos printer for and what language.
If for invoicing Why not just make a print procedure. That works best for me.
Franco
All The Best,
Franco
Canada
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: USB Printing

Post by serge_girard »

Hi Franco,

It is for use as POS ticket, such as a Citizen CT-S851 Thermal Ticketprinter or a STAR TSP 650II Thermal Ticketprinter
I now have old PC's with parallel connections and some have to be replaced with newer without parallel. So I will need both options.

Serge
There's nothing you can do that can't be done...
franco
Posts: 821
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: USB Printing

Post by franco »

Serge,
I put in a star 654 in for a customer who is using my dos pos compiled in harbour.
I use a star tsp100 eco futureprint for my demo system. Both work very well.
They have a network out cable though I have not tried to hook to router. This could also be a solution for your older computers.
I use a regular print procedure for these printers, which I could share with you if you like. I do not know how to achive so would
just be in a regular reply.
Franco
All The Best,
Franco
Canada
User avatar
serge_girard
Posts: 3166
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: USB Printing

Post by serge_girard »

Hi Franco,

Thanks! My older computers + printers are working fine. Except 1 which going to be replaced by a new one without parallel. So the new PC will also have a new printer: that's why I need 2 solutions. For the older ones nothing will change and the new one I will need one of the above mention solutions.
I will let you know which one (or more) will fit to my needs.

Serge
There's nothing you can do that can't be done...
Post Reply