ts-7000
[Top] [All Lists]

Re: [ts-7000] Re: Support for USB Printer - Is it really that complicate

To:
Subject: Re: [ts-7000] Re: Support for USB Printer - Is it really that complicated?
From: "Martin Guy" <>
Date: Fri, 2 Nov 2007 19:00:49 +0000
2007/11/2, Ed K <>:
> From my C program I'm simply writing my report output to a file
> (pr_out.txt) then using the system "cat" command to send it to the
> printer:
>
>      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.

You could try non-blocking IO. You'll need to take control of your
file-outputting stuff rather than using lame old system(), but a small
function to do the equivalent should be enough.
You can set non-blocking IO when you open the device with funny flags
to open(), then a write() either succeeds in sending data or returns
immediately saying it couldn't do it right now.

No guarantees that will work in your specific setup and through the
usb dongle etc, but it's your best shot.

> I've looked at fork() and wait() and several other system calls
> but I can't figure out how to use them.

I think those are irrelevant to your problem, unless you want to try a
bizarre way of doing it :)
However you are going to need a few system calls: open, read, write,
close, maybe the dreaded ioctl() and fcntl() to get that level of
control. You probably *can* do it using the stdio routines (fopen()
etc), but since you cannot set nonblocking IO without using
unix-specific fcntl() too, you may as well go whole-hog and use pure
system calls for the printer-output section of that particular
routine.
If you need help understanding system calls, contact me for a link.

    M


 
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/
 

<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU