Problem with fopen, linux, and RS-232, possibly

G

Gregory Graham

I have a temperature sensor device we use to shutdown our servers. It
relys on fopen() blocking when the serial port device isn't ready.
Unfortunately that's not what's happening. The fopen() returns
immediately without an error. What have I got wrong?

Basically when it gets too hot the device connects the 8 and 6 lines
to line 20. That should, as I understand it, tell the fopen() that
the file is available and cause the rest of the program to execute.

The code is below. I compile it with "gcc -o minmon minmon.c" and
invoke it as "minmon /dev/tyyS0" on SuSE9 with gcc 2.95.3

#include <stdio.h>
#include <signal.h>

int await_event(char* port)
{
FILE *file;
int fd;

if ((file = fopen(port, "r")) != NULL) /*blocks*/
fclose(file); /*no longer need port*/
else
{
fprintf(stderr, "ERROR opening port %s", port);
return -1;
}
return 0;
}

main (int argc, char* argv[])
{
int pid, getuid();
char* port, *script;

if (argc != 2 )
{
fprintf(stderr, "Usage:");
fprintf(stderr, "\t%s device\n", argv[0]);
exit(3);
}
else /*run in diagnostic mode*/
{
port = argv[1];
printf("watching on port: %s\n", port);
if (await_event(port) == 0) /*blocks*/
{
printf("%s: diagnostic power out\n", argv[0]);
/*insert shutdown code here*/
}
else
printf("%s: ERROR while waiting for event\n",
argv[0]);
exit(0);
}
}
 
A

alp

Hi Gregory,

Are those pins you specified the DCD signal?
I am not sure how fopen() is calling open(), but you want to make sure
open() is called WITHOUT the O_NDELAY flag.
Also, you may want the O_NOCTTY flag to be present.

Try writing the program using open() instead, and specify the exact
flags.
You can also pass fcntl()s to the device.

If this is not DCD signal, and rather some obscure pins than the driver
may be unaware of its "readiness", then any open() call may not block.
Whether the device is actually capable of sending data or not. I
haven't checked the serial pinout to verify.

Here is some reading that may be of assistance.
http://www.easysw.com/~mike/serial/serial.html#2_5
Hope this helps.

Art Perry
Linux Systems/Software Engineer
 
A

Arthur Perry

On Wed, 8 Dec 2004, Gregory Graham wrote:

Hi Gregory,

Are those pins you specified the DCD signal?
I am not sure how fopen() is calling open() (I didn't bother checking),
but you want to make sure that open() is called WITHOUT the O_NDELAY flag.
Also, you may want the O_NOCTTY flag to be present.

Try writing the program using open() instead, and specify the exact flags.
You can also pass fcntl()s to the device.

If these pins are not DCD signal, and rather some obscure pins then the
driver may be unaware of its "readiness". Then any open() call may not
block, whether the device is actually capable of sending data or not. I
haven't checked the serial pinout to verify.

Here is some reading that may be of assistance.
http://www.easysw.com/~mike/serial/serial.html#2_5

Hope this helps.

Art Perry
Linux Systems/Software Engineer
 
G

Gordon Burditt

I have a temperature sensor device we use to shutdown our servers. It
relys on fopen() blocking when the serial port device isn't ready.
Unfortunately that's not what's happening. The fopen() returns
immediately without an error. What have I got wrong?

Sometimes serial ports have several associated devices.
Some of them wait for carrier detect ("dial-in") and some
of them don't ("dial-out").
Basically when it gets too hot the device connects the 8 and 6 lines
to line 20.

DTR -> DSR and DTR -> DCD . This is typical of a quick-and-dirty
way for a UPS to signal a power failure when batteries are
near to exhausted.

That should, as I understand it, tell the fopen() that
the file is available and cause the rest of the program to execute.

Gordon L. Burditt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top