You were all correct in that the CABLE appears as the printer
dev/usb/lp0 on the system. The cable seems to have a buffer that
fills after I've written 128 bytes or so. I tried Non-Blocking I/O
writes and I am able to tell when this happens. The problem is (or
was) that I'd have to write 128 bytes to the printer (cable) before I
could tell that it the printer was off-line. The next time the user
turned the printer ON these 128 characters would be printed. I needed
to find out if the printer was online BEFORE sending it any data.
My solution (although it's not pretty) is that I now do this:
#define LPGETSTATUS 0x060b (from ioctl.h I think)
fd = open("/dev/usb/lp0", O_RDWR);
ioctl(fd, LPGETSTATUS, &status);
I check "status" to see if the printer is on-line. It seems to work.
I don't know if it is a bad practice to be mucking about with ioctl
from within a user-space program or not but it's the only thing I've
found that will work for me.
Once I'm sure the printer is on-line I can either use "write" to send
it data or use a system call to "cat /data/myfile > /dev/usb/lpo". I
think there is a "printer busy" status code returned by ioctl but for
now I'm just using a system call to print.
What is still maddening to me is that printer.o can return a message
to the console stating that the printer is offline but there is
(apparently) no way for my program to be aware of that message. I
tried messing around with signals to see if printer.o was raising a
signal that I could intercept but I didn't do any good there either.
I don't particularly like the solution I've come up with but for now
it will work. Thanks again to everyone for their help.
Ed
--- In "Ed K" <> wrote:
> ret = system("cat pr_out.txt > /dev/usb/lp0");
>
> This works like a charm, except for one little thing; if the printer
> is turned off my program hangs (the system call never returns) until
> the printer is turned on. After a few seconds a message appears on
> the console saying that lp0 is offline.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|