Я работаю с ulinux на микроблоге.чтение из трубы для SPI
Ive некоторые проблемы с SPI. Мой код работает, я вижу, что труба зачитывается. Но как я могу проверить данные (rdata) printf не работает.
Вот мой код
//slavetool
int main(int argc, char **argv)
{
uint8_t rdata[1500];
int ctrl = 0;
int fd;
int pipenr = 9;
int n;
char device[15];
fd_set socks;
//open codec
sprintf(device,"/dev/spi/pipe%d", pipenr);
fd = open(device, O_RDWR);
if(fd < 0)
{
printf("Failed to open pipe %s\n", device);
return 0;
} else
{
printf("openend %s\n", device);
}
printf("fd = %i\n", fd);
printf("Initialisation complete!\n");
while(1)
{
printf("try to set!\n");
FD_ZERO(&socks);
FD_SET(fd, &socks);
printf("fd_set set!\n");
n = select(fd + 1, &socks, NULL, NULL, NULL);
//printf("Select is %i!\n", n);
if(FD_ISSET(fd, &socks))
{
ctrl = read(fd, &rdata, 1500);
printf("entered data: %s", rdata); //DOESN'T WORK
printf("ctrl: %i", ctrl); //DOESN'T WORK
printf("Check1\n"); // WORK
if(ctrl<0)
{
perror("read");
printf("Ende ctrl ist %i!\n",ctrl);
FD_ZERO(&socks);
close(fd);
return -1;
}
printf("Check2\n");
} else {printf("FD_ISSET not set");}
}
close(fd);
return 0;
}
Terminal:
# ./spiread
openend /dev/spi/pipe9
fd = 3
Initialisation complete!
try to set!
fd_set set!
Select is 1!
Wait:
Check1
Check2
* Редактировать Спасибо вам быстрый ответ. Не работайте! Перепрыгните через этот print(). ** Править О, это работает! Thx Alter Mann. Cant голосовать до -.-
Посмотрите на редактирование моего ответа, это было не правильно –