Hello, I am having a problem with the program below.
It stops [meaning: just does nothing and doesnt react to any of my inputs or inputs of voltage to the port...], whats wrong??
In bold text i show the point where it stops...
Thanks a lot
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <linux/fs.h>
#include <termios.h>
#include <sys/types.h>
#include <fcntl.h>
#include "../h/icp_mio_hw.h"
void *ctr_val;
int mystdin, fd_ai_ch;
ssize_t bytes_read;
char ch;
size_t nbytes = 4, cnst = 4;
off_t offset = 0;
void ainp_test(int ctr_num)
{
fd_ai_ch = open("/dev/mio0.ai0",0,0);
printf("The file descroptor for the ai is: %d\n", fd_ai_ch);
ioctl(fd_ai_ch,MIO_IOCTL_AI_CH_ADC_BIP_INP_RANGE, 0);
ioctl(fd_ai_ch,MIO_IOCTL_AI_CH_ADC_INP_RANGE, 1);
ioctl(fd_ai_ch,MIO_IOCTL_AI_CH_ADC_UNITS, ADC_mV_UNIT);
/*
** permanent read
*/
/* set stdin to non-blocking */
mystdin = open("/dev/stdin", 0, 0);
printf("The file descroptor for the stdin is: %d\n", mystdin);
if(mystdin < 0)
{
printf("stdin open error\n");
return;
}
printf("Usage: to switch to the next input value just press ENTER\n");
printf(" to switch to the next test step just press SPACE and then ENTER\n");
printf(" to break down the test just press Z and then ENTER\n");
do
{
printf("Entering loop\n");//<- IT PRINTS THIS AND GETS BLOCKED!
bytes_read = read(fd_ai_ch, &ctr_val, nbytes);
printf("Bytes read\n");
if ( bytes_read != cnst)
{
printf ("read error on ai_ch_0\n");
close(mystdin);
return;
}else
{
printf ("ai_ch input value %i\n", ctr_val);
}
/* block */
read(mystdin /*stdin */, &ch, 1);
usleep( 100000 );
}while ((ch != ' ') && (ch != 'Z'));
close(mystdin);
if ( ch == 'Z' )
{
printf ("User break\n");
return;
}
close(fd_ai_ch);
return;
}
flamingo_the_brown_the_1