Experimental Physics and Industrial Control System
Subject: |
Re: Streams questions (how to read +00011-01 as 11e-01=1.1) |
From: |
Dirk Zimoch <[email protected]> |
To: |
TechTalk EPICS <[email protected]> |
Date: |
Wed, 21 Nov 2007 17:22:45 +0100 |
Hi all,
Here is an ad-hoc format converter for a "mantissa and exponent representation
without e". In other words: Two signed decimal integers like in +01234-56
meaning 1234e-56 (or 1.234e-43)
Eric and someone else I don't remember requested it.
Put the converter file in the src directory, add FORMATS+=Exponential to
CONFIG_STREAM and requild. The format is %m. (Any better suggestion?)
Maximal field width does not work at the moment. Low level, it just reads %d%d.
Output is not implemented because it is not clear how to do the formatting,
Why +00011-01 and not +00110-02 or +11000-04 ?
Was +00011-01 originally 1.1000000000000 or 1.11 or 1.10000000000001 ?
What are the rules for rounding and precision?
Dirk
Dirk Zimoch wrote:
Hi Eric,
at the moment, I don't have a direct support for this. But I tried the
following construct:
record (ai, "$(P):read")
{
field(DTYP, "stream")
field(INP, "@proto read($(P):calc) terminal")
field(FLNK, "$(P):calc")
}
record (calcout, "$(P):calc")
{
field(CALC, "A*10^B")
field(OUT, "$(P):read")
}
with the protocol
Terminator="\r\n";
read {
in "U1";
in "%(\$1.A)d%(\$1.B)d";
}
The protocol reads mantissa and exponent as decimal integer and put them
into fields A and B of a calc record. This record calculates the value
and writes it back to the input record.
I already got a request for the same format earlier but have not yet
found the time to implement it.
Dirk
Eric Berryman wrote:
Hello!
I've run into a problem I'm guessing others have solved using the
Streams module. I have a device that outputs reads in the format:
U1\r\n+00011-01\r\n
meaning 11e-01 , which would be the preferred format for using a
general format specifier in the protocol file.
What would be the format to successfully read in this number from the
Streams protocol file?
(Or, will I have to run as a string read through a c filter program,
sub record)
Thank you!
Eric
--
Dr. Dirk Zimoch
Paul Scherrer Institut, WBGB/006
5232 Villigen PSI, Switzerland
Phone +41 56 310 5182
/***************************************************************
* StreamDevice Support *
* *
* (C) 1999 Dirk Zimoch ([email protected]) *
* (C) 2007 Dirk Zimoch ([email protected]) *
* *
* This is a custom exponential format converter for *
* StreamDevice. *
* The number is represented as two signed integers, mantissa *
* and exponent, like in +00011-01 *
* Please refer to the HTML files in ../doc/ for a detailed *
* documentation. *
* *
* If you do any changes in this file, you are not allowed to *
* redistribute it any more. If there is a bug or a missing *
* feature, send me an email and/or your patch. If I accept *
* your changes, they will go to the next release. *
* *
* DISCLAIMER: If this software breaks something or harms *
* someone, it's your problem. *
* *
***************************************************************/
#include "StreamFormatConverter.h"
#include "StreamError.h"
#include <math.h>
// Exponential Converter %m: format +00351-02 means +351e-2
class ExponentialConverter : public StreamFormatConverter
{
virtual int parse(const StreamFormat&, StreamBuffer&, const char*&, bool);
virtual int scanDouble(const StreamFormat&, const char*, double&);
};
int ExponentialConverter::
parse(const StreamFormat& fmt, StreamBuffer& info,
const char*& source, bool scanFormat)
{
if (!scanFormat)
{
error("At the moment for %%m format only input is implemented\n");
return false;
}
return double_format;
}
int ExponentialConverter::
scanDouble(const StreamFormat& fmt, const char* input, double& value)
{
int mantissa;
int exponent;
int length = -1;
sscanf(input, "%d%d%n", &mantissa, &exponent, &length);
if (fmt.flags & skip_flag) return length;
if (length == -1) return -1;
value = (double)(mantissa) * pow(10, exponent);
return length;
}
RegisterConverter (ExponentialConverter, "m");
- References:
- Streams questions Eric Berryman
- Re: Streams questions Dirk Zimoch
- Navigate by Date:
- Prev:
Re: Stream Raw converter and un/signed integrer Dirk Zimoch
- Next:
Problems building edm-1-11-0zg David Dudley
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
<2007>
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
- Navigate by Thread:
- Prev:
Re: Streams questions Dirk Zimoch
- Next:
RE: Streams questions Mohan Ramanathan
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
<2007>
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025