LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-18-2007, 07:14 AM   #1
brownflamigo1
Member
 
Registered: Jun 2007
Distribution: Ubuntu
Posts: 90

Rep: Reputation: 15
Analogue input program problems...


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
 
Old 06-18-2007, 09:07 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Do you have any confirmation that a driver for your MIO board is installed and configured? You are not testing for error return from the open() call on the MIO device. Modify your code to check for valid fd's. Same for the ioctl() calls. Are you sure that the hardware has been configured to acquire any reading? Most boards require some kind of enabling signal to allow the ADC to perform conversions.
I assume that this is a National Instruments board and driver. They are usually pretty good about providing some simple test/diagnostic code with their boards. Have you tested the combined hardware/driver installation with some known-good software?
--- rod.

Last edited by theNbomr; 06-18-2007 at 09:08 AM.
 
Old 06-18-2007, 11:00 AM   #3
cppkid
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
I agree with the above person that you must always check your open() call if it is opened correctly or it returned some error.
Secondly the statement where you mentioned that the code blocked is the Blocking read call and it will be blocked until it will receive some data. So make sure that you are providing some data on the port you are reading. It will remain blocked until it will read data or error from that port.

Also as it is blocking there so i think that connection to the port is open else it would return with errno set to some error.
 
Old 06-23-2007, 07:35 AM   #4
brownflamigo1
Member
 
Registered: Jun 2007
Distribution: Ubuntu
Posts: 90

Original Poster
Rep: Reputation: 15
Thanks guys
yeah, the problem was in the open().
now it is all good
Nik
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
input avoided in my c program. nflenz Programming 6 12-12-2006 01:47 PM
Can't get user input when using a pipe to my C++ program ta0kira Programming 18 04-22-2006 12:53 PM
Standard Input in Perl Program eachow Linux - General 2 11-17-2005 12:16 AM
Program gets aborted on large input shinni Programming 4 03-12-2005 09:25 PM
a program to record audio input matt_w_lambert Linux - Software 4 04-27-2003 03:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration