Create XML ad Hoc (Current Cost Code)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Create XML ad Hoc (Current Cost Code)

#1 Post by darioit » 11 Feb 2014 16:57

Hello, my goal is to create a file with timestamp containing a raw exactly like this, maximum 20 raw for file.

Code: Select all

<MenTime>11/02/2014 23:05:20</MenTime><msg><src>CC128-0.11</src><dsb>01369</dsb><time>22:57:56</time><tmpr>19.7</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00485</watts></ch1></msg>


Using this command in batch Dos
"Type COM3"
I get this raw from serial port, each raw is push every 6 seconds from serial port:

Code: Select all

<msg><src>CC128-0.11</src><dsb>01369</dsb><time>22:57:56</time><tmpr>19.7</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00485</watts></ch1></msg>


But this raw it's missing from this initial part:

Code: Select all

<MenTime>11/02/2014 23:05:20</MenTime>


So I create this Batch:

Code: Select all

@echo on

REM _________   D A T E    A N D    T I M E   ___________________________________________
for /f "delims=" %%A in ('wmic OS Get localdatetime  ^| find "."') do set DATETIMEWMI=%%A
set  Y=%DATETIMEWMI:~0,4%
set  M=%DATETIMEWMI:~4,2%
set  G=%DATETIMEWMI:~6,2%
set HH=%DATETIMEWMI:~8,2%
set MM=%DATETIMEWMI:~10,2%
set SS=%DATETIMEWMI:~12,2%
set MS=%DATETIMEWMI:~15,2%
set DD=%G%%M%%Y%
set DD0=%Y%-%M%-%G%
set DD1=%G%/%M%/%Y%
set ORA=%HH%%MM%
set ORA1=%HH%.%MM%.%SS%
set ORA2=%HH%:%MM%:%SS%
set TIMESTAMP=%G%%M%%Y%_%HH%%MM%%SS%
REM ______________________________________________________________________________________


SET Head=<MenTime>%DD1% %ORA2%</MenTime>

type nul > C:\Meniscus\Data\abcdefghi_%TIMESTAMP%
type COM3 >> C:\Meniscus\Data\abcdefghi_%TIMESTAMP%


First problem why doesn't work this set "SET Head"
Second problem, how can I quit "type COM3" after 20 raw
Third problem I call this script with another one to have different variable in MenTime, but command "type Com3" does't quit

This is a example of correct file "abcdefghi_%TIMESTAMP%"
<MenTime>11/02/2014 23:04:51</MenTime><msg><src>CC128-v0.11</src><dsb>01369</dsb><time>22:57:26</time><tmpr>19.6</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00477</watts></ch1></msg>

<MenTime>11/02/2014 23:04:57</MenTime><msg><src>CC128-v0.11</src><dsb>01369</dsb><time>22:57:32</time><tmpr>19.6</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00467</watts></ch1></msg>

<MenTime>11/02/2014 23:05:03</MenTime><msg><src>CC128-v0.11</src><dsb>01369</dsb><time>22:57:38</time><tmpr>19.6</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00473</watts></ch1></msg>


Thanks in advance and Regards

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Create XML ad Hoc (Current Cost Code)

#2 Post by Squashman » 11 Feb 2014 17:50

darioit wrote:
SET Head=<MenTime>%DD1% %ORA2%</MenTime>

type nul > C:\Meniscus\Data\abcdefghi_%TIMESTAMP%
type COM3 >> C:\Meniscus\Data\abcdefghi_%TIMESTAMP%[/code]

First problem why doesn't work this set "SET Head"

The answer to that should be quite obvious with the 2 lines of code after your SET command. The < symbol and > symbol are special characters for directing input and output.

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

Re: Create XML ad Hoc (Current Cost Code)

#3 Post by darioit » 11 Feb 2014 23:53

May I write continuously a file C:\Meniscus\Data\data.xml, and every 2 minutes cut the file with a simple rename to finally name C:\Meniscus\Data\abcdefghi_%TIMESTAMP% ?
I don't think is blocked by Serial Port

Post Reply