From: Paulus Peus on
Hello Gerhard,

Thanks, this does the trick.


> Paulus,
>
> have not tested this with Vista, but I'm sure it will work. There is
> also no need for redirecting some ports. You can send your
> LowLevel-String to every installed and working printer (LPT, USB,
> Serial, Network, ...)
>
> Create your String to print:
>
> cText := StrEvaluate(&sreset )
> cText += StrEvaluate(&sInit )
> cText += StrEvaluate(&sT080)
> DO WHILE TRUE
> // filling an array with text of fields to be printed
> aDoorgeef[1]:= "License: "+oZerver:FIELDGET(#VERG_NR)
> aDoorgeef[2]:= " " // empty row
> aDoorgeef[3]:= "Name : "+oZerver:FIELDGET(#NAAM)
> aDoorgeef[4]:= "Adress : "+oZerver:FIELDGET(#ADRES)
> // writing the array to the handle
> FOR j=1 TO Len(aDoorgeef)
> cText += aDoorgeef[j]+StrEvaluate(&cCRLF)
> NEXT j
> // checking the EOF
> IF !oZerver:EOF ; oZerver:Skip(); ENDIF
> IF oZerver:EOF; EXIT; ENDIF
> ENDDO
> oZerver:Close()
> and send this String directly to the Printer:
>
> cMyPrinter := 'The Name of your installed printer' // e.g.
> '\\server01\HP LaserJet 1022n'
> WriteData2Printer(cMyPrinter, cText)
> FUNCTION WriteData2Printer (cPrinter AS STRING, cData AS STRING) AS
> LOGIC
> PASCAL
> LOCAL lResult AS LOGIC
> LOCAL hPrinter AS PTR
> LOCAL pszPrinter AS PSZ
> LOCAL pBuffer AS PTR
> LOCAL dwWritten AS DWORD
> LOCAL pDocInfo IS _winDoc_Info_1
> // Default (@cPrintJobName, "PrinterSpooler Document")
>
> /***** from MSDN
> The SEQUENCE FOR a print job IS AS follows:
> 1. TO BEGIN a print job, CALL StartDocPrinter.
> 2. TO BEGIN each page, CALL StartPagePrinter.
> 3. TO write data TO a page, CALL WritePrinter.
> 4. TO END each page, CALL EndPagePrinter.
> 5. Repeat 2, 3, and 4 FOR AS many pages AS necessary.
> 6. TO END the print job, CALL EndDocPrinter.
> *****************/
> lResult := FALSE
> pszPrinter := StringAlloc(cPrinter + _CHR(0))
> IF OpenPrinter(pszPrinter, @hPrinter, NULL)
> pBuffer := StringAlloc(cData + _CHR(0))
> pDocInfo.pDocName := String2Psz("PrinterSpooler Document")
> pDocInfo.pOutPutFile := NULL_PSZ // String2Psz (NULL_STRING)
> pDocInfo.pDatatype := String2Psz ("RAW")
> IF StartDocPrinter(hPrinter, 1, @pDocInfo) <> 0
> // IF StartPagePrinter(hPrinter)
> IF WritePrinter(hPrinter, pBuffer, SLen(cData), @dwWritten)
> IF dwWritten == SLen(cData)
> lResult := TRUE
> ENDIF
> ELSE
> dwWritten := GetLastError()
> ENDIF
> // EndPagePrinter(hPrinter)
> // ENDIF
> EndDocPrinter(hPrinter)
> ELSE
> dwWritten := GetLastError()
> ENDIF
> ClosePrinter(hPrinter)
> MemFree(pBuffer)
> ELSE
> dwWritten := GetLastError()
> ENDIF
> MemFree(pszPrinter)
> RETURN lResult
>
> HTH
>
> Gerhard
>
> "Paulus Peus" <ptgm.janssen(a)hetnet.nl> schrieb im Newsbeitrag
> news:596f1d19258cc2e05e0170dde(a)news.online.nl...
>
>> I Know, you all think I should better use a Windows printerdrive,
>> instead
>> of good-old Dos printing.
>> OK, I will considerate that if anyone can tell me how to print labels
>> one-by-one on my matrixprinter. Windows always throughs out a A4 page
>> after printing one label. So I have to turn back the chained labels.
>> I
>> find it not posible to print just one label and then a printerstop,
>> so no
>> paper is ejected.
>> But this is my problem (a year ago already posted, but no answer
>> found):
>> In VO I want to print to an usb-port with a usb-matrix printer (or
>> with
>> USB2LPT cable on an LPT-matrixprinter).
>> From the computer I try to send an escape sequence to the printer, to
>> set
>> the printer with the right character.
>> (I can do that by redirecting the LPT-port to an usb, shared printer,
>> via
>> Net Use command.)
>> So far so good ...under XP.
>> To pay attention to:
>> 1) use the Microsoft Loopback Adapter in case of no network detected.
>> 2) use the correct USB-port on the computer to which the printer is
>> redirected:
>> it mathers which usb-port to fysical connect to with your usb-printer
>> or
>> USB2LPT-cable!
>> Unter Vista: no printer respons what so ever. Printing from a
>> windows-application
>> is no problem, but low level printing from VO: no way.
>> VISTA IS BLOCKING LOWLEVEL (Esc-codes) TO BE SENT TO THE PRINTER!
>> ===========================================================
>> || CAN ANYONE TELL ME HOW TO SOLVE THIS VISTA-PROBLEM? ||
>> ===========================================================
>> This is how I tell the printer what to do from VO:
>>
>> FUNCTION LPT_printing
>> (...) // leaving out the uninteresting part
>> // Define the Linefeed-Carriage-return
>> cCRLF:="CHR(13)+CHR(10)"
>> // open a handle form dos-printing
>> nHandle := FOpen2( "LPT1.DOS", FO_WRITE)
>> // here I write some Escape-code to the printer, to select the
>> character-settings
>> // &... is a macrosubstitution for escapecodes, loaded from my driver
>> files
>> FWrite( nHandle, StrEvaluate(&sreset )) FWrite( nHandle,
>> StrEvaluate(&sInit ))
>> FWrite( nHandle, StrEvaluate(&sT080))
>> DO WHILE TRUE
>> // filling an array with text of fields to be printed
>> aDoorgeef[1]:= "License: "+oZerver:FIELDGET(#VERG_NR)
>> aDoorgeef[2]:= " " // empty row
>> aDoorgeef[3]:= "Name : "+oZerver:FIELDGET(#NAAM)
>> aDoorgeef[4]:= "Adress : "+oZerver:FIELDGET(#ADRES)
>> // writing the array to the handle
>> FOR j=1 TO Len(aDoorgeef)
>> FWrite( nHandle, aDoorgeef[j]+StrEvaluate(&cCRLF) )
>> NEXT j
>> // checking the EOF IF !oZerver:EOF ; oZerver:Skip(); ENDIF
>> IF oZerver:EOF; EXIT; ENDIF
>> ENDDO
>> oZerver:Close()
>> FClose( nHandle)
>> RETURN


 | 
Pages: 1
Prev: Dispatch & Control
Next: How to solve memory leak