How to Capture Multiples Lines/All Buffer Data in Tasker Variable

83 views
Skip to first unread message

djsv...@gmail.com

unread,
Feb 26, 2017, 5:06:14 PM2/26/17
to Android Send/Expect
Hello, 
I am trying to capture multi line response in that may vary. Let say one that looks like this:

KD-8x8CS>sta
sta
<status>TA</status>
-----------------------------------------------------------
--               Key Digital Systems STATUS              --
-----------------------------------------------------------
--  KD-8x8CS  System Address = 00  F/W Version 1.9       --
--                                                       --
-- Power : On                                            --
-- Front Panel Buttons Enable                            --
--                                                       --
-- Video Input 01 : EDID = HDMI OUTPUT 01                --
-- Video Input 02 : EDID = HDMI OUTPUT 02                --
-- Video Input 03 : EDID = HDMI OUTPUT 01                --
-- Video Input 04 : EDID = DEFAULT 09                    --
-- Video Input 05 : EDID = DEFAULT 09                    --
-- Video Input 06 : EDID = DEFAULT 09                    --
-- Video Input 07 : EDID = DEFAULT 09                    --
-- Video Input 08 : EDID = DEFAULT 09                    --
--                                                       --
-- Video Output 01 : Input = 01,  Output =ON             --
-- Video Output 02 : Input = 05,  Output =ON             --
-- Video Output 03 : Input = 05,  Output =ON             --
-- Video Output 04 : Input = 05,  Output =ON             --
-- Video Output 05 : Input = 05,  Output =ON             --
-- Video Output 06 : Input = 05,  Output =ON             --
-- Video Output 07 : Input = 05,  Output =ON             --
-- Video Output 08 : Input = 05,  Output =ON             --
--                                                       --
-----------------------------------------------------------

KD-8x8CS>

I spend many hours studying th RegEx and all tools and theory tells me that ".+" should return the whole thing, specifically when DOTALL flag is on (help claims it is). However, ".+" only returns "sta" which is the second line above (sta is my input followed by enter, Putty). I also tried "\r+", "\n+" and "\r\n". Those can be seen in the Buffer bellow, which was captured by "Output". In this perticular example, I can capture all the valuer info I need. But I have different devices that can respond unexpected text and I want to learn how to capture it all in Tasker variable.

[

  {

    "timestamp": 0,

    "recordType": "Start",

    "recordData": "Standalone"

  },

  {

    "timestamp": 0,

    "recordType": "Version",

    "recordData": "2020041"

  },

  {

    "timestamp": 0,

    "recordType": "Send/Expect Data",

    "recordData": "Timeout seconds: 3\nSend : sta\\r\nExpect: Output\n"

  },

  {

    "timestamp": 1,

    "recordType": "Connection Started",

    "recordData": "192.168.1.166:5001"

  },

  {

    "timestamp": 10,

    "recordType": "Connection Completed",

    "recordData": "192.168.1.166:5001"

  },

  {

    "timestamp": 10,

    "recordType": "Send",

    "recordData": "sta\\r"

  },

  {

    "timestamp": 10,

    "recordType": "Data Sent",

    "recordData": null

  },

  {

    "timestamp": 10,

    "recordType": "Expect",

    "recordData": "Output"

  },

  {

    "timestamp": 10,

    "recordType": "Received Buffer Contains",

    "recordData": ""

  },

  {

    "timestamp": 54,

    "recordType": "Received Bytes",

    "recordData": "87"

  },

  {

    "timestamp": 54,

    "recordType": "Received Buffer Contains",

    "recordData":

"sta\r\n<status>TA</status>\r\n-----------------------------------------------------------\r\n"

  },

  {

    "timestamp": 94,

    "recordType": "Received Bytes",

    "recordData": "171"

  },

  {

    "timestamp": 94,

    "recordType": "Received Buffer Contains",

    "recordData":

"sta\r\n<status>TA</status>\r\n-----------------------------------------------------------\r\n--\t\t

Key Digital Systems STATUS             

--\r\n-----------------------------------------------------------\r\n-- 

KD-8x8CS  System Address = 00  F/W Version 1.9       --\r\n"

  },

  {

    "timestamp": 133,

    "recordType": "Received Bytes",

    "recordData": "197"

  },

  {

    "timestamp": 133,

    "recordType": "Received Buffer Contains",

    "recordData":

"sta\r\n<status>TA</status>\r\n-----------------------------------------------------------\r\n--\t\t

Key Digital Systems STATUS             

--\r\n-----------------------------------------------------------\r\n-- 

KD-8x8CS  System Address = 00  F/W Version 1.9       --\r\n--              

                       \t\t --\r\n-- Power : On                            

 \t\t --\r\n-- Front Panel Buttons Enable                \t\t --\r\n--     

                               \t \t\t --\r\n"

  },

  {

    "timestamp": 177,

    "recordType": "Received Bytes",

    "recordData": "200"

  },

  {

    "timestamp": 177,

    "recordType": "Received Buffer Contains",

    "recordData":

"sta\r\n<status>TA</status>\r\n-----------------------------------------------------------\r\n--\t\t

Key Digital Systems STATUS             

--\r\n-----------------------------------------------------------\r\n-- 

KD-8x8CS  System Address = 00  F/W Version 1.9       --\r\n--              

                       \t\t --\r\n-- Power : On                             

 \t\t --\r\n-- Front Panel Buttons Enable                \t\t --\r\n--     

                               \t \t\t --\r\n-- Video Input 01 : EDID =

HDMI OUTPUT 01   \t\t --\r\n-- Video Input 02 : EDID = HDMI OUTPUT 02  

\t\t --\r\n-- Video Input 03 : EDID = HDMI OUTPUT 01   \t\t --\r\n-- Video

Input 04 : EDID = DEFAULT 09   \t\t --\r\n"

  },

  {

    "timestamp": 214,

    "recordType": "Received Bytes",

    "recordData": "188"

  },

  {

    "timestamp": 214,

    "recordType": "Received Buffer Contains",

    "recordData":

"sta\r\n<status>TA</status>\r\n-----------------------------------------------------------\r\n--\t\t

Key Digital Systems STATUS             

--\r\n-----------------------------------------------------------\r\n-- 

KD-8x8CS  System Address = 00  F/W Version 1.9       --\r\n--              

                       \t\t --\r\n-- Power : On                            

 \t\t --\r\n-- Front Panel Buttons Enable                \t\t --\r\n--     

                               \t \t\t --\r\n-- Video Input 01 : EDID =

HDMI OUTPUT 01   \t\t --\r\n-- Video Input 02 : EDID = HDMI OUTPUT 02  

\t\t --\r\n-- Video Input 03 : EDID = HDMI OUTPUT 01   \t\t --\r\n-- Video

Input 04 : EDID = DEFAULT 09   \t\t --\r\n-- Video Input 05 : EDID =

DEFAULT 09   \t\t --\r\n-- Video Input 06 : EDID = DEFAULT 09   \t\t

--\r\n-- Video Input 07 : EDID = DEFAULT 09   \t\t --\r\n-- Video Input 08

: EDID = DEFAULT 09   \t\t --\r\n"

  },

  {

    "timestamp": 254,

    "recordType": "Received Bytes",

    "recordData": "157"

  },

  {

    "timestamp": 254,

    "recordType": "Received Buffer Contains",

    "recordData":

"sta\r\n<status>TA</status>\r\n-----------------------------------------------------------\r\n--\t\t

Key Digital Systems STATUS             

--\r\n-----------------------------------------------------------\r\n-- 

KD-8x8CS  System Address = 00  F/W Version 1.9       --\r\n--              

                       \t\t --\r\n-- Power : On                            

 \t\t --\r\n-- Front Panel Buttons Enable                \t\t --\r\n--     

                               \t \t\t --\r\n-- Video Input 01 : EDID =

HDMI OUTPUT 01   \t\t --\r\n-- Video Input 02 : EDID = HDMI OUTPUT 02  

\t\t --\r\n-- Video Input 03 : EDID = HDMI OUTPUT 01   \t\t --\r\n-- Video

Input 04 : EDID = DEFAULT 09   \t\t --\r\n-- Video Input 05 : EDID =

DEFAULT 09   \t\t --\r\n-- Video Input 06 : EDID = DEFAULT 09   \t\t

--\r\n-- Video Input 07 : EDID = DEFAULT 09   \t\t --\r\n-- Video Input 08

: EDID = DEFAULT 09   \t\t --\r\n--                                    

\t\t\t --\r\n-- Video Output 01 : Input = 01,  Output =ON     \t --\r\n--

Video Output 02 : Input = 05,  Output =ON     \t --\r\n"

  },

  {

    "timestamp": 254,

    "recordType": "Expect Matched",

    "recordData":

"sta\r\n<status>TA</status>\r\n-----------------------------------------------------------\r\n--\t\t

Key Digital Systems STATUS              

--\r\n-----------------------------------------------------------\r\n-- 

KD-8x8CS  System Address = 00  F/W Version 1.9       --\r\n--              

                       \t\t --\r\n-- Power : On                            

 \t\t --\r\n-- Front Panel Buttons Enable                \t\t --\r\n--     

                               \t \t\t --\r\n-- Video Input 01 : EDID =

HDMI OUTPUT 01   \t\t --\r\n-- Video Input 02 : EDID = HDMI OUTPUT 02  

\t\t --\r\n-- Video Input 03 : EDID = HDMI OUTPUT 01   \t\t --\r\n-- Video

Input 04 : EDID = DEFAULT 09   \t\t --\r\n-- Video Input 05 : EDID =

DEFAULT 09   \t\t --\r\n-- Video Input 06 : EDID = DEFAULT 09   \t\t

--\r\n-- Video Input 07 : EDID = DEFAULT 09   \t\t --\r\n-- Video Input 08

: EDID = DEFAULT 09   \t\t --\r\n--                                    

\t\t\t --\r\n-- Video Output"

  },

  {

    "timestamp": 255,

    "recordType": "Disconnect",

    "recordData": null

  },

  {

    "timestamp": 255,

    "recordType": "Succeeded",

    "recordData": null

  }

]

David

unread,
Mar 2, 2017, 1:50:53 AM3/2/17
to Android Send/Expect

On Sunday, February 26, 2017 at 2:06:14 PM UTC-8, djsvetljo wrote:

I spend many hours studying th RegEx and all tools and theory tells me that ".+" should return the whole thing, specifically when DOTALL flag is on (help claims it is). However, ".+" only returns "sta" which is the second line above (sta is my input followed by enter, Putty). I also tried "\r+", "\n+" and "\r\n". Those can be seen in the Buffer bellow, which was captured by "Output". In this perticular example, I can capture all the valuer info I need. But I have different devices that can respond unexpected text and I want to learn how to capture it all in Tasker variable.'

Sorry.  This is a documentation bug.  The RE is not being compiled with the DOTALL flag on.  But per the JDK documentation for DOTALL you can explicitly add this to RE using the (?s) prefix. For example:

(?s)(<?<all>.+)

will populate the Tasker variable "all" with all data that has been seen.  However this may not give you the expected results, as it is dependent upon how much data is has been received at the time the expression is evaluated.  The .+ says one or more character matches.  But there is no guarantee that all of the data has shown up.  This is solved by knowing what the end of the data looks like.  In your case, if the first instance of "Output" is the end of what you are interested in, then try something like:

(?s)(<?<all>.*)Output



djsv...@gmail.com

unread,
Mar 2, 2017, 9:03:46 PM3/2/17
to Android Send/Expect

(?s)(<?<all>.+)
This results is task error - exception - time out waiting for data. I think it's because there is nothing to expect. However, when log is checked, all the data is in the received buffer part.

Also, just (*s) in send/expect stand-alone crashes it (2.2.5 trial).

By know I know how to capture certain data. I have one device that is acting up and sends partial data sometimes. It's not very important but it would be nice to know that it's possible.

Reply all
Reply to author
Forward
0 new messages