SET PRINTER TO LPT1

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

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

SET PRINTER TO LPT1

Post by serge_girard »

Hello,

Somebody has a solution for this problem:

Code: Select all

SET PRINTER TO LPT1
SET DEVICE  TO PRINTER
SET PRINTER ON  

WZP := '027007' // instructions for opening a cash drawer
WZT := 0
TEL := 1
DO WHILE LEN(SUBSTR(ALLTRIM(WZP),TEL,3)) > 0
   WZT := VAL(((SUBSTR(WZPRINTER,TEL,3))))
   ? CHR(WZT)
   TEL := TEL+3
ENDDO

SET PRINTER OFF
SET PRINTER TO
SET DEVICE  TO SCREEN
SET CONSOLE ON
When the cash drawer is connected to the power supply everything works fine. Sometimes set power supply ON is forgotten and my program will HANG (at SET PRINTER TO LPT1) "forever" untill power is switched on. I need to be able to show a message saying something like: "switch power on!".

PRINTREADY(1) has no effect!

Cash drawer is connected to EPSON ticket printer (this one supplies POWER and is sometimes forgotten!)

Serge
There's nothing you can do that can't be done...
User avatar
danielmaximiliano
Posts: 2611
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: SET PRINTER TO LPT1

Post by danielmaximiliano »

Try ISPRINTER () -> lReady
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: SET PRINTER TO LPT1

Post by serge_girard »

Thanks Daniel, but this does not works always! Very strange!

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

Re: SET PRINTER TO LPT1

Post by edk »

Serge, check it:

Code: Select all

#include "hmg.ch"

Function Main()
Local cPort := "LPT1"
Local fdes, nRetMsg
Local lIsReady, nChar

Msgbox ( 'Checking ' + cPort )

DO WHILE .T.
	fdes := FCreate (cPort, 2 )
	IF fdes = -1 	//not ready
		lIsReady := .F.
		IF !MsgRetryCancel ( "ERROR #" + AllTrim(Str( FError())) + " " + ErrStatPrn( FError() ) , "Error" )
			FClose (fdes)
			EXIT
		ENDIF
	ELSE
		lIsReady := .T.
		FClose (fdes)
		EXIT
	ENDIF
ENDDO

Msginfo ( cPort + " is " + IF(!lIsReady, "NOT ready.", "ready."))

IF lIsReady
	aSend:={027,007}
	fdes := FCreate (cPort, 2 )
	FOR EACH nChar IN aSend
		FWRITE(fdes, Chr( nChar), 1)
	NEXT 
	FClose (fdes)
ENDIF
RETURN
*******************************************************
FUNCTION ErrStatPrn( nErr )
Local cDesc:='Other error'
SWITCH nErr 
CASE 2
	cDesc:='Device not found'
	EXIT
CASE 5
	cDesc:='Access denied'
	EXIT
CASE 21
	cDesc:='Device not ready'
	EXIT
CASE 23
	cDesc:='Data error (CRC)'
	EXIT
CASE 28
	cDesc:='Printer out of paper'
	EXIT
CASE 29
	cDesc:='Write fault'
	EXIT
CASE 33
	cDesc:='Lock violation'
	EXIT
CASE 53
	cDesc:='Network name not found'
	EXIT
CASE 61
	cDesc:='Print queue full'
	EXIT
CASE 63
	cDesc:='Print file deleted (not enough space)'
	EXIT
CASE 67
	cDesc:='Network name not found'
	EXIT
ENDSWITCH
RETURN cDesc

Make sure to create a queue for the LPT1 port in the Windows system. The easiest way is to add a Generic Text Only printer on the LPT1 port and set a short timeout e.g. 5 seconds instead of the default 90 seconds (you can set it in the properties of the LPT1 printer port)

Let me know if it works for you.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: SET PRINTER TO LPT1

Post by serge_girard »

Strangely enough not working !

I test on a stand-alone PC with W7, nothing connected, no printers. It gives: LPT1 is ready
Other PC with W7, printer attached, power OFF, gives LPT1 is NOT ready!

I will try on other W10 machine, later!

Thx, Serge
There's nothing you can do that can't be done...
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: SET PRINTER TO LPT1

Post by serge_girard »

On my W10 nothing connected, no printers. It gives: LPT1 is ready !
So printing to it will result in hang-up until PRINTER is switched on OR close application by taskmanager OR TSKILL....

Any idea how to solve?

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

Re: SET PRINTER TO LPT1

Post by edk »

Maybe this will works:

Code: Select all

#include "hmg.ch"

Function Main()
Local cPort := "LPT1:"
Local cPrinterName:=""
Local lIsReady, nChar, aSend

Msgbox ( 'Checking ' + cPort )
cPrinterName := WIN_PRINTERPORTTONAME( cPort)
IF EMPTY(cPrinterName)
	MsgStop ('There is no any printer installed on port ' +cPort)
	lIsReady:=.F.
ELSE
	Msgbox ( 'Found printer ' +cPrinterName+ ' on port ' + cPort )
	DO WHILE .T.
		nWinStat:=win_printerStatus(cPrinterName)
		IF nWinStat#0
			lIsReady := .F.
			IF !MsgRetryCancel ( decRAWerror(nWinStat), "Status" )
				EXIT
			ENDIF
		ELSE
			lIsReady := .T.
			EXIT
		ENDIF
	ENDDO
ENDIF

Msginfo ( cPort + " is " + IF(!lIsReady, "NOT ready.", "ready."))

IF lIsReady
	aSend:={027,007}
	fdes := FCreate (cPort, 2 )
	FOR EACH nChar IN aSend
		FWRITE(fdes, Chr( nChar), 1)
	NEXT 
	FClose (fdes)
ENDIF
RETURN
*******************************************************
FUNCTION decRAWerror(nErr)
SWITCH nErr
	CASE 0x00000200      ; RETURN "BUSY"; EXIT
	CASE 0x00400000      ; RETURN "DOOR_OPEN"; EXIT
	CASE 0x00000002      ; RETURN "ERROR ON PRINTER"; EXIT
	CASE 0x00008000      ; RETURN "INITIALIZING"; EXIT
	CASE 0x00000020      ; RETURN "MANUAL_FEED"; EXIT
	CASE 0x00001000      ; RETURN "NOT_AVAILABLE"; EXIT
	CASE 0x00040000      ; RETURN "NO_TONER"; EXIT
	CASE 0x00000080      ; RETURN "OFFLINE"; EXIT
	CASE 0x00000800      ; RETURN "OUTPUT_BIN_FULL"; EXIT
	CASE 0x00200000      ; RETURN "OUT_OF_MEMORY"; EXIT
	CASE 0x00080000      ; RETURN "PAGE_PUNT"; EXIT
	CASE 0x00000008      ; RETURN "PAPER_JAM"; EXIT
	CASE 0x00000010      ; RETURN "PAPER_OUT"; EXIT
	CASE 0x00000040      ; RETURN "PAPER_PROBLEM"; EXIT
	CASE 0x00000001      ; RETURN "PAUSED"; EXIT
	CASE 0x00000004      ; RETURN "PENDING_DELETION"; EXIT
	CASE 0x01000000      ; RETURN "POWER_SAVE"; EXIT
	CASE 0x00000400      ; RETURN "PRINTING"; EXIT
	CASE 0x00004000      ; RETURN "PROCESSING"; EXIT
	CASE 0x02000000      ; RETURN "SERVER_OFFLINE"; EXIT
	CASE 0x00800000      ; RETURN "SERVER_UNKNOWN"; EXIT
	CASE 0x00020000      ; RETURN "TONER_LOW"; EXIT
	CASE 0x00100000      ; RETURN "USER_INTERVENTION"; EXIT
	CASE 0x00002000      ; RETURN "WAITING"; EXIT
	CASE 0x00010000      ; RETURN "WARMING_UP"; EXIT
ENDSWITCH

RETURN "ERROR "+hb_ValToStr(nErr)
*****************************************
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: SET PRINTER TO LPT1

Post by serge_girard »

This looks fine and seems to work!

I will test on other machines before celebrating too soon..
Because I have no printers attached it must give 'There is no any printer installed on port '
And it does !

Edward, thanks again!!!

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

Re: SET PRINTER TO LPT1

Post by franco »

Serge, I use star receit printers. Every time I print and a want to open the drawer I send a chr(7) print command.
There is a telephone looking cord from printer to cash drawer.
I have not tried this since changing to hmg from clipper, I do not have a cash drawer to try right now but something in the
back of my mind there`s another character you have to send after chr(7)+chr?.. If 7 does not work let me know, I could dig.
All the best,
Franco
All The Best,
Franco
Canada
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: SET PRINTER TO LPT1

Post by serge_girard »

Thanks Franco, for the time being the above solution works fine. I don't have such printer and cash drawer by myself so testing is rather complicated.

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