pci2726byteのテストプログラムを作成して、実行しなさい。
このプログラムは、CHK-2101のスイッチ入力に対応してLED出力が点灯する。
このプログラムは、入力データの4バイトが全て1になるまで止まらない。
入力データの4バイトが16進数の FF FF FF FFになったときに停止する。
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(void)
{
int fd, i, flag;
unsigned char i_data[4];
ssize_t r_count, w_count;
fd = open("/dev/pci2762byte", O_RDWR);
if (fd < 0) {
printf("[open] no Shippai.\n");
return -errno;
}
flag = 1;
while (flag) {
// SW1-SW8, SW9-SW16, SW17-SW24, SW25-SW32
r_count = read(fd, i_data, 4);
if (r_count < 0) {
printf("input error = %d\n", -errno);
return -errno;
}
printf("input data: ");
for (i = 0; i < r_count; i++) {
printf("%X ", i_data[i]);
}
printf("\n");
// LED33-LED40, LED41-LED48, LED49-LED56, LED57-LED64
w_count = write(fd, i_data, r_count);
if (w_count < 0) {
printf("output error = %d\n", -errno);
return -errno;
}
flag = 4;
for (i = 0; i < 4; i++) {
if (i_data[i] == 0xff)
flag--;
}
usleep(1000*100);
}
printf("Owari\n");
close(fd);
}