245-3

How to Install and Test PCI 8 Photo/8 Relay Card on Linux


  The page describes you how to install and test PCI 8 Photo/8 Relay Card on Linux.


1. Install Devicw Driver

1.1 Download Device Driver
1.2 DIP Switch set
  1.2.1 PnP mode
  1.2.2 Manual mode
1.3 Install step
2. Uninstall the driver
3. Self test the card
3.1 The test method
3.2 The Loopback test tool
  3.2.1 DB25 Connector assignment
  3.2.2 The circuit figure
  3.2.3 The Finished Product
  3.2.4 The usage of the test tool
3.3 The test programs
  3.3.1 Run the test1.c program
  3.3.2 Run the test2.c program
  3.3.3 Run the test2.c program








1. Install the driver:


This sample is under REDHAT 8.0 KERNEL 2.4.18-14.

You can do it in the ' text-mode ' or use the Terminal of System tools in ' graphic-mode '.


1.1 Download Device driver


Please download the driver from as follows:

dpci8in8out_2.2.14.tgz for Kernel 2.2.14 Release Date:2003/3/05

dpci8in8out_2.4.18.tgz for Kernel 2.4.18 Release Date:2003/3/05

Download the driver to /tmp.

You can use 'uname -a' command to check your kernel's version.





1.2 DIP Switch


The switch is used to identify card number, default setting is card 1. There are two methods to set

the card number:


1.2.1 PnP mode

Just plug in PCI bus adapter into PCI slot, the PCI BIOS will allocate I/O address to each adapter

automatically and assign card number start from 0 to each adapter. However, if you plug in more

than one adapter, please set whole adapters to card number 1 (default setting), then use software

tools to distinguish port id.


1.2.2 Manual mode

Set card number by card identifier switch, the PCI BIOS will assign pre-allocated I/O address to each

adapter. Please set different card number to each adapter (do not duplicate card number setting).









1.3 Install steps


Please follow as follows to install:

Step 1: Extract the file.

Step 2: Execute the instal1 to install.

Step 3: Please use 'lsmod' command to check.



Step 4: Please edit /etc/rc.local to add a command line as follows:






Step 5: Please reboot the systems.

Step 6: Please use 'lsmod' to check after system started. You can find PCI 8Photo/8Relay.





2. How to uninstall


If you want to remove the driver.You can use 'ls' command to find 'uninstall' file.

Then execute the file.







3. Self test the card


3.1 The test method

The 'LOOPBACK TEST' is a diagnostic procedure in which a signal is transmitted and received

through all or portion of a circuit.The received signal is compared with the transmitted signal in

order to evaluate the integrity of the equipment or transmission path.



3.2 The test tool

For testing you need to prepare a test equipment.You can do it as follows:


3.2.1 DB37 Connector assignment

According to DB37 Connector assignments ,you can make a loopback equipment.

About loopback equipment, please refer to:




3.2.2 The circuit figure


According to DB37 Connector Assignments ,we draw the circuit figure.




3.2.3 The Finished Product

In the sample ,you need some materials as follows:

DB37 CONNECTOR (Male) x 1

wine (1mm)






3.2.4 The usage of the loopback test tool

The usage of the test tool refer to the following figure.

Eight LEDs indiate when I/O is testing.





3.3 The test programs


The device driver already includes three test programs.
test.c: Auto tests Relay Output ON/OFF.
test1.c: Auto tests Relay Output and Photo Input.
test2.c: Manuly tests Relay Output.


3.3.1 Run the test.c program

Please compile test.c as follows:

#cc test.c

Then it will create a 'a.out' file.

Please execute it to test Relay.

You will see Led light from L1 to L8 on the PCI 8 Photo/8 Relay card.



The test.c's content is as follows:


#include "dpci8in8out.h"

#include "dpci8in8outlib.c"

#include <stdio.h>

#include <fcntl.h> /* open */

#include <unistd.h> /* exit */


/* Main - Call the ioctl functions */

main()

{

int file_desc, i,count=0;

char buf[255];

char b=1;

char *msg = "Message passed by ioctl\n";


sprintf(buf,"/dev/%s0\0",DEVICE_NAME);

file_desc = open(buf, O_RDONLY);

if (file_desc < 0)

{

printf ("Can't open device file: %s\n", buf);

exit(-1);

}

Write8In8OutPort(file_desc,0x0);

do{

Write8In8OutPort(file_desc,b);

b=b<<1;

count++;

if(count%8==0) b=1;

sleep(1);

} while(count<1000);

close(file_desc);

}


3.3.2 Run the test1.c program

Please compile test1.c as follows:

#cc test1.c

Then it will create a 'a.out' file.

Please execute it to test Relay and Photo.

The result is as follows:



The test1.c's content is as follows:


#include "dpci8in8out.h"

#include "dpci8in8outlib.c"

#include <stdio.h>

#include <fcntl.h> /* open */

#include <unistd.h> /* exit */

#include <string.h>

#include <sys/select.h>


/*It is a delay function.*/

void mysleep( long sec, long msec){

struct timeval tv;

tv.tv_sec = sec;

tv.tv_usec = msec*1000;

select(0, NULL, NULL, NULL, &tv);

}


/* Main - Call the ioctl functions */

main()

{

int file_desc,data,i,j=0;

unsigned char buf[255];


sprintf(buf,"/dev/%s0\0",DEVICE_NAME);

file_desc = open(buf, O_RDONLY);

if (file_desc < 0)

{

printf ("Can't open device file: %s\n", buf);

exit(-1);

}

Write8In8OutPort(file_desc,0x0);

for(i=1;i<256;i++)

{

Write8In8OutPort(file_desc,i);

printf("I write %d\n", i);

mysleep(0,100);

printf("I read %02x\n",Read8In8OutPort(file_desc));

mysleep(1,100);

}

Write8In8OutPort(file_desc,0x0);

close(file_desc);

}



3.3.3 Run the test2.c program

Please compile test2.c as follows:






The test2.c's content is as follows:


#include "dpci8in8out.h"

#include "dpci8in8outlib.c"

#include <stdio.h>

#include <fcntl.h> /* open */

#include <unistd.h> /* exit */

#include <stdio.h>


/* Main - Call the ioctl functions */

main()

{

int file_desc, i,j,count=0;

char buf[255];

int b=1;

char *msg = "Message passed by ioctl\n";


sprintf(buf,"/dev/%s0\0",DEVICE_NAME);

file_desc = open(buf, O_RDONLY);

if (file_desc < 0)

{

printf ("Can't open device file: %s\n", buf);

exit(-1);

}


Write8In8OutPort(file_desc,0x0);


printf("Input 1 to 8 to test:\n");

printf("Input 0 to single-off:\n");

printf("Input else number to end test:\n");

j=0;

while(0 <= j <= 8)

{

scanf("%d",&j);

if (j==0){

Write8In8OutPort(file_desc,0);

}

if (j<=8){

b=1;

b=b<<(j-1);

Write8In8OutPort(file_desc,b);

sleep(1);

}

else

{

break;

}

}

Write8In8OutPort(file_desc,0x0);

printf("End test\n");

close(file_desc);

}