Thread: using PCL(printer cammand language)

  1. #1
    unregistered
    Guest

    Question using PCL(printer cammand language)

    hi ! can any one write a program for printing in c using PCL and using outportb function and not fprintf functions

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > can any one write a program for printing in c using PCL
    Someone has for sure....

    > using outportb function
    Why? - it's a non-portable function

    > not fprintf functions
    Why not? - this is a portable function
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Unregistered
    Guest

    Angry

    NEVER mind that compatibility stuff . Given below is my code and it is int working properly . This program is intended to print wingding characters on a pcl compatible printer .However it is printing in ascii . thanks in advance

    /************SOURCE CODE***********************/

    #include<stdio.h>
    #include<conio.h>
    #include<dos.h>
    #include<stdarg.h>
    const int BASE = 0x378;

    int checkackstatus();
    void strobe();
    void send(int data,...);
    void init();
    int checkprintstatus(); // not used in this program


    void main()
    {
    clrscr();
    init(); // init printer
    send(27,69); // Reset
    send(27,40,115,50,55,51,48,84); //wingdings
    send(97,98,99,100,101,102,103,104,105,106,107,108, 109);//contents
    send(27,69); // Reset

    }

    int checkackstatus()
    {
    unsigned char status = inportb(BASE+1);
    int chkpnt = 1 ,row = 1;

    if ((status & 0x40) != 0)
    {
    gotoxy(1,row++);
    printf("Printer does not acknowledge");
    chkpnt = 0;
    }
    return chkpnt;
    }

    void strobe()
    { unsigned char test;
    test=inportb(BASE+2);
    test&=0x1e;
    outportb(BASE+2,test);
    test|=1;
    outportb(BASE+2, test);
    }

    void send(int data,...)
    {
    outportb(BASE, data); strobe();
    while(!checkackstatus());
    clrscr();
    va_list ap;
    int arg;
    va_start(ap, data);
    while ((arg = va_arg(ap,int)) != 0)
    {
    outportb(BASE, arg); strobe();
    while(!checkackstatus());
    clrscr();
    }
    va_end(ap);

    }

    void init()
    {
    unsigned char a=inportb(BASE+2);
    a &= 235;
    outportb(BASE+2,a);
    a |= 4;
    outportb(BASE+2,a);

    while ((inportb(BASE+1) & 0x80) == 0)
    { printf("Printer is busy "); }

    clrscr();
    }

    int checkprintstatus()
    {
    unsigned char status = inportb(BASE+1);
    int chkpnt = 1 ,row = 1;

    if ((status & 0x80) == 0)
    {
    gotoxy(1,row++);
    printf("Printer is busy ");
    chkpnt = 0 ;
    }

    if ((status & 0x40) != 0)
    {
    gotoxy(1,row++);
    printf("Printer does not acknowledge");
    chkpnt = 0;
    }
    if ((status & 0x20) != 0)
    {
    gotoxy(1,row++);
    printf("Printer is out of paper ");
    chkpnt = 0;
    }
    if ((status & 0x10) != 0)
    {
    gotoxy(1,row++);
    printf("Printer is off line ");
    chkpnt = 0 ;
    }
    if ((status & 0x08) != 0)
    {
    gotoxy(1,row++);
    printf("Printer error ");
    chkpnt = 0 ;
    }

    while(row <7)
    {gotoxy(1,row++);
    printf(" ");
    }

    return chkpnt;
    }

    /*****************END**************************/

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well there are big problems with your send function
    1. Why so many calls to clrscr()? I mean, once for every character.

    2. while ((arg = va_arg(ap,int)) != 0)
    But your calls do not conform to this protocol.

    For example
    &nbsp; send(27,69); // Reset
    This will send two bytes, and some unspecified number of garbage until the code chances upon a zero.
    Try
    &nbsp; send(27,69,0); // Reset
    All your send calls should have a 0 as the last parameter

    > void main()
    Mmm - nope
    main returns an int
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Unregistered
    Guest
    ok. changed calls to send but still no luck.
    void main()
    {
    clrscr();

    // init printer
    init();
    send(27,69,0); // Reset
    send(27,40,115,50,55,51,48,84,0); //wingdings
    send(97,98,99,100,101,102,103,104,105,106,107,108, 109,0);
    send(27,69,0); // Reset

    }

    for information on PCL here are the links :

    http://itsa.ucsf.edu/~rpb/hppcl.html
    http://www.hp.com/cgi-bin/cposupport...t_doc/bpd07298
    http://homepages.borland.com/efg2lab...ojects/Prt.ZIP

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > send(27,69,0); // Reset
    Could you translate this into the character form, which means the same thing.
    'E' has the decimal value 69.

    send ( 27, 'E', 0 ); // Reset

    It would make it easier to compare against the descriptions of the PCL.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed