[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: input time limit
From: |
Geraint Paul Bevan |
Subject: |
Re: input time limit |
Date: |
Tue, 09 Nov 2004 18:17:17 +0000 |
User-agent: |
Mozilla Thunderbird 0.7.1 (X11/20040715) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Heather Duman wrote:
| I'm writing some code that calibrates values reported by a sensor. I
| have some criteria that must be met before calibration can occur. After
| these criteria have been met, I have an input (prompt) statement to
| enter the measured value used for calibration. The sensor will continue
| transmitting values even if calibration has not occurred. Is there any
| way to place a time limit on the input request in case it is not
| noticed? We need all values to be recorded, regardless of calibration.
| All of my attempts at using "pause ()" have failed to produce the
| desired result.
|
| Heather Duman
|
I don't know any way of setting a time limit on input, but it should be
possible to do what you want by spawning a separate sub-process to get
the calibration data. If the sub-process writes the data to file, the
main process can pick it up if/when it exist.
The attached files get dummy sensor data and then try to read an input.
If you are quick, the calibration data will be read. If not, the sensor
collection will carry on regardless.
getvalue.m: # ensure that this is executable (chmod +x)
#! /usr/bin/octave -q
printf ( "\n" );
calibration = input ( "Enter a value: " );
save -ascii calibration.dat calibration;
exit;
run.m: # run this from Octave
clear calibration;
function get_sensor_data ()
~ printf ( "Getting data ... " );
~ pause (5);
~ data = rand (1);
~ printf ( "%f\n", data );
endfunction
function prompt_calibration ()
~ delete ( "calibration.dat" );
~ [pid, msg] = fork ();
~ if ( pid == 0 )
~ # child process
~ exec ( "./getvalue.m", "" );
~ endif
endfunction
function read_calibration ()
~ if ( file_in_path ( ".", "calibration.dat" ) )
~ load -ascii calibration.dat calibration;
~ printf ( "calibration data is %f\n", calibration );
~ else
~ warning ( "no calibration data ... continuing" );
~ endif
endfunction
## main loop
for i = 1 : 5
~ if ( i == 3 )
~ prompt_calibration();
~ endif
~ get_sensor_data();
~ if ( i == 3 )
~ read_calibration();
~ endif
endfor
- --
Geraint Bevan
http://www.mech.gla.ac.uk/~gbevan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iEYEARECAAYFAkGRCa0ACgkQcXV3N50QmNP5VwCfRP9Qw2M5jy1Rbl0psfkRd1Yp
n+UAn2+WjVAchhdU2cRzP5Yscws4IeP6
=i3vW
-----END PGP SIGNATURE-----
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------