synchro data processing

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
darioit
Posts: 230
Joined: 02 Aug 2010 05:25

synchro data processing

#1 Post by darioit » 24 Sep 2014 07:35

Hello Everybody,
I want share with you my new milestone, but in this case is not strictly related to script problem, but a data flow, here my question in detail:

My data comining from Serial Port Com1 about 15/20 seconds, but the interval is every 6 second, I show you:
<msg><src>CC128-v0.11</src><dsb>01591</dsb><time>20:04:02</time><tmpr>23.1</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00301</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01591</dsb><time>20:04:08</time><tmpr>23.1</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00300</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01591</dsb><time>20:04:14</time><tmpr>23.1</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00303</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01591</dsb><time>20:04:20</time><tmpr>23.1</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00310</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01591</dsb><time>20:04:26</time><tmpr>23.1</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00303</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01591</dsb><time>20:04:32</time><tmpr>23.1</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00299</watts></ch1></msg>


I get my data with this script, every 5 second and put the result in a RRD DB

Code: Select all

@echo off
set RIGA=
for /F %%a in ('tail -n2 CurrentCostXml.xml ^| find "<watts>"') do call set RIGA="%%a"
set TEMP=%RIGA:~71,4%
set WATT=%RIGA:~104,5%
rrdtool update powertemp.rrd N:%WATT%:%TEMP%


But the result is wrong because data coming every 15/20 second, so I read for 15 second the same result because is not updated

How can I read every 5 second the real last raw?
20:04:02 00301
20:04:08 00300
20:04:14 00303
20:04:20 00310
20:04:26 00303
20:04:32 00299

Thanks in advance and regards

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: synchro data processing

#2 Post by penpen » 24 Sep 2014 09:37

You could store the last timestamp within a temporary file and check against it (something like that):

Code: Select all

@echo off
set RIGA=
for /F %%a in ('tail -n2 CurrentCostXml.xml ^| find "<watts>"') do call set RIGA="%%a"
set "tmpr=%RIGA:~71,4%"
set "watts=%RIGA:~104,5%"

cmd /D /A /C "> "currentTimestamp.tmp" echo %RIGA:~50,8%"
fc "lastTimestamp.tmp" "currentTimestamp.tmp"
if not ErrorLevel 0 (
   del "lastTimestamp.tmp"
   ren "currentTimestamp.tmp" "lastTimestamp.tmp"
   rrdtool update powertemp.rrd N:%watts%:%tmpr%
)
Currently untested, please check if %RIGA:~50,8% is always the timestamp.

penpen

darioit
Posts: 230
Joined: 02 Aug 2010 05:25

Re: synchro data processing

#3 Post by darioit » 26 Sep 2014 07:05

Thanks for reply, I do many many test and I find the problem was the command "TYPE.EXE" insode cmd.com

I dont't know the reason, but it's seems that have a polling of 20 seconds indipendent of serial port flow

I replace "type.exe" with Python pyserial and now the flow is mutch better

Post Reply