Fedora Linux Support Community & Resources Center
  #1  
Old 13th August 2008, 02:40 AM
cj5cowboy Offline
Registered User
 
Join Date: Nov 2006
Location: Indiana
Age: 51
Posts: 39
getting data from a sensor

Hi,

I have a seismic sensor that I need to hook up to a serial port and start reading data from.
(I don't have much documentation other than a datasheet of the AD converter I found on the net)

Here is what I am trying to do.

The AD converter can be set in a 'mode' (4 different ones single step conversion and continuous conversion combined with a resolution).
There is no response if you set a mode.

Than there are a few commands one can use; status, get a digit pair(a byte) (there are 3 different digit pairs.
The sensor doesn't send any data over the serial link when not asked for it.

Anyway, I am trying to send one byte commands and try to retriven one byte responses but I seem to get a lot of 'Resource temporarily unavailable' messages when I try to read the data.

what would be the best way to talk to that sensor so that I don't get those EAGAIN 'Resource temporarily unavailable' erros ?

thanks,

Ron

Oh I am using C btw.
Reply With Quote
  #2  
Old 13th August 2008, 09:37 AM
oneofmany's Avatar
oneofmany Offline
Registered User
 
Join Date: Aug 2006
Posts: 226
what programming language are you using? how have you configured the port and how are you accessing it?
Reply With Quote
  #3  
Old 13th August 2008, 02:19 PM
cj5cowboy Offline
Registered User
 
Join Date: Nov 2006
Location: Indiana
Age: 51
Posts: 39
I am using C (I think I mentioned that).

I disassembled the sensor to look at it, it only uses pin 2,3 and 5 (so there is no handshakes or flow control) The data is binary, so xon/xoff won't work either.

here is how I open the port:
int OpenSeismoPort(char *dev)
{
char sPortName[64];

sprintf(sPortName, "/dev/%s", dev);
#ifdef DEBUG
printf("sPortName=%s\n", sPortName);
#endif

fd = open(sPortName, O_RDWR | O_NOCTTY | O_NDELAY );
if (fd < 0) {
printf("open error:%s %d %s\n", sPortName, errno, strerror(errno));
}
else
{
struct termios options;

// Get the current options for the port...
tcgetattr(fd, &options);

// Set the baud rates to 19200...
cfsetispeed(&options, B19200);
cfsetospeed(&options, B19200);

// Enable the receiver and set local mode...
options.c_cflag = B19200 | CLOCAL | CREAD | CS8 | PARENB;

options.c_cflag &= ~CSTOPB; // one stop bit

options.c_lflag &= ~ICANON; // binary data non canonical

options.c_cc[VTIME] = 0; // we're not using the inter character timer
options.c_cc[VMIN] = 1; // blocking read until 1 character arrives


tcflush(fd, TCIFLUSH);
// Set the new options for the port...
tcsetattr(fd, TCSANOW, &options);
}
return fd;
}

than reading and writing I just use write and read.
Somebody once got it to work on an msdos/windows95 machine. The sensor is pretty old ('95) and the company that built them is not in business anymore.

The msdos app probably used things like outportb/inportb at the time. (I remember that being kinda popular in those turbo-c days)

Is that something I should use ?, outb_p, inb_p ? Is that 'more direct' ?

thanks for your reply,

Ron
Reply With Quote
  #4  
Old 13th August 2008, 04:01 PM
oneofmany's Avatar
oneofmany Offline
Registered User
 
Join Date: Aug 2006
Posts: 226
its been a while since i used raw c but if i remember correctly, reads and writes are buffered so that's probably not a good option. also, try lowering your baud rate to something like 9600 and seeing if that has any affect. back in the 95 days that was considered "compatibility" speed.

if you still have the original driver/software available you could try using that with a breakout box and seeing what the data flow is like too.
Reply With Quote
  #5  
Old 13th August 2008, 04:51 PM
cj5cowboy Offline
Registered User
 
Join Date: Nov 2006
Location: Indiana
Age: 51
Posts: 39
I did that, I installed it on an old pc and looked at what teh data did. it is what I expected (after reading the data sheet). However .. when I snooped that serial port on a windows machine I didn't see any serial line problems.

I rewrote some stuff to see what is going on. it seems at some point that 'nothing happens'.

What I try and do is close the serial port (with a close(fd)) and than open it again.

It seems that closing the port takes forever (well almost forever.)
that pretty much indicates something must be wrong I think

I tried setting the speed of the port and device to 9600 doesn't make a difference.
(I also tried several different pc's to
Reply With Quote
  #6  
Old 13th August 2008, 11:42 PM
cj5cowboy Offline
Registered User
 
Join Date: Nov 2006
Location: Indiana
Age: 51
Posts: 39
I figured it out, I needed the nodelay option is the tio.c_oflag member of termios too.
Reply With Quote
Reply

Tags
data, sensor

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fan / Temp sensor program synic Using Fedora 9 14th February 2009 10:44 AM
USB Temperature sensor Jeff Sadowski Guides & Solutions (No Questions) 2 6th August 2007 03:44 PM
Sensor error on gDesklets Edward Lichtner Using Fedora 0 21st October 2005 06:01 PM


Current GMT-time: 21:07 (Saturday, 18-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat