EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: streamdevice to find the last match
From: Benjamin Franksen <[email protected]>
To: <[email protected]>
Date: Thu, 22 Aug 2013 23:10:07 +0200
Am Donnerstag, 22. August 2013, 21:17:37 schrieb Zhang, Dehong:
> I run into 2 little problems: I wait for the hardware to send a message
> like "BOS123456,P=987654EOS\r\n".
> Here BOS is my starting label and EOS the ending label.
>
> Due to timing, which I cannot control, sometimes I would receive 2 messages
> together, like:
> "BOS123456,P=987654EOS\r\nBOS345,P=987649EOS\r\n".
> Here the first one was sent when the state was still changing, the second
> one was sent when the state stablizes.  But the time in between is so
> short that the 2 messages just come out as one.  How can I skip the first
> match, only get the second/last match?
>
> My protocal is like:
> InTerminator  = CR;
> OutTerminator = CR LF;
> ReplyTimeout  = 800;
> ReadTimeout   = 100;
> WriteTimeout  = 100;
> ExtraInput    = Ignore;

It might be useful or perhaps even necessary to remove the last line, since
you want the whole response to match (so you can extract the last part).

> # Reports from the controller
> STATUS  { ReplyTimeout = 50; ReadTimeout = 10; InTerminator =; in
> "%.1/BOS([0-9,P=]*EOS)/"; }
>
> I tried to use the "$" anchor, but cannot get it to work -- maybe because
> "$" is a special character in streamdevice.

Hm, looks as if you use the regular expression matcher (which is based on
PCRE), so I think I can answer this question. To express "match expression X
zero or more times, then match X exactly once" you say

        /X*X/

In your case the expression X is

        BOS\d+,P=\d+EOS\r\n

so your whole regex should be

        /(BOS\d+,P=\d+EOS\r\n)*BOS\d+,P=\d+EOS\r\n/

This should correctly match the response you get from the device, but does not
yet say which part to extract as the result.

In order to assign the last message to the VAL field of your record (probably
a stringin record or something like that, since you seem to want to match both
numbers simultaneously and also want to include the EOS in the result), your
protocol string should be

        "%.2/(BOS\d+,P=\d+EOS\r\n)*BOS(\d+,P=\d+EOS)\r\n/"

Or maybe this is not what you want. For instance, to get only the number after
the P=, say

        "%.2/(BOS\d+,P=\d+EOS\r\n)*BOS\d+,P=(\d+)EOS\r\n/"

etc. Note that in both cases you must match the second group (%.2/.../), not
the first one as in your version.

Cheers
Ben
--
"Make it so they have to reboot after every typo." -- Scott Adams

________________________________

Helmholtz-Zentrum Berlin für Materialien und Energie GmbH

Mitglied der Hermann von Helmholtz-Gemeinschaft Deutscher Forschungszentren e.V.

Aufsichtsrat: Vorsitzender Prof. Dr. Dr. h.c. mult. Joachim Treusch, stv. Vorsitzende Dr. Beatrix Vierkorn-Rudolph
Geschäftsführung: Prof. Dr. Anke Rita Kaysser-Pyzalla, Thomas Frederking

Sitz Berlin, AG Charlottenburg, 89 HRB 5583

Postadresse:
Hahn-Meitner-Platz 1
D-14109 Berlin

http://www.helmholtz-berlin.de


References:
streamdevice to find the last match Zhang, Dehong

Navigate by Date:
Prev: Re: Problems compiling Nexus library as DLL on Windows Timothy Madden
Next: Asyn AutoConnect and stream device on a soft IOC Scott Baily
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: streamdevice to find the last match Zhang, Dehong
Next: Re: streamdevice to find the last match Dirk Zimoch
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 20 Apr 2015 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·