[PARPORT] simple driver

From: Nordic Boy (jklaas@cs.albany.edu)
Date: Wed Apr 05 2000 - 19:03:24 EDT

  • Next message: G. Eric Morgan: "[PARPORT] Still having Zip parallel problems"

    Well, I have gotten far enough to have gotten stuck. I guess I don't
    really understand what I am doing yet.

    To start at the beginning. I am trying to write a parallel port driver
    for an electronic switch, specifically a printer switch, although this
    could be applied to a bidirectional switch made by the same company. I
    have an ATEN AS-152 switch. This is a dual mode switch, which means that
    it can take two computers and attach them to one printer or two printers
    and attach them to one computer. The DOS and Windows drivers require
    manual intervention to cause the device to switch ports when it is one
    computer attached to two printers (it is automatic the other direction).

    If you have any other questions pertaining to the nature of the device,
    you can retrieve a copy of the manual in pdf form from
    http://www.aten-usa.com/download/manuals.htm. You will need a
    username/password it is aten/manuals.

    I have a copy of some dos example code (this was included in the drivers
    here: http://www.aten-usa.com/download/drivers/as2p161w.exe) and I am
    attempting to write drivers for linux that would make the switch operate
    essentially automatically (more on this later).

    After reading the module documentation and setting this up as a module, I
    was able to get my driver to get a list of ports and attach my driver and
    claim each of the ports (actually, I only have one on the machine). I can
    see that parport is using my driver when looking in proc so I am assuming
    that that I should be able to use the port at will from this point.

    The DOS code that has me interested are the commands to make the port
    switch. Here is the meat of it

    void ot_p(port_no, code1, code2, code3)
     unsigned int port_no ;
     unsigned char code1, code2, code3 ;
    {
     unsigned int far *i_ptr ;
     unsigned int port_adr ;
     unsigned int iii ;
      port_no-- ;
      FP_SEG(i_ptr) = 0x40 ; FP_OFF(i_ptr) = 8 + (port_no << 1) ;
      port_adr = *i_ptr ;
            
      outp(port_adr+2 , inp(port_adr+2) & 0xf7) ;
      for (iii=0 ; iii<5 ; iii++)
        {
         outp(port_adr, code1); wait(); outp(port_adr, code1 |0x80); wait();
         outp(port_adr, code2); wait(); outp(port_adr, code2 |0x80); wait();
         outp(port_adr, code3); wait(); outp(port_adr, code3 |0x80); wait();
        }
      outp(port_adr+2 , inp(port_adr+2) | 0x08) ;
    }

    I can't figure out what "outp(port_adr+2 , inp(port_adr+2) & 0xf7) ;"
    does but I assume that it is to set the port up for recieving
    commands. The for loop sends the code to switch the port. The codes are
    listed here:

               port A: 0x04, 0x84, 0x05, 0x85, 0x06, 0x86
               port B: 0x04, 0x84, 0x05, 0x85, 0x07, 0x87
               port C: 0x04, 0x84, 0x05, 0x85, 0x02, 0x82
               port D: 0x04, 0x84, 0x05, 0x85, 0x03, 0x83
            broadcast: 0x04, 0x84, 0x05, 0x85, 0x01, 0x81

    I attempted to replicate this by the following code. At this point I had
    claimed the port sucessfully.

        mydevice[0]->port->ops->write_control(mydevice[0]->port, 0x04);
        mydevice[0]->port->ops->write_control(mydevice[0]->port, 0x84);
        mydevice[0]->port->ops->write_control(mydevice[0]->port, 0x05);
        mydevice[0]->port->ops->write_control(mydevice[0]->port, 0x85);
        mydevice[0]->port->ops->write_control(mydevice[0]->port, 0x07);
        mydevice[0]->port->ops->write_control(mydevice[0]->port, 0x87);

    Can anyone help me?

    My eventual goal is to create two device files for each port on the
    switch and to make the switch switch automatically when a job is sent to
    that device file. I think though that I would just like to get the switch
    to just twich for the moment.

    Thank you for any help you can give me.

    James Klaas

    -- To unsubscribe, send mail to: linux-parport-request@torque.net --
    -- with the single word "unsubscribe" in the body of the message. --



    This archive was generated by hypermail 2b29 : Wed Apr 05 2000 - 19:12:09 EDT