473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using generic printer

Hello,

Is there a way to send a string of text to a generic tekst printer under
..NET.
Somethings as in the good old days
File f = Open("LPT1");
f.Writeline("Blablabla");

The goal is to use an old lineprinter as a log printer printing out each
line (incomming allert) at a time without having to build a whole page
before printing.

Greets,

Jean Paul
Aug 8 '06 #1
7 4445
Jean Paul,

What you can do is call the CreateFile API function through the P/Invoke
layer. This will allow you to specify "LPT1", and give you a handle to that
printer.

Then, you can pass that handle to the FileStream class and use that
instance to write to the port.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jean Paul Mertens" <ON****@newsgroups.nospamwrote in message
news:eo**************@TK2MSFTNGP03.phx.gbl...
Hello,

Is there a way to send a string of text to a generic tekst printer under
.NET.
Somethings as in the good old days
File f = Open("LPT1");
f.Writeline("Blablabla");

The goal is to use an old lineprinter as a log printer printing out each
line (incomming allert) at a time without having to build a whole page
before printing.

Greets,

Jean Paul

Aug 8 '06 #2
Nicholas,

I'l give it a try.

tnx
JP

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comschreef
in bericht news:Ow****************@TK2MSFTNGP05.phx.gbl...
Jean Paul,

What you can do is call the CreateFile API function through the
P/Invoke layer. This will allow you to specify "LPT1", and give you a
handle to that printer.

Then, you can pass that handle to the FileStream class and use that
instance to write to the port.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jean Paul Mertens" <ON****@newsgroups.nospamwrote in message
news:eo**************@TK2MSFTNGP03.phx.gbl...
>Hello,

Is there a way to send a string of text to a generic tekst printer under
.NET.
Somethings as in the good old days
File f = Open("LPT1");
f.Writeline("Blablabla");

The goal is to use an old lineprinter as a log printer printing out each
line (incomming allert) at a time without having to build a whole page
before printing.

Greets,

Jean Paul


Aug 8 '06 #3
It is certainly possible, although it is not necessarily advisable. Printers
are accessed via their drivers, and for good reason. Assuming that you have
an old dot matricx printer that works, and it can print out text sent to it
directly, you can certainly open the LPT port and write to it.

However, as I said, that's not necessarily the best idea. It's hard to know
without knowing your actual requirements. Your concept of logging is rather
bizarre. A long time ago, logging was done this way, because it was the only
way possible. But putting data onto paper is both expensive in terms of
resources used (paper, ink, etc), and processor overhead (because printing
is a high priority process). In addition, paper has its purposes, but
storage of information is hardly one of them. You can store beaucoups more
information in a much smaller (and more reliable) form on a computer, a
disk, or a CD/DVD. If you do not want to store it, why are you printing it
to a permanent (and large) storage medium?

Can you provide some more of the reasons behind this odd approach?

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Expect the unaccepted.

"Jean Paul Mertens" <ON****@newsgroups.nospamwrote in message
news:eo**************@TK2MSFTNGP03.phx.gbl...
Hello,

Is there a way to send a string of text to a generic tekst printer under
.NET.
Somethings as in the good old days
File f = Open("LPT1");
f.Writeline("Blablabla");

The goal is to use an old lineprinter as a log printer printing out each
line (incomming allert) at a time without having to build a whole page
before printing.

Greets,

Jean Paul

Aug 8 '06 #4
Hey Kevin,

One of the main reasons to log on paper is the juridical value of the paper.
We are a garage and by example the law is still requesting that the selling
of gas oil has to be registered in real time directly on paper. Also the
entrance and the leave of a car in the garage has to be registered on a
paper carrier.

An other good reason to log on paper is, if you log only important events on
the paper, that it is more fasten to control. If I log my backup events in
the application logbook it is certainly fine but most of the time my backup
runs without any problem. On the server there are so many application events
that most of the time one only inspect this logbook when there is really a
known problem. I have five servers running and so real problem events can
hide in the mass. If now there is a real problem with a backup on one of the
machines and I send this event to the log printer it just need a quick
inspect in the morning and if I see an error message between the lines of
selling gas oil and registering the cars, it is seen directly and can be
corrected.

And a third reason is that one can easy centralize debug information. It's a
habit I inherited from my VAX time writing in Fortran and Assembler having
merely no debuggers (we only had crashdumps, if you ever analyzed one you
know what I mean). So when an error or a certain event occurs and you can
send this to a printer from wherever on the network, it reconstructs better
and helps on tracking problems.

If you restrict to one line logging and only relevant items you nearly use
one box of paper a year. So that's not a reason to not doing it.

About storing logs to a digital medium; can you still read 8" disks... so I
have to go to the museum for inspecting my logs what with CD's in ten or
fifty years... but I can still read the papers of the middle ages. And I am
sure that those people would wonder why one should, for God shake, be
interested a 1,000 years later in what they wrote on a sheet of paper.

CU
JP

"Kevin Spencer" <uc*@ftc.govschreef in bericht
news:%2***************@TK2MSFTNGP05.phx.gbl...
It is certainly possible, although it is not necessarily advisable.
Printers are accessed via their drivers, and for good reason. Assuming
that you have an old dot matricx printer that works, and it can print out
text sent to it directly, you can certainly open the LPT port and write to
it.

However, as I said, that's not necessarily the best idea. It's hard to
know without knowing your actual requirements. Your concept of logging is
rather bizarre. A long time ago, logging was done this way, because it was
the only way possible. But putting data onto paper is both expensive in
terms of resources used (paper, ink, etc), and processor overhead (because
printing is a high priority process). In addition, paper has its purposes,
but storage of information is hardly one of them. You can store beaucoups
more information in a much smaller (and more reliable) form on a computer,
a disk, or a CD/DVD. If you do not want to store it, why are you printing
it to a permanent (and large) storage medium?

Can you provide some more of the reasons behind this odd approach?

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Expect the unaccepted.

"Jean Paul Mertens" <ON****@newsgroups.nospamwrote in message
news:eo**************@TK2MSFTNGP03.phx.gbl...
>Hello,

Is there a way to send a string of text to a generic tekst printer under
.NET.
Somethings as in the good old days
File f = Open("LPT1");
f.Writeline("Blablabla");

The goal is to use an old lineprinter as a log printer printing out each
line (incomming allert) at a time without having to build a whole page
before printing.

Greets,

Jean Paul


Aug 9 '06 #5
Good enough, Jean Paul!

At any rate, I see that your question has been more specifically answered
already. Let me know if you need any more specific information.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Expect the unaccepted.

"Jean Paul Mertens" <ON****@newsgroups.nospamwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hey Kevin,

One of the main reasons to log on paper is the juridical value of the
paper. We are a garage and by example the law is still requesting that the
selling of gas oil has to be registered in real time directly on paper.
Also the entrance and the leave of a car in the garage has to be
registered on a paper carrier.

An other good reason to log on paper is, if you log only important events
on the paper, that it is more fasten to control. If I log my backup events
in the application logbook it is certainly fine but most of the time my
backup runs without any problem. On the server there are so many
application events that most of the time one only inspect this logbook
when there is really a known problem. I have five servers running and so
real problem events can hide in the mass. If now there is a real problem
with a backup on one of the machines and I send this event to the log
printer it just need a quick inspect in the morning and if I see an error
message between the lines of selling gas oil and registering the cars, it
is seen directly and can be corrected.

And a third reason is that one can easy centralize debug information. It's
a habit I inherited from my VAX time writing in Fortran and Assembler
having merely no debuggers (we only had crashdumps, if you ever analyzed
one you know what I mean). So when an error or a certain event occurs and
you can send this to a printer from wherever on the network, it
reconstructs better and helps on tracking problems.

If you restrict to one line logging and only relevant items you nearly use
one box of paper a year. So that's not a reason to not doing it.

About storing logs to a digital medium; can you still read 8" disks... so
I have to go to the museum for inspecting my logs what with CD's in ten
or fifty years... but I can still read the papers of the middle ages. And
I am sure that those people would wonder why one should, for God shake, be
interested a 1,000 years later in what they wrote on a sheet of paper.

CU
JP

"Kevin Spencer" <uc*@ftc.govschreef in bericht
news:%2***************@TK2MSFTNGP05.phx.gbl...
>It is certainly possible, although it is not necessarily advisable.
Printers are accessed via their drivers, and for good reason. Assuming
that you have an old dot matricx printer that works, and it can print out
text sent to it directly, you can certainly open the LPT port and write
to it.

However, as I said, that's not necessarily the best idea. It's hard to
know without knowing your actual requirements. Your concept of logging is
rather bizarre. A long time ago, logging was done this way, because it
was the only way possible. But putting data onto paper is both expensive
in terms of resources used (paper, ink, etc), and processor overhead
(because printing is a high priority process). In addition, paper has its
purposes, but storage of information is hardly one of them. You can store
beaucoups more information in a much smaller (and more reliable) form on
a computer, a disk, or a CD/DVD. If you do not want to store it, why are
you printing it to a permanent (and large) storage medium?

Can you provide some more of the reasons behind this odd approach?

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Expect the unaccepted.

"Jean Paul Mertens" <ON****@newsgroups.nospamwrote in message
news:eo**************@TK2MSFTNGP03.phx.gbl...
>>Hello,

Is there a way to send a string of text to a generic tekst printer under
.NET.
Somethings as in the good old days
File f = Open("LPT1");
f.Writeline("Blablabla");

The goal is to use an old lineprinter as a log printer printing out each
line (incomming allert) at a time without having to build a whole page
before printing.

Greets,

Jean Paul



Aug 9 '06 #6
To all,

If ever one is interested doing the same here is my solution

Greets and succes

JP

[Code snipset...]
public class ErrorPrinter : MarshalByRefObject

{

public ErrorPrinter()

{

}

const uint GENERIC_READ = 0x80000000;

const uint GENERIC_WRITE = 0x40000000;

const uint OPEN_EXISTING = 3;

[DllImport("kernel32.dll", SetLastError = true)]

static extern SafeFileHandle CreateFile(string lpFileName, uint
dwDesiredAccess,

uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition,

uint dwFlagsAndAttributes, IntPtr hTemplateFile);
public void LPrint(string msg)

{

Console.WriteLine("Message is: {0}", msg);

SafeFileHandle handleValue = null;

string toPrint = string.Format("{0:dd/MM/yy hh:mm:ss}: {1}\n",DateTime.Now,
msg);

// open LPT1 for Writing

handleValue = CreateFile("LPT1:", GENERIC_WRITE, 0, IntPtr.Zero,
OPEN_EXISTING, 0, IntPtr.Zero);
if (handleValue.IsInvalid)

return ;
FileStream f = new FileStream(handleValue, FileAccess.Write);

byte[] buffer = Encoding.ASCII.GetBytes(toPrint);

f.Write(buffer, 0, buffer.Length);

f.Flush();

f.Close();

}

}

[End Code Snipset...]
"Kevin Spencer" <uc*@ftc.govschreef in bericht
news:uL**************@TK2MSFTNGP03.phx.gbl...
Good enough, Jean Paul!

At any rate, I see that your question has been more specifically answered
already. Let me know if you need any more specific information.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Expect the unaccepted.

Aug 9 '06 #7
Nice work! Tres bien!

--

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Accept the Unexpected.

"Jean Paul Mertens" <ON****@newsgroups.nospamwrote in message
news:OY*************@TK2MSFTNGP05.phx.gbl...
To all,

If ever one is interested doing the same here is my solution

Greets and succes

JP

[Code snipset...]
public class ErrorPrinter : MarshalByRefObject

{

public ErrorPrinter()

{

}

const uint GENERIC_READ = 0x80000000;

const uint GENERIC_WRITE = 0x40000000;

const uint OPEN_EXISTING = 3;

[DllImport("kernel32.dll", SetLastError = true)]

static extern SafeFileHandle CreateFile(string lpFileName, uint
dwDesiredAccess,

uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition,

uint dwFlagsAndAttributes, IntPtr hTemplateFile);
public void LPrint(string msg)

{

Console.WriteLine("Message is: {0}", msg);

SafeFileHandle handleValue = null;

string toPrint = string.Format("{0:dd/MM/yy hh:mm:ss}:
{1}\n",DateTime.Now, msg);

// open LPT1 for Writing

handleValue = CreateFile("LPT1:", GENERIC_WRITE, 0, IntPtr.Zero,
OPEN_EXISTING, 0, IntPtr.Zero);
if (handleValue.IsInvalid)

return ;
FileStream f = new FileStream(handleValue, FileAccess.Write);

byte[] buffer = Encoding.ASCII.GetBytes(toPrint);

f.Write(buffer, 0, buffer.Length);

f.Flush();

f.Close();

}

}

[End Code Snipset...]
"Kevin Spencer" <uc*@ftc.govschreef in bericht
news:uL**************@TK2MSFTNGP03.phx.gbl...
>Good enough, Jean Paul!

At any rate, I see that your question has been more specifically answered
already. Let me know if you need any more specific information.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Expect the unaccepted.


Aug 9 '06 #8

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

Similar topics

11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
0
by: a_man | last post by:
Hi everyone Im writing an application in c# and I want to print directly to a printer with some printer specific commands than only the printer understands. Below is my code. I have an arraylist...
13
by: Susan Beebe | last post by:
I have downloaded the code described in Microsoft article Q154078. I am trying to send raw ZPL (zebra barcode printer) code from Microsoft access. It works just fine if I hard code the actual...
1
by: hasanainf | last post by:
Hi all and thanking you all in advance for your help My client wants to use a receipt printer. Since I have never used one before I have some questions. 1. Unlike other printers which are set...
0
by: SKa | last post by:
Hi there, Does anybody knows how to print a printer connected to LPT1, and installed as a Generic/Text Only printer? I'll send raw text commands so creating a PrintDocument won't work for me.
7
by: Jean Paul Mertens | last post by:
Hello, Is there a way to send a string of text to a generic tekst printer under ..NET. Somethings as in the good old days File f = Open("LPT1"); f.Writeline("Blablabla"); The goal is to use...
8
by: Microsoft News | last post by:
Greetings community at large. I have a c# app that generates a PDF file. I have a printer that prints PDF natively. But I cannot figure out how to programatically print in C# ... I can...
0
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object:...
14
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object:...
0
by: =?Utf-8?B?VCBCdW1iYXJnZXI=?= | last post by:
I am using WriteFile to write directly to LPT1, where I have an Epson POS printer. This works fine unless I have a printer (anything, 'Generic / Text only', the printer itself) setup to use LPT1...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.