Parsing information from serial port

Hello!

I have Device, it constantly transmits information by serial port 9 parameters (will call them ABCDEFGHI). Each parameter has length of 2 byte.
Parameter A is the Header ($4444), other parameters are unsigned integer.
The task is to get parameters B, C, D, E, G every 40 seconds.

I read this manual https://www.openhab.org/addons/bindings/serial1/ and I can get information from serial:

String Serial1 {serial="/dev/ttyUSB1@9600"}

But not understand how do it once every 40 seconds (not constantly!) and how to get B, C, D, E, G (using of REGEX in my situation is not clear to me too).

To get the info posted every 40 seconds you can try using a rule with a cron job.

Example:

rule "Info"
when
    Time Cron "40 * * * * ? *"  // at 40 seconds of every minuet
then
    val infoRex = transform("REGEX", ".*=(\\w*.\\d*).*", Youritem.state.toString) // random example
Test_Item.postUpdate(infoRex)
end

As for the Regex transformation I can try and help but I’m not the greatest with regex.:smile:
If you can post exactly what’s transmitted I’ll take a stab at trying to figure it out.:crossed_fingers:

Thanks for answer.

  1. infoRex will start to read Serial from 40 seconds, but never ends. And we get the same problem.
  2. If you know another way to parsing, please, post it.

May be better to use the Item as a trigger and find another way to only post the data every 40 seconds.

Could you please post what your wanting to parse. Being able to see the info helps.

  1. Need way to terminate reading from serial
  2. For example: (spaces only for help to see) $4444 5000 0190 0220 0434 1234 1234 9090 3322 4444 4999 0220 0230 0474 3234 1334 9190 3122

Does the device stream this data continuously?
And you only want to capture one “frame” every 40s?

Yes, data is streaming continuously.
No needs to register data often then 40 s. The second problem is the long (infinitely long!) string to parsing if we read data continuously.

You may want to consider a python script instead
Get the script to capture the stream continuously
Count the frames and every 10000 frames (for example or whatever number of frames is 40 seconds)
send the data to openhab via the rest api or mqtt

Unfortunately I am not greatest in Python. If you can help, I will be thankful to you.

https://pyserial.readthedocs.io/en/latest/shortintro.html

Thanks, will try it.