失敗にそなえて、現在のソースファイルを変更する前に保存しておく。
次のサンプルプログラムをdio_app.cという名前で保存し、
コンパイルして実行しなさい。OUT1からOUT8までが点灯すれ
ば成功である。
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "dio_ioctl.h"
int main(void)
{
int fd, i, ret;
DIO_POINT point;
fd = open("/dev/pci2726c", O_RDWR);
if (fd < 0) {
printf("[open] no Shippai.\n");
return -errno;
}
ret = ioctl(fd, IOCTL_DIO_RESET);
if (ret < 0) {
printf("[ioctl reset] no Shippai = %d\n", ret);
return -errno;
}
for (i = 1; i <= 8 ;i++) {
point.start_point = i;
point.data_count = 1;
point.data[0] = 1;
ret = ioctl(fd, IOCTL_DIO_OUTPUT, &point);
if (ret < 0) {
printf("[ioctl output] no Shippai = %d\n", ret);
return -errno;
}
usleep(1000*200); // 待ち時間
}
close(fd);
return 0;
}