⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pci550x_dio_out.c

📁 linux下面
💻 C
字号:
/* * pci550x user program - digitial I/O - outputs * * Invoke this test program from the command line as follows: * * $ ./pci550x_dio_out /dev/pci550xN P * *      where N   = pci550x device number *            P   = port number 0|1|2|3|16 *                  default = 0 * * EXAMPLE: run the test on device 1, digital I/O port 2 * $ ./pci550x_dio_out /dev/pci550x2 2 */#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/fcntl.h>#include <signal.h>#include <sys/ioctl.h>#include <unistd.h>#include "pci550x.h"/* GLOBLA DATA */int i,m;int fd;int brd_type;int rc;unsigned dio_port0, dio_port1, dio_port16;int main(int argc, char **argv) {	/* open the device */	fd = open(argv[1], O_RDWR);	if(fd == -1) {		perror("open failed");		exit(1);	} else {		printf("open succeeded on %s\n", argv[1]);	}	/* query device type */	rc = ioctl(fd, PCI550X_IOCG_BRD_TYPE, &brd_type);	if(rc == -1) {		perror("ioctl PCI550X_IOCG_BRD_TYPE");		exit(1);	} else {		printf("ADAC Board Type:  %s\n", brd_names[brd_type]);	}        if (argc > 2) sscanf(argv[2], "%d", &dio_port0);                      	/* configure DIO port 0 as an output port */	m = PCI550X_DIO_OUTPUT;	rc = ioctl(fd, PCI550X_IOCT_DIO_DDC0, m);	if(rc == -1) {		perror("ioctl PCI550X_IOCT_DIO_DDC0");		exit(1);	} else {		dio_port0 = 0xaa;		rc = ioctl(fd, PCI550X_IOCS_DIO_0, &dio_port0);		if (rc == -1) {			perror("ioctl PCI550X_IOCS_DIO_0");			exit(1);		} else			printf("DIO port 0 configured for output\n");			printf("DIO port 0 output: 0x%x\n", dio_port0);	}	/* configure DIO port 1 as an output port */	m = PCI550X_DIO_OUTPUT;	rc = ioctl(fd, PCI550X_IOCT_DIO_DDC1, m);	if(rc == -1) {		perror("ioctl PCI550X_IOCT_DIO_DDC1");		exit(1);	} else {		dio_port1 = 0x55;		rc = ioctl(fd, PCI550X_IOCS_DIO_1, &dio_port1);		if (rc == -1) {			perror("ioctl PCI550X_IOCS_DIO_1");			exit(1);		} else			printf("DIO port 1 configured for output\n");			printf("DIO port 1 output: 0x%x\n", dio_port1);	}	/* write both DIO output ports */	dio_port16 = 0x1234;	rc = ioctl(fd, PCI550X_IOCS_DIO_16, &dio_port16);	if (rc == -1) {		perror("ioctl PCI550X_IOCS_DIO_16");		exit(1);	} else		printf("DIO port 16 output: 0x%x\n", dio_port16);	close(fd);	return(0);	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -