Harbour + Cobol problem printing

347 views
Skip to first unread message

Ignacio Bisi

unread,
May 2, 2020, 4:13:49 PM5/2/20
to Harbour Users
Hi. I need to build a program to print on lpt1 qrcode, codebars and data from cobol. From cobol call a program which is responsable to print the barcodes and qrcodes: This is when I call it:

OPEN OUTPUT IMPRESORA
           WRITE RECIMP FROM "Hola"
          
           CALL "SYSTEM" USING "HYDRAPRU".

This is just an example, the thing is that i need to print "Hola" and the things in HYDRAPRU in one page. Now It cant print but in two different pages. In the first page I get "hola" and in the second page y get the barcode and qrcode.
To make the barcode and qrcode I use the hbzebra library, and I try to create and send to the printer with win32prn().

Here is the problem:

function prn_init
   Public cPrinter := win_printerPortToName("LPT1")
   Public oPrn:= Win32Prn():New(cPrinter)
   
   oPrn:LandScape := .f.
   oPrn:BinNumber := 0
   oPrn:FormType := 9 // A4 form
   oPrn:Copies := 1
   
   if !oPrn:Create()
      Alert("Printer Error! check printer.")
      return
   endif
   if !oPrn:StartDoc("Hydra")
      Alert("Printer Error! check printer.")
      oPrn:Destroy()
      return
   endif
Return

I realised that when I call oPrn:StartDoc("Hydra") i'm creating a new document name and this is the reason of why the trouble is happening. But i don't know how to mix both programs to print everything in one page.

I would appreciate very much if someone contributes some help.

Thanks.


Itamar Lins

unread,
May 3, 2020, 6:56:29 PM5/3/20
to Harbour Users
Hi!
Make the all file, before of send print.
While open doc(file) via manager print, it is create a process(queue) with exclusive mode.

Best regards,
Itamar M. Lins Jr.

Ignacio Bisi

unread,
May 4, 2020, 12:54:12 AM5/4/20
to Harbour Users
Hi! Thanks for response. Do you mean append to the print queue?

Matt Johnson

unread,
May 4, 2020, 6:31:44 PM5/4/20
to harbou...@googlegroups.com
See if your barcode printer has a debug mode which prints hex codes not labels.


--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/51174cb5-67bc-4f02-b963-295dbc657efc%40googlegroups.com.

jgt

unread,
May 4, 2020, 7:01:47 PM5/4/20
to Harbour Users


 
You haven't said which cobol compiler you are using, but assuming it is either Microfocus or Gnucobol, I would first change the select statement from:
              "select printer assign to lpt1"
      to
             "select printer assign to file "testoutput"

You can then determine where the form feed is being inserted.  It is possible that the barcode is moving the print cursor to a position closer to the top of the page and thus causing a form feed.
Are you using PCL5 escape sequence or Postscript?

Ignacio Bisi

unread,
May 5, 2020, 8:40:49 AM5/5/20
to Harbour Users
Hi! i'm using RM/Cobol-85 and have no trouble when i'm printing. I used PCL before this code to print only barcodes. Now I can create QR i'm usin HBZEBRA library. And this library needs a printer object to draw them. And when I see que printer queue I se this:


Screen Shot 2020-05-05 at 09.31.56.png

Where "Local Downlevel Documents" are the data printer from Cobol and Documento, the qr and barcode. So I don't think that this is a problem about the position of the print cursor. The function hb_zebra_draw() needs a printer object to work, maybe is there where the problem is.

Here is the full code of harbour:



#include "hbzebra.ch"
#include "hbwin.ch"
#include "ct.ch"
REQUEST HB_CODEPAGE_DEWIN
*******************************************************************************************************************
Procedure Main
parameter numero
Local import,cant,dec,idcli,cant2,numfac,cantfac,a, id1, id2,import2
Local tocut := {}
Local to3 := {}
Local to2 := {}
Local qr2 := {}
Local qr1 := {}
tocut := hb_ValToStr(numero)
to2 := AllTrim(SubStr(tocut,2,28))
to3 := AllTrim(SubStr(tocut,31,28))
id1 := AllTrim(Substr(tocut,1,1))
id2 := AllTrim(Substr(tocut,30,1))
prn_init()
oPrn:SetFont( "Courier New", 7, { 3, -50 } )
if id1 == "a"
** Formato
qr1 := "000201"
** Metodo de inicio
qr1 := qr1 + "010212"
** Moneda de la TX
qr1 := qr1 + "5303032"
** Importe de la TX
** numero factura + id cliente
numfac := SubStr(tocut,13,7)
numfac := AllTrim(Str(val(numfac)))
cantfac := AllTrim(str(len(numfac)))
idcli := SubStr(tocut, 6, 7)
idcli := AllTrim(Str(val(idcli)))
cant2 := AllTrim(str(len(idcli)))
qr1 := qr1 + "620201"
mk_qrcode(qr1,755,397)
EanBarCode(oPrn,187,50,1,to2,HB_ZEBRA_FLAG_CHECKSUM)
oPrn:TextOutAt(500, 1600, "*" +to2+ "*")
endif
if id1 == "b"
** Formato
qr1 := "000201"
** Metodo de inicio
qr1 := qr1 + "010212"
** Moneda de la TX
qr1 := qr1 + "5303032"
** Importe de la TX
** numero factura + id cliente
numfac := SubStr(tocut,13,7)
numfac := AllTrim(Str(val(numfac)))
cantfac := AllTrim(str(len(numfac)))
idcli := SubStr(tocut, 6, 7)
idcli := AllTrim(Str(val(idcli)))
cant2 := AllTrim(str(len(idcli)))
qr1 := qr1 + "620201"
EanBarCode(oPrn,187,50,1,to2,HB_ZEBRA_FLAG_CHECKSUM)
oPrn:TextOutAt(500, 1600, "*" +to2+ "*")
EanBarCode(oPrn,650,423,1,to2,HB_ZEBRA_FLAG_CHECKSUM)
mk_qrcode(qr1,755,397)
oPrn:TextOutAt(3160, 4930, "*" +to2+ "*")
endif
prn_exit()
Return
*******************************************************************************************************************
Function mk_qrcode(ccString, posx, posy)
// ChecoCode for C....
local qr_arr := {}
local i
for i = 1 to 5
intpos := at(",",ccString)
t_string := substr(ccString,1,intpos-1)
aadd(qr_arr,t_string)
ccString := right(ccString,len(ccString)-intpos)
next i
qr_feld01 := ccString // Service
qr_feld02 := "" // Version
qr_string := qr_feld01+chr(10)+qr_feld02+chr(10)
qr_string := hb_strToUTF8(qr_string,"DEWIN")
if len(qr_string) >= 330
alert("QR Code String to long: "+str(len(qr_string)))
else
EanQRCode(oPrn,posx,posy,1.5,qr_string,HB_WIN_RGB_BLACK,HB_ZEBRA_FLAG_QR_LEVEL_M)
endif
RETURN NIL
*******************************************************************************************************************
Function EanQRCode(coPRN, nY, nX, nWidth, nQRCODE, nColor,iFlags)
Local hCODE,nRET
Local nLineWidth:=IIF(nWidth==NIL .OR. nWidth<1,1,nWidth)
Local nLineHeight:=nLineWidth
Local nSCALE:=7.2
hCODE:=hb_zebra_create_qrcode(nQRCODE,iFlags)
nY *= nSCALE
nLineWidth *= nSCALE
IF hCODE != NIL
IF hb_zebra_geterror( hCODE ) == 0
IF Empty( nLineHeight )
nLineHeight := 16
ENDIF
IF hb_zebra_geterror( hCODE ) != 0
RETURN HB_ZEBRA_ERROR_INVALIDZEBRA
Endif
nRET:=hb_zebra_draw( hCODE, {|x,y,w,h| coPRN:FillRect(Int( x + .5 ), Int( y + .5 ),;
Int( x + .5 ) + Int( w ), Int( y + .5 ) + Int( h ) + 1,nColor) },;
nX*nSCALE, nY, nLineWidth, nLineHeight*nSCALE )
Endif
hb_zebra_destroy( hCODE )
Endif
Return nRET
*************************************************************************************************************************
function prn_init
Public cPrinter := win_printerPortToName("LPT1")
Public oPrn:= Win32Prn():New(cPrinter)
oPrn:LandScape := .f.
oPrn:BinNumber := 0
oPrn:FormType := 9 // A4 form
oPrn:Copies := 1
if !oPrn:Create()
Alert("Printer Error! check printer.")
return
endif
if !oPrn:StartDoc()
Alert("Printer Errosr! check printer.")
oPrn:Destroy()
return
endif
Return
*******************************************************************************************************************
Function prn_exit
oPrn:EndDoc() // call endpage() at least one time
oPrn:Destroy()
Return Nil
*******************************************************************************************************************
*******************************************************************************************************************
Function EanBarCode(coPRN, nY, nX, nWidth, cod39,iFlags)
Local hCODE,nRET
Local nLineWidth:=IIF(nWidth==NIL .OR. nWidth<1,1,nWidth)
Local nLineHeight:= 24
Local nSCALE:=7.2
hCODE:=hb_zebra_create_code128(cod39,iFlags)
nY *= nSCALE
nLineWidth *= nSCALE
IF hCODE != NIL
IF hb_zebra_geterror( hCODE ) == 0
IF Empty( nLineHeight )
nLineHeight := 16
ENDIF
IF hb_zebra_geterror( hCODE ) != 0
RETURN HB_ZEBRA_ERROR_INVALIDZEBRA
Endif
nRET:=hb_zebra_draw( hCODE, {|x,y,w,h| coPRN:FillRect(Int( x + .5 ), Int( y + .5 ),;
Int( x + .5 ) + Int( w ), Int( y + .5 ) + Int( h ) + 1) },;
nX*nSCALE, nY, nLineWidth, nLineHeight*nSCALE )
Endif
hb_zebra_destroy( hCODE )
Endif
Return nRET
*************************************************************************************************************************



jgt

unread,
May 5, 2020, 12:22:02 PM5/5/20
to Harbour Users


Let me first qualify my answer by saying that I have over 30 years experience with Cobol, Foxpro 2.6, SCO Unix and Linux, and a year or two with Harbour.  I have almost no experience with MSDOS or MS Windows.
I believe that MS Windows only emulates LPT1, and does not actually allow user direct access to the device, so what happens is that the Cobol program opens a print stream, writes a line, then the Harbour program opens a print stream, writes a qr-code, and closes the print stream, then returns to the Cobol program which doesn't seem to notice that its print stream has been hijacked.

Assuming that you a printing a document (invoice?), I would be inclined to print the entire document in either the Cobol program or the Harbour program.
Since Cobol does not handle objects as well as Harbour, I would create an array in Cobol to hold the entire page of data:
                   01 invoice-page.
                        03 pr-line pic x(80) occurs 60.
then
                  call system using 'HYDRAPRU' invoice-page
and remove the print file from the Cobol program.

Jack

jgt

unread,
May 5, 2020, 12:48:56 PM5/5/20
to Harbour Users
If you don't like the above, you might consider switching to Gnucobol  as it has an IDE and is free and it also is like Harbour in that it converts Cobol source to C and then compiles the C.
Reply all
Reply to author
Forward
0 new messages