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!)
#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)
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!
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....
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 !
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