473,695 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing directly to specialized LPT1: device in VB.NET

Tom
I am converting an old application that was printing directly to a
specialized printer device (i.e. a special label printer). It was doing this
by opening a file with the file path of 'LPT1:' and then using PRINT # to
print directly to the printer device.

Obviously, this is not going to work under VB.NET - StreamWriter won't let
you open a device like LPT1: and such. I assume I am going to have to switch
to the System.Drawing. Printing namespace to do this? And if so, is this
going to work the same way? (i.e. this printer needs special codes and such
sent to it - which my code does, but it is not a general-purpose printer).
Or is there another way to do it? And, since the users default printer may
NOT be the LPT1: device (i.e. their default printer would probably be a
network printer, with the label printer as a locally attached printer), how
do I specify that I want it to print on the printer that is connected to
LPT1:?

Thanks in advance.

Tom
Nov 20 '05 #1
5 12817
Tom
Chris: Yep, I saw that in another message after I sent my previous post.

Now my question is: Using the example to print raw data - do you know if you
can use a printer name like "LPT1:"? Or do you -HAVE- to use a specific
Windows driver/printer name?

Tom

"Chris Podmore" <Ch**********@d iscussions.micr osoft.com> wrote in message
news:6C******** *************** ***********@mic rosoft.com...
Tom,

I don't know if this will help but Herfried posted the following link in a topic with the subject 'Sending Control characters to a POS printer'.
HOW TO: Send Raw Data to a Printer by Using Visual Basic .NET
<URL:http://support.microso ft.com/?scid=kb;EN-US;322090>

Hope it helps.
Chris.

"Tom" wrote:
I am converting an old application that was printing directly to a
specialized printer device (i.e. a special label printer). It was doing this by opening a file with the file path of 'LPT1:' and then using PRINT # to print directly to the printer device.

Obviously, this is not going to work under VB.NET - StreamWriter won't let you open a device like LPT1: and such. I assume I am going to have to switch to the System.Drawing. Printing namespace to do this? And if so, is this
going to work the same way? (i.e. this printer needs special codes and such sent to it - which my code does, but it is not a general-purpose printer). Or is there another way to do it? And, since the users default printer may NOT be the LPT1: device (i.e. their default printer would probably be a
network printer, with the label printer as a locally attached printer), how do I specify that I want it to print on the printer that is connected to
LPT1:?

Thanks in advance.

Tom

Nov 20 '05 #2
Tom,

I'm not sure about talking directly to LPT1:, looking at the code it looks like it has to go through the printer driver. If you want to talk directly to LPT1: instead of the printer driver, I'm not sure how you would do that.

I did a quick search about talking to DOS devices but couldn't find anything. Sorry I wasn't much help, I hop you find an answer.

Chris.

"Tom" wrote:
Chris: Yep, I saw that in another message after I sent my previous post.

Now my question is: Using the example to print raw data - do you know if you
can use a printer name like "LPT1:"? Or do you -HAVE- to use a specific
Windows driver/printer name?

Tom

"Chris Podmore" <Ch**********@d iscussions.micr osoft.com> wrote in message
news:6C******** *************** ***********@mic rosoft.com...
Tom,

I don't know if this will help but Herfried posted the following link in a

topic with the subject 'Sending Control characters to a POS printer'.

HOW TO: Send Raw Data to a Printer by Using Visual Basic .NET
<URL:http://support.microso ft.com/?scid=kb;EN-US;322090>

Hope it helps.
Chris.

"Tom" wrote:
I am converting an old application that was printing directly to a
specialized printer device (i.e. a special label printer). It was doing this by opening a file with the file path of 'LPT1:' and then using PRINT # to print directly to the printer device.

Obviously, this is not going to work under VB.NET - StreamWriter won't let you open a device like LPT1: and such. I assume I am going to have to switch to the System.Drawing. Printing namespace to do this? And if so, is this
going to work the same way? (i.e. this printer needs special codes and such sent to it - which my code does, but it is not a general-purpose printer). Or is there another way to do it? And, since the users default printer may NOT be the LPT1: device (i.e. their default printer would probably be a
network printer, with the label printer as a locally attached printer), how do I specify that I want it to print on the printer that is connected to
LPT1:?

Thanks in advance.

Tom


Nov 20 '05 #3
Hi,

Perhaps a better solution would be to download my IONET IO control for .NET.
It is free, and permits both reading and writing to standard IO ports
(including the printer port, of course).

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
Nov 20 '05 #4
"Tom" <to*@nospam.com > wrote in message news:<ue******* *******@TK2MSFT NGP10.phx.gbl>. ..
I am converting an old application that was printing directly to a
specialized printer device (i.e. a special label printer). It was doing this
by opening a file with the file path of 'LPT1:' and then using PRINT # to
print directly to the printer device.

Obviously, this is not going to work under VB.NET - StreamWriter won't let
you open a device like LPT1: and such. I assume I am going to have to switch
to the System.Drawing. Printing namespace to do this? And if so, is this
going to work the same way? (i.e. this printer needs special codes and such
sent to it - which my code does, but it is not a general-purpose printer).
Or is there another way to do it? And, since the users default printer may
NOT be the LPT1: device (i.e. their default printer would probably be a
network printer, with the label printer as a locally attached printer), how
do I specify that I want it to print on the printer that is connected to
LPT1:?

Thanks in advance.

Tom


Hi Tom,

I'm just visiting this NG for the first time and I'm not yet a VS .NET
developer, but this is soon to change ;-)

At the moment I develop in CA-Visual Objects and have an app which, by
using several of the WinAPI functions, does some of what you need -
here is the CA-VO code to print to an UBI label-printer. The really
useful stuff is the bit entitled "Print this page" - here, the WinAPI
functions OpenPrinter, StartDocPrinter , WritePrinter, EndDocPrinter
and ClosePrinter are being used to send raw data to (in this case) a
printer attached locally to LPT1, and which has been assigned a name
via the Windows Printer setup Assistant.

If you don't wish to have to use such a name, but instead send raw
data to the port LPT1, I believe (but I haven't tried it!) that you
could use the winAPI function SetPrinter(hPri nter, dwLevel, pPrinter,
dwCommand), where the second argument (dwLevel) specifies the type of
data contained in the pPrinter argument. pPrinter is a pointer to an
array that contains one of the PRINTER_INFO_X structures, where X can
be one of 2, 3, 4, 5 or 6. Now, if dwLevel is equal to 2 (OK for Win
95 and NT+2K+XP), then the pPrinter array contains a PRINTER_INFO_2
structure and this structure contains a member pPortName, which is a
pointer to a null-terminated string that identifies the port (LPT1,
LPT2, etc.) used to transmit data to the printer. See, eg.
http://msdn.microsoft.com/library/de...tspol_13ua.asp
for more info.

HTH, Robertino
CLASS WELabel_WAPI

PROTECT oOwner AS USUAL
PROTECT aWELData AS ARRAY

PROTECT cBkgCmd, cDataCmd AS STRING
METHOD Init(oOwner, aWELData) CLASS WELabel_WAPI

SELF:oOwner := oOwner
SELF:aWELData := aWELData
RETURN SELF

METHOD Print() CLASS WELabel_WAPI
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
LOCAL cCmdString, cEinh AS STRING
LOCAL nTotalMenge, nPerPack, nInThisPack, nDiv AS FLOAT
LOCAL nLabelCount, nTotalLabels AS DWORD
LOCAL lHasSerNums AS LOGIC
lResult := FALSE
nTotalMenge := SELF:aWELData[4]
nPerPack := SELF:aWELData[5]
lHasSerNums := !Empty(SELF:aWE LData[6])
// For fractional quantities (not actually needed!!)....
IF (cEinh $ "stkpcsea") // "st", "stk", "pc", "pcs", "ea".......
IF (((nTotalMenge - Floor(nTotalMen ge)) != 0) .or. ((nPerPack -
Floor(nPerPack) ) != 0))
// Do nothing...
ELSE
// ...ditto...
ENDIF
ELSE
ENDIF

nDiv := FLOAT(nTotalMen ge) / FLOAT(nPerPack)
nTotalLabels := Ceil(nDiv)
//TEXTbox{SELF:oO wner, , "nTotalLabe ls = " +
NTrim(nTotalLab els)}:Show()

nLabelCount := 0
//nTotalLabels := 1 // Test...
DO WHILE (nLabelCount < nTotalLabels)
nLabelCount ++

IF (nTotalMenge >= nPerPack)
nInThisPack := nPerPack
ELSE
nInThisPack := nTotalMenge
ENDIF
nTotalMenge -= nInThisPack
//textbox{, , "nInThisPac k = " + NTrim(nInThisPa ck)}:Show()

SELF:SetupFormB ackground(nTota lLabels, nLabelCount)
SELF:SetupFormD ata(nInThisPack , nLabelCount)
cCmdString := SELF:cBkgCmd + SELF:cDataCmd
// Print this page.......
pszPrinter := StringAlloc(VL_ PRINTER_NAME + _chr(0))
IF OpenPrinter(psz Printer, @hPrinter, NULL)

pBuffer := StringAlloc(cCm dString + _chr(0))
pDocInfo.pDocNa me := String2Psz("Ver sand-Label")

IF StartDocPrinter (hPrinter, 1, @pDocInfo)<>0
IF WritePrinter(hP rinter, pBuffer, SLen(cCmdString ), @dwWritten)
IF (dwWritten == SLen(cCmdString ))
lResult := TRUE
END
ELSE
dwWritten := GetLastError()
END
EndDocPrinter(h Printer)
ELSE
dwWritten := GetLastError()
END
MemFree(pBuffer )
ClosePrinter(hP rinter)

ELSE
dwWritten := GetLastError()
END
MemFree(pszPrin ter)
// End print this page...

ENDDO
RETURN NIL

METHOD SetupFormBackgr ound(nTotalLabe ls, nLabelCount) CLASS
WELabel_WAPI
LOCAL cBkg, cFarb, cXRef, cYRef, cQ, cFrmBkupMode AS STRING
cQ := _chr(34)
cFarb := "N," // N="N/W", R="W/N".......
cXRef := PadL(NTrim(Floo r(Val(LABEL_X_O RIGIN) * 8)), 3, "0")
cYRef := PadL(NTrim(Floo r(Val(LABEL_Y_O RIGIN) * -8)), 3, "0")

// "Form Backup" occurs when the paper is retracted at the start of a
label -
// for longer print runs (multiple labels), we want to turn this off
until
// the last label in the print run is reached. Then turn it back on
again,
// so that the last label will be in the correct "tear-off" position.
cFrmBkupMode := Iif((nLabelCoun t < (nTotalLabels)) , "JB", "JF")
// Set up coordinates and Form (8 dots per mm.)........... .....
cBkg := cLF // Start command
structure...
cBkg += "N"+cLF // Clear image memory...
cBkg += "M117,0,0"+ cLF // All memory to Direct
Mode...
cBkg += cFrmBkupMode+cL F // Form backup-mode...
cBkg += "ZB"+cLF // Set print direction...
cBkg += "R" + cXRef + "," + cYRef +cLF // Set reference point (so
we can move whole form dynamically)...
cBkg += "q832"+cLF // Set label width
(paper-width) (104)...
cBkg += "Q440,16"+c LF // Set Form-length
(paper-height) (55) and gap-width (2)...
cBkg += "X0,0,3,800,408 "+cLF // Border rectangle
(form-width and -height) (100 * 51) to leave 2mm free all round......
cBkg += "LO0,40,800,3"+ cLF // Horizontal line 1......
cBkg += "LO0,184,800,1" +cLF // Horizontal line 2......
cBkg += "LO440,216,360, 1"+cLF // Horizontal line 3......
cBkg += "LO640,40,1,144 "+cLF // Vertical line 1....
cBkg += "LO440,184,1,22 4"+cLF // Vertical line 2....
cBkg += "I8,2,049"+ cLF // Character-set....

//TEXTBox{, , "cBkg = " + cBkg}:Show()

// Print top headers........ ............... .......
cBkg += "A16,12,0,4,1,1 ,N," + cQ + "BlahBlah GmbH, Germany" + cQ +
cLF // Print text...
cBkg += "A704,12,0,4,1, 1,N," + cQ + "C1572" + cQ + cLF
// Print text...
// Print mid headers........ ............... .......
cBkg += "A16,64,0,2,1,1 ,N,"+cQ+ "Part Number:"+cQ+cLF //
Print text...
cBkg += "A16,96,0,2,1,1 ,N,"+cQ+ "Part Name..:"+cQ+cLF //
Print text...
cBkg += "A16,128,0,2,1, 1,N,"+cQ+ "Revision...:"+ cQ+cLF // Print
text...
cBkg += "A16,160,0,2,1, 1,N,"+cQ+ "Serial No..:"+cQ+cLF //
Print text...
cBkg += "A320,160,0,2,1 ,1,N,"+cQ+ "LBA Cert.:"+cQ+cLF // Print
text...
cBkg += "A648,160,0,2,1 ,1,N,"+cQ+ "Stamp"+cQ+ cLF // Print
text...
// Print lower LH headers........ ............... .......
cBkg += "A16,270,0,2,1, 1,N,"+cQ+ "WE-Number..:"+cQ+c LF // Print
text...
cBkg += "A16,302,0,2,1, 1,N,"+cQ+ "Order No...:"+cQ+cLF // Print
text...
cBkg += "A16,334,0,2,1, 1,N,"+cQ+ "Batch No...:"+cQ+cLF // Print
text...
cBkg += "A16,366,0,2,1, 1,N,"+cQ+ "Charge No..:"+cQ+cLF // Print
text...
// Print lower RH headers........ ............... .......
cBkg += "A480,196,0,2,1 ,1,N,"+cQ+ "Limited Shelf-Life Part"+cQ+cLF
// Print text...
cBkg += "A456,248,0,2,1 ,1,N,"+cQ+ "Mfg Date....:"+cQ+c LF //
Print text...
cBkg += "A456,280,0,2,1 ,1,N,"+cQ+ "Shelf-Life..:"+cQ+cLF //
Print text...
cBkg += "A456,312,0,2,1 ,1,N,"+cQ+ "Expiry Date :"+cQ+cLF //
Print text...
cBkg += "A456,344,0,2,1 ,1,N,"+cQ+ "Storage Date:"+cQ+cLF //
Print text...

SELF:cBkgCmd := cBkg
RETURN NIL

METHOD SetupFormData(n InThisPack, nLabelCount) CLASS WELabel_WAPI
LOCAL cData, cFarb, cQ AS STRING
LOCAL cTKZ, cRev, cSNVon, cSerN, cWENum, cOrdNum, cBatch, cChargeNum,
cShLDate AS STRING
LOCAL cShLife, cMfDate, cCuDate, cWEDate, cBen AS STRING
LOCAL cZNum, cZTyp, cZJahr, cZert, cCure, cLSN, cPos AS STRING
LOCAL nDrkZahl AS BYTE
cQ := _chr(34)
cFarb := "N," // N="N/W", R="W/N".......
nDrkZahl := 1
cTKZ := SELF:aWELData[1]
cBen := SELF:aWELData[2]
cRev := SELF:aWELData[3]

cSNVon := SELF:aWELData[6]
IF !Empty(cSNVon)
cSerN := NTrim(Val(cSNVo n) + nLabelCount - 1)
ELSE
cSerN := "N/A"
ENDIF

cZert := SELF:aWELData[7]
cWENum := SELF:aWELData[8]
cOrdNum := SELF:aWELData[9]
cBatch := SELF:aWELData[10]
cChargeNum := SELF:aWELData[11]
cMfDate := SELF:aWELData[12]
cShLife := AllTrim(SELF:aW ELData[13])
cShLDate := AllTrim(SELF:aW ELData[14])
cWEDate := AllTrim(SELF:aW ELData[15])
// Print Part-Details........ ............... ..
cData += "A168,58,0,4,1, 1,"+cFarb+cQ+cT KZ+cQ+cLF // Print text...
cData += "A168,90,0,4,1, 1,"+cFarb+cQ+cB en+cQ+cLF // Print text...
cData += "A168,122,0,4,1 ,1,"+cFarb+cQ+c Rev+cQ+cLF // Print text...
cData += "A168,154,0,4,1 ,1,"+cFarb+cQ+c SerN+cQ+cLF // Print
text...
cData += "A448,154,0,4,1 ,1,"+cFarb+cQ+c Zert+cQ+cLF // Print
text...

cData += "A168,266,0,4,1 ,1,"+cFarb+cQ+c WENum+cQ+cLF // Print
text...
cData += "A168,298,0,4,1 ,1,"+cFarb+cQ+c OrdNum+cQ+cLF // Print
text...
cData += "A168,330,0,4,1 ,1,"+cFarb+cQ+c Batch+cQ+cLF // Print
text...
cData += "A168,362,0,4,1 ,1,"+cFarb+cQ+c ChargeNum+cQ+cL F // Print
text...

cData += "A620,242,0,4,1 ,1,"+cFarb+cQ+c MfDate+cQ+cLF // Print
text...
cData += "A620,274,0,4,1 ,1,"+cFarb+cQ+c ShLife+cQ+cLF // Print
text...
cData += "A620,306,0,4,1 ,1,"+cFarb+cQ+c ShLDate+cQ+cLF // Print
text...
cData += "A620,338,0,4,1 ,1,"+cFarb+cQ+c WEDate+cQ+cLF // Print
text...
// Final command to printer to print.........
cData += "P1,"+LTrim(Str (nDrkZahl))+cLF // Print contents of image
buffer...

SELF:cDataCmd := cData
RETURN NIL
Nov 20 '05 #5
Tom
Dick: Thanks! I'll give your IONET IO control a try....

Tom

"Dick Grier" <di************ **@msn.com> wrote in message
news:O$******** *****@TK2MSFTNG P12.phx.gbl...
Hi,

Perhaps a better solution would be to download my IONET IO control for ..NET. It is free, and permits both reading and writing to standard IO ports
(including the printer port, of course).

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.

Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4774
by: Fabio Pliger | last post by:
Hi! I'm using wxPython to handle my application gui.. So, I have a notebook widget and i have to print the object inside it's tab ... Maybe doing a preview before printing... I know that wx has many objects to handle printing.. i've tryied to use them, but i wasn't able to... Any hint? By now, i solved the problem saving a screenshot if the screen in an image(bmp) and then sending it to printer... (a print preview would be cool...) tnx...
2
3709
by: Marc Champagne | last post by:
Hi folks, I wish to print on pre-printed continuous forms on a dot matrix printer. My initial intent was to access to printer directly (in raw mode, somehow) in order to send whatever is necessary to do the job. I had to try... but FileOpen does not permit opening LPT1.
7
4439
by: Ritu | last post by:
Hi All, Can any body please tell me how i can write a device driver using CSharp. Thanks, Ritu
2
6145
by: Peter Rohlfs | last post by:
I'm trying to bring some code from an Access database into Visual Basic .net 2k3. The access code goes directly to LPT1 as follows ---------------------------- Open "lpt1" For Output As #1 ' Open LPT1 for output. Print #1, "^FO80,85" Print #1, "^BY3,3,1" Print #1, "^B2,60,y,n"
1
7428
by: Alexandre | last post by:
Does anybody know as printing directly in the lpt1? Tks
3
6281
by: Adam Right | last post by:
Hi, Anyone knows how to print with dot matrix printer ? I want to print text with some formatting such as bold, underlined font, and landscape document etc... How can i do this with C#? Thanks...
4
2170
by: sashalom | last post by:
Anybody able to help me about making comparison between thermal printer and ink-jet printer? For DVD Thanks
2
2071
by: Michel Vanderbeke | last post by:
Hello, How can I write directly to LPT1 and to COM1 in VB.NET 2005? Many thanks and greetings from Brugge, Michel
5
5198
by: Tony | last post by:
I have this in VB6 Open "lpt1" For Output As #1 Print #1, "abc" Close (1) How to do this in VB.NET? I am trying with FileOpen but it doesnt work. Can anyone help? Thanks
0
8568
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8982
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8845
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7660
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6491
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5839
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3003
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.