Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### DisplayENVI.ps1 ############################################
- #
- # Routine to display power recorded by a Current Cost Monitor.
- #
- ################################################################
- $loop_forever = $true
- $CommPort_in="COM1"
- $BaudRate=57600
- $Sensor=0
- #$template=[xml]("<msg><src></src><dsb></dsb><time></time><tmpr></tmpr><sensor></sensor><id></id><type></type><ch1><watts></watts></ch1><ch2><watts></watts></ch2><ch3><watts></watts></ch3></msg>")
- [double]$CH1 = 0.0
- [double]$CH2 = 0.0
- [double]$CH3 = 0.0
- [double]$Total = 0.0
- $TimeNow=" "
- #########################################3######################
- $port_in= new-Object System.IO.Ports.SerialPort $CommPort_in,$BaudRate,None,8,one
- $port_in.Open()
- $data=$port_in.Readline() #Discard a possibly partial msg
- #
- do {
- $data=$port_in.Readline()
- #Write-Host ($data)
- #Remove any chars (probably noise) received before <msg
- if ((!$data.StartsWith("<msg>")) -or (!$data.EndsWith("</msg>")))
- {$Data =$data.substring($data.IndexOf("<"),$data.LastIndexOf(">") - $data.IndexOf("<")+1)
- }
- [xml]$data_in=$data #may still have noise inside the message. trap error and continue
- #---------------------------------------------------
- if ($data_in.msg.sensor -eq $Sensor)
- {$CH1=$data_in.msg.ch1.watts
- $CH2=$data_in.msg.ch2.watts
- $CH3=$data_in.msg.ch3.watts
- $Total = $CH1 + $CH2 + $CH3
- $TimeNow=$data_in.msg.time
- Write-Host ("Sensor=$Sensor, Time=$TimeNow Total=$Total, Ch1=$CH1, Ch2=$CH2, Ch3=$CH3")
- }
- else
- {
- # All other sensors ignored
- }
- #----------------------------------------------------
- } While ($loop_forever='true')
- $port_in.close()
- Write-Host ("DisplayENVI completed")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement