REPOST: C# Guru's! ReadPrinter....I need to read printer buffer to stringbuilder...

T

trint

The WritePrinter() is working. I know this ReadPrinter()
implementation isn't correct because it never reads into "reaDstrinG"
buffer from the printer...But, I'm sure one of you Guru's do know how I

can make this work (and any help is appreciated):

sb = new StringBuilder(initialValue);

PrintDirect.OpenPrinter(@"\\Web1\Shipping1",ref lhPrinter,0);
for (int i = -1; i < 23; i++)
{
PrintDirect.ReadPrinter(lhPrinter, sb = sb.Insert(3, reaDstrinG),
buf, out pcRead);
}
___________________________-

[ DllImport( "winspool.drv",CharSet=CharSet.Ansi,ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern bool ReadPrinter(IntPtr hPrinter, StringBuilder
data, int buf, out int pcRead);
And still, ReadPrinter is not working at all.

Mattias wrote this:
Use bool as the return type and make the data parameter a
StringBuilder
and...
public static extern bool ReadPrinter(IntPtr hPrinter, StringBuilder
data, int buf, out int pcRead);

Any help is appreciated.
Trint
 
W

Willy Denoyette [MVP]

Not sure what you are expecting to read from a printer (you are NOT reading
from a printer job!!).
Anyway you don't check the return from the ReadPrinter API, so you and we
can't tell what went wrong. But I'm pretty sure you can't read from a
printer over the network, nor can you read from a uni-directional printer.

Willy.
 
T

Trint Smith

Yeah! you can read this printer on a network. I have a program that
came with it that reads it's supplies level down to the staples in the
cartridge.
Here is what I send to the printer and then must receive back it's
response:

st1 = "\x1b%-12345X@PJL \f" +
"@PJL COMMENT ***Inquiring About \f" +
"@PJL COMMENT Environment Settings*** \f" +
@"@PJL ECHO " + formaTtd + " \f" +
"@PJL INQUIRE INTRAY2 \f" +
"@PJL INQUIRE INTRAY3 \f" +
"@PJL INQUIRE INTRAY4 \f" +
"@PJL INQUIRE STAPLER \f" +
"@PJL INQUIRE TONNER \f" +
"@PJL INQUIRE TIMEOUT \f" +
"@PJL ENTER LANGUAGE=PCL \f" +
"\x1b%-12345X\f";

PrintDirect.OpenPrinter(@"HP LaserJet 4250 PCL 6",ref lhPrinter,0);
PrintDirect.WritePrinter(lhPrinter,st1,st1.Length,ref pcWritten);
PrintDirect.ClosePrinter(lhPrinter);

And somehow, I have to make the following code work or similar code:

char[]thisMightbeIt;
int buf = 0;
int pcRead;
System.Text.StringBuilder sb = new System.Text.StringBuilder();

PrintDirect.OpenPrinter(@"HP LaserJet 4250 PCL 6",ref lhPrinter,0);
for (int i = -1; i < 23; i++)
{
PrintDirect.ReadPrinter(lhPrinter, sb.Append(thisMightbeIt,100),
buf, out pcRead);

}

Thanks for an help on this!
Trint

..Net programmer
(e-mail address removed)
 
W

Willy Denoyette [MVP]

Trint Smith said:
Yeah! you can read this printer on a network. I have a program that
came with it that reads it's supplies level down to the staples in the
cartridge.
Here is what I send to the printer and then must receive back it's
response:

st1 = "\x1b%-12345X@PJL \f" +
"@PJL COMMENT ***Inquiring About \f" +
"@PJL COMMENT Environment Settings*** \f" +
@"@PJL ECHO " + formaTtd + " \f" +
"@PJL INQUIRE INTRAY2 \f" +
"@PJL INQUIRE INTRAY3 \f" +
"@PJL INQUIRE INTRAY4 \f" +
"@PJL INQUIRE STAPLER \f" +
"@PJL INQUIRE TONNER \f" +
"@PJL INQUIRE TIMEOUT \f" +
"@PJL ENTER LANGUAGE=PCL \f" +
"\x1b%-12345X\f";

PrintDirect.OpenPrinter(@"HP LaserJet 4250 PCL 6",ref lhPrinter,0);
PrintDirect.WritePrinter(lhPrinter,st1,st1.Length,ref pcWritten);
PrintDirect.ClosePrinter(lhPrinter);

And somehow, I have to make the following code work or similar code:

char[]thisMightbeIt;
int buf = 0;
int pcRead;
System.Text.StringBuilder sb = new System.Text.StringBuilder();

PrintDirect.OpenPrinter(@"HP LaserJet 4250 PCL 6",ref lhPrinter,0);
for (int i = -1; i < 23; i++)
{
PrintDirect.ReadPrinter(lhPrinter, sb.Append(thisMightbeIt,100),
buf, out pcRead);

}

Thanks for an help on this!
Trint

Net programmer
(e-mail address removed)


I didnt say you can't read from a printer, I said you cannot read from a
uni-directional printer and probably not from a networked printer.
And most importantly, you are not checking your return from the ReadPrinter
call how the hell would you want us to tell you why it's not working.
Second, the example you are posting now is reading from a local attached
printer ((@"HP LaserJet 4250 PCL 6"), while in the original post you are
refering to a networked printer ((@"\\Web1\Shipping1",) quite a difference
isn't it?

Note also that you can query the information you are looking for through the
System.Management namespace classes and the WMI win32_printer class.


Willy.
 
T

Trint Smith

I was just testing my code with a usb.

.Net programmer
(e-mail address removed)
 
W

Willy Denoyette [MVP]

Trint Smith said:
I was just testing my code with a usb.

And what does this mean, is it working or not?
Does it mean it works when you run the code on the box to which the printer
is physically attached?
And that it fails if you run the code on another box using
(@"\\Web1\Shipping1... as printer name in the OpenPrinter call?

Willy.
 
T

Trint Smith

No, it doesn't work yet. But I'm currently working on that.

.Net programmer
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top