LinuxQuestions.org
Visit Jeremy's Blog.
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 09-25-2007, 05:29 PM   #1
randomsel
Member
 
Registered: Oct 2006
Location: Wilmington, DE
Distribution: Slackware 11
Posts: 201

Rep: Reputation: 30
How to monitor a device? A Linux Programing question.


Greetings to all,

I've just started a little project that needs to monitor a character device in Linux for changes (specifically, a Gumstix computer monitoring /dev/gpio-event).

Quote:
Once pins are setup to be monitored, any program can read /dev/gpio-event to get notified of the events. By default, an ASCII string of the form: "pin edge timestamp" followed by a newline will be delivered to /devb/gpio-event for each event that occurs.
...
For C programs, you can opt to use a binary interface instead. The binary versus ASCII setting is maintained on a per-file basis, so each program could each open /dev/gpio-event with a different ASCII/binary setting.
I don't have much experience programing in Linux, so this could (hopefully) come down to a yes/no answer. Here goes:

If programing in C, would the correct way of getting notified of an event from the device, without using polling, be pipe()? If not, please help with pointers to the correct answer/s.

Thanks in advance.
 
Old 09-25-2007, 07:58 PM   #2
maroonbaboon
Senior Member
 
Registered: Aug 2003
Location: Sydney
Distribution: debian
Posts: 1,495

Rep: Reputation: 48
You might get a better informed answer in the programming or embedded forums.

In C you can just use 'read' on a device file. The call will block until there is something to read, and you would have to loop until you got a newline. Is that the behaviour you want?

Alternatively you can use Asynchronous_I/O (Wikipedia), but that is really a form of polling.

I'm not sure what other alternatives there are.
 
Old 09-25-2007, 08:23 PM   #3
randomsel
Member
 
Registered: Oct 2006
Location: Wilmington, DE
Distribution: Slackware 11
Posts: 201

Original Poster
Rep: Reputation: 30
Thanks for the quick reply!

The blocking behavior is exactly what I wanted, but the books I read about programming said reading a file from at it's end would return 0, and the only mention about blocking was in pipes. Thanks for clearing that up!
 
Old 09-26-2007, 08:08 PM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 09-26-2007, 10:34 PM   #5
jdiggitydogg
Member
 
Registered: Sep 2007
Posts: 42

Rep: Reputation: 15
other functions such as fgets and fread should also work after the device is opened with fopen. if you really, really wanted to use pipes, you could execute 'cat /dev/xxxx' with popen. you'd then read from the popen file handle. i'm just throwing this out there, although i can't think of a good reason to use pipes/popen in this scenario.

Last edited by jdiggitydogg; 09-26-2007 at 10:36 PM.
 
  


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
Programing linux handheld device mlanzone Programming 1 11-30-2005 02:04 AM
Programing linux handheld device mlanzone Linux - General 0 11-29-2005 04:35 PM
Newbie programing question matthewa Programming 4 03-20-2005 04:37 PM
C programing question israel Programming 2 11-29-2004 06:05 AM
Question on programmERS, not programING MasterC Programming 5 09-01-2002 04:13 AM

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

All times are GMT -5. The time now is 07:02 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