How do talk with printer

Michael Sweet msweet at apple.com
Wed Nov 11 08:32:17 PST 2009


Please don't write code like this - normal users don't have access to  
USB device files.

If you do this as a filter, you'll send your commands to stdout and  
read the response back using cupsBackChannelRead.  After you read the  
buffer (which you must then nul-terminate if it is ordinary text),  
validate the value in the buffer before using it!

Also, your fprintf is missing a newline at the end and the colon after  
"PPD" - it should read like this:

     fprintf(stderr, "PPD: RibbonLength=%s\n", buff);

Again, you'll need to nul-terminate your buffer (buff[retv] = '\0') to  
use it this way, and you absolutely should be validating the buffer  
otherwise you could be writing random garbage to the PPD file.

On Nov 11, 2009, at 4:34 AM, sivakumar wrote:

> Hi,
>
>
>      I want to talk with the printer i written some code that follows,
>
> USBOpen()
> {
> char buff[256] = {0};
> int fd=open("\dev\usb\lp0",O_RDWR);
>
>  memset(buff,0,sizeof(buff));
>  sprintf(buff,"\033!RIBLEN\r");
>  retv =  write(fd,buff,strlen(buff));
>  memset(buff,0,sizeof(buff));
>  retv = write(fd,"\033E 2\r",strlen("\033E 2\r"));
>  retv = read(fd,buff,sizeof(buff));
>
> fprintf(stderr,"PPD RibbonLength=%s",buff);
>
> }
>
> where i should place the code (BackEnd/Filter/Shuduler),and i want  
> to update this one to PPD file.
>
> I am using
>
> Fedora 10 OS
> GNOME Desktop
> CUPS 1.3
>
>
> Thanking You
>
> _______________________________________________
> cups-ddk mailing list
> cups-ddk at easysw.com
> http://lists.easysw.com/mailman/listinfo/cups-ddk

___________________________________________________
Michael Sweet, Senior Printing System Engineer







More information about the cups mailing list